theme.js
6.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/**
* Theme Browsing
*
* Controls visibility of theme details on manage and install themes pages.
*/
jQuery( function($) {
$('#availablethemes').on( 'click', '.theme-detail', function (event) {
var theme = $(this).closest('.available-theme'),
details = theme.find('.themedetaildiv');
if ( ! details.length ) {
details = theme.find('.install-theme-info .theme-details');
details = details.clone().addClass('themedetaildiv').appendTo( theme ).hide();
}
details.toggle();
event.preventDefault();
});
});
/**
* Theme Browser Thickbox
*
* Aligns theme browser thickbox.
*/
var tb_position;
jQuery(document).ready( function($) {
tb_position = function() {
var tbWindow = $('#TB_window'), width = $(window).width(), H = $(window).height(), W = ( 1040 < width ) ? 1040 : width, adminbar_height = 0;
if ( $('body.admin-bar').length )
adminbar_height = 28;
if ( tbWindow.size() ) {
tbWindow.width( W - 50 ).height( H - 45 - adminbar_height );
$('#TB_iframeContent').width( W - 50 ).height( H - 75 - adminbar_height );
tbWindow.css({'margin-left': '-' + parseInt( ( ( W - 50 ) / 2 ), 10 ) + 'px'});
if ( typeof document.body.style.maxWidth != 'undefined' )
tbWindow.css({'top': 20 + adminbar_height + 'px','margin-top':'0'});
};
};
$(window).resize(function(){ tb_position(); });
});
/**
* Theme Install
*
* Displays theme previews on theme install pages.
*/
jQuery( function($) {
if( ! window.postMessage )
return;
var preview = $('#theme-installer'),
info = preview.find('.install-theme-info'),
panel = preview.find('.wp-full-overlay-main'),
body = $( document.body );
preview.on( 'click', '.close-full-overlay', function( event ) {
preview.fadeOut( 200, function() {
panel.empty();
body.removeClass('theme-installer-active full-overlay-active');
});
event.preventDefault();
});
preview.on( 'click', '.collapse-sidebar', function( event ) {
preview.toggleClass( 'collapsed' ).toggleClass( 'expanded' );
event.preventDefault();
});
$('#availablethemes').on( 'click', '.install-theme-preview', function( event ) {
var src;
info.html( $(this).closest('.installable-theme').find('.install-theme-info').html() );
src = info.find( '.theme-preview-url' ).val();
panel.html( '<iframe src="' + src + '" />');
preview.fadeIn( 200, function() {
body.addClass('theme-installer-active full-overlay-active');
});
event.preventDefault();
});
});
var ThemeViewer;
(function($){
ThemeViewer = function( args ) {
function init() {
$( '#filter-click, #mini-filter-click' ).unbind( 'click' ).click( function() {
$( '#filter-click' ).toggleClass( 'current' );
$( '#filter-box' ).slideToggle();
$( '#current-theme' ).slideToggle( 300 );
return false;
});
$( '#filter-box :checkbox' ).unbind( 'click' ).click( function() {
var count = $( '#filter-box :checked' ).length,
text = $( '#filter-click' ).text();
if ( text.indexOf( '(' ) != -1 )
text = text.substr( 0, text.indexOf( '(' ) );
if ( count == 0 )
$( '#filter-click' ).text( text );
else
$( '#filter-click' ).text( text + ' (' + count + ')' );
});
/* $('#filter-box :submit').unbind( 'click' ).click(function() {
var features = [];
$('#filter-box :checked').each(function() {
features.push($(this).val());
});
listTable.update_rows({'features': features}, true, function() {
$( '#filter-click' ).toggleClass( 'current' );
$( '#filter-box' ).slideToggle();
$( '#current-theme' ).slideToggle( 300 );
});
return false;
}); */
}
// These are the functions we expose
var api = {
init: init
};
return api;
}
})(jQuery);
jQuery( document ).ready( function($) {
theme_viewer = new ThemeViewer();
theme_viewer.init();
});
/**
* Class that provides infinite scroll for Themes admin screens
*
* @since 3.4
*
* @uses ajaxurl
* @uses list_args
* @uses theme_list_args
* @uses $('#_ajax_fetch_list_nonce').val()
* */
var ThemeScroller;
(function($){
ThemeScroller = {
querying: false,
scrollPollingDelay: 500,
failedRetryDelay: 4000,
outListBottomThreshold: 300,
/**
* Initializer
*
* @since 3.4
* @access private
*/
init: function() {
var self = this;
// Get out early if we don't have the required arguments.
if ( typeof ajaxurl === 'undefined' ||
typeof list_args === 'undefined' ||
typeof theme_list_args === 'undefined' ) {
$('.pagination-links').show();
return;
}
// Handle inputs
this.nonce = $('#_ajax_fetch_list_nonce').val();
this.nextPage = ( theme_list_args.paged + 1 );
// Cache jQuery selectors
this.$outList = $('#availablethemes');
this.$spinner = $('div.tablenav.bottom').children( '.spinner' );
this.$window = $(window);
this.$document = $(document);
/**
* If there are more pages to query, then start polling to track
* when user hits the bottom of the current page
*/
if ( theme_list_args.total_pages >= this.nextPage )
this.pollInterval =
setInterval( function() {
return self.poll();
}, this.scrollPollingDelay );
},
/**
* Checks to see if user has scrolled to bottom of page.
* If so, requests another page of content from self.ajax().
*
* @since 3.4
* @access private
*/
poll: function() {
var bottom = this.$document.scrollTop() + this.$window.innerHeight();
if ( this.querying ||
( bottom < this.$outList.height() - this.outListBottomThreshold ) )
return;
this.ajax();
},
/**
* Applies results passed from this.ajax() to $outList
*
* @since 3.4
* @access private
*
* @param results Array with results from this.ajax() query.
*/
process: function( results ) {
if ( results === undefined ) {
clearInterval( this.pollInterval );
return;
}
if ( this.nextPage > theme_list_args.total_pages )
clearInterval( this.pollInterval );
if ( this.nextPage <= ( theme_list_args.total_pages + 1 ) )
this.$outList.append( results.rows );
},
/**
* Queries next page of themes
*
* @since 3.4
* @access private
*/
ajax: function() {
var self = this;
this.querying = true;
var query = {
action: 'fetch-list',
paged: this.nextPage,
s: theme_list_args.search,
tab: theme_list_args.tab,
type: theme_list_args.type,
_ajax_fetch_list_nonce: this.nonce,
'features[]': theme_list_args.features,
'list_args': list_args
};
this.$spinner.show();
$.getJSON( ajaxurl, query )
.done( function( response ) {
self.nextPage++;
self.process( response );
self.$spinner.hide();
self.querying = false;
})
.fail( function() {
self.$spinner.hide();
self.querying = false;
setTimeout( function() { self.ajax(); }, self.failedRetryDelay );
});
}
}
$(document).ready( function($) {
ThemeScroller.init();
});
})(jQuery);