0
|
1 |
/** |
|
2 |
* Option Tree UI |
|
3 |
* |
|
4 |
* Dependencies: jQuery, jQuery UI, ColorPicker |
|
5 |
* |
|
6 |
* @author Derek Herman (derek@valendesigns.com) |
|
7 |
*/ |
|
8 |
;(function($) { |
|
9 |
OT_UI = { |
|
10 |
processing: false, |
|
11 |
init: function() { |
|
12 |
this.init_hide_body(); |
|
13 |
this.init_sortable(); |
|
14 |
this.init_add(); |
|
15 |
this.init_edit(); |
|
16 |
this.init_remove(); |
5
|
17 |
this.init_edit_title(); |
0
|
18 |
this.init_edit_id(); |
|
19 |
this.init_activate_layout(); |
5
|
20 |
this.init_conditions(); |
0
|
21 |
this.init_upload(); |
|
22 |
this.init_upload_remove(); |
|
23 |
this.init_numeric_slider(); |
|
24 |
this.init_tabs(); |
|
25 |
this.init_radio_image_select(); |
|
26 |
this.init_select_wrapper(); |
5
|
27 |
this.bind_select_wrapper(); |
|
28 |
this.init_google_fonts(); |
0
|
29 |
this.fix_upload_parent(); |
|
30 |
this.fix_textarea(); |
|
31 |
this.replicate_ajax(); |
|
32 |
this.reset_settings(); |
5
|
33 |
this.css_editor_mode(); |
|
34 |
this.javascript_editor_mode(); |
0
|
35 |
}, |
|
36 |
init_hide_body: function(elm,type) { |
|
37 |
var css = '.option-tree-setting-body'; |
|
38 |
if ( type == 'parent' ) { |
|
39 |
$(css).not( elm.parent().parent().children(css) ).hide(); |
|
40 |
} else if ( type == 'child' ) { |
|
41 |
elm.closest('ul').find(css).not( elm.parent().parent().children(css) ).hide(); |
|
42 |
} else if ( type == 'child-add' ) { |
|
43 |
elm.children().find(css).hide(); |
|
44 |
} else if ( type == 'toggle' ) { |
|
45 |
elm.parent().parent().children(css).toggle(); |
|
46 |
} else { |
|
47 |
$(css).hide(); |
|
48 |
} |
|
49 |
}, |
|
50 |
init_remove_active: function(elm,type) { |
|
51 |
var css = '.option-tree-setting-edit'; |
|
52 |
if ( type == 'parent' ) { |
|
53 |
$(css).not(elm).removeClass('active'); |
|
54 |
} else if ( type == 'child' ) { |
|
55 |
elm.closest('ul').find(css).not(elm).removeClass('active'); |
|
56 |
} else if ( type == 'child-add' ) { |
|
57 |
elm.children().find(css).removeClass('active'); |
|
58 |
} else { |
|
59 |
$(css).removeClass('active'); |
|
60 |
} |
|
61 |
}, |
5
|
62 |
init_sortable: function(scope) { |
|
63 |
scope = scope || document; |
|
64 |
$('.option-tree-sortable', scope).each( function() { |
0
|
65 |
if ( $(this).children('li').length ) { |
|
66 |
var elm = $(this); |
|
67 |
elm.show(); |
|
68 |
elm.sortable({ |
|
69 |
items: 'li:not(.ui-state-disabled)', |
|
70 |
handle: 'div.open', |
|
71 |
placeholder: 'ui-state-highlight', |
|
72 |
start: function (event, ui) { |
|
73 |
ui.placeholder.height(ui.item.height()-2); |
|
74 |
}, |
|
75 |
stop: function(evt, ui) { |
|
76 |
setTimeout( |
|
77 |
function(){ |
|
78 |
OT_UI.update_ids(elm); |
|
79 |
}, |
|
80 |
200 |
|
81 |
) |
|
82 |
} |
|
83 |
}); |
|
84 |
} |
|
85 |
}); |
|
86 |
}, |
|
87 |
init_add: function() { |
5
|
88 |
$(document).on('click', '.option-tree-section-add', function(e) { |
0
|
89 |
e.preventDefault(); |
|
90 |
OT_UI.add(this,'section'); |
|
91 |
}); |
5
|
92 |
$(document).on('click', '.option-tree-setting-add', function(e) { |
0
|
93 |
e.preventDefault(); |
|
94 |
OT_UI.add(this,'setting'); |
|
95 |
}); |
5
|
96 |
$(document).on('click', '.option-tree-help-add', function(e) { |
0
|
97 |
e.preventDefault(); |
|
98 |
OT_UI.add(this,'the_contextual_help'); |
|
99 |
}); |
5
|
100 |
$(document).on('click', '.option-tree-choice-add', function(e) { |
0
|
101 |
e.preventDefault(); |
|
102 |
OT_UI.add(this,'choice'); |
|
103 |
}); |
5
|
104 |
$(document).on('click', '.option-tree-list-item-add', function(e) { |
0
|
105 |
e.preventDefault(); |
|
106 |
OT_UI.add(this,'list_item'); |
|
107 |
}); |
5
|
108 |
$(document).on('click', '.option-tree-social-links-add', function(e) { |
|
109 |
e.preventDefault(); |
|
110 |
OT_UI.add(this,'social_links'); |
|
111 |
}); |
|
112 |
$(document).on('click', '.option-tree-list-item-setting-add', function(e) { |
0
|
113 |
e.preventDefault(); |
|
114 |
if ( $(this).parents('ul').parents('ul').hasClass('ui-sortable') ) { |
|
115 |
alert(option_tree.setting_limit); |
|
116 |
return false; |
|
117 |
} |
|
118 |
OT_UI.add(this,'list_item_setting'); |
|
119 |
}); |
|
120 |
}, |
|
121 |
init_edit: function() { |
5
|
122 |
$(document).on('click', '.option-tree-setting-edit', function(e) { |
0
|
123 |
e.preventDefault(); |
|
124 |
if ( $(this).parents().hasClass('option-tree-setting-body') ) { |
|
125 |
OT_UI.init_remove_active($(this),'child'); |
|
126 |
OT_UI.init_hide_body($(this),'child'); |
|
127 |
} else { |
|
128 |
OT_UI.init_remove_active($(this),'parent'); |
|
129 |
OT_UI.init_hide_body($(this), 'parent'); |
|
130 |
} |
|
131 |
$(this).toggleClass('active'); |
|
132 |
OT_UI.init_hide_body($(this), 'toggle'); |
|
133 |
}); |
|
134 |
}, |
|
135 |
init_remove: function() { |
5
|
136 |
$(document).on('click', '.option-tree-setting-remove', function(event) { |
0
|
137 |
event.preventDefault(); |
|
138 |
if ( $(this).parents('li').hasClass('ui-state-disabled') ) { |
|
139 |
alert(option_tree.remove_no); |
|
140 |
return false; |
|
141 |
} |
|
142 |
var agree = confirm(option_tree.remove_agree); |
|
143 |
if (agree) { |
|
144 |
var list = $(this).parents('ul'); |
|
145 |
OT_UI.remove(this); |
|
146 |
setTimeout( function() { |
|
147 |
OT_UI.update_ids(list); |
|
148 |
}, 200 ); |
|
149 |
} |
|
150 |
return false; |
|
151 |
}); |
|
152 |
}, |
|
153 |
init_edit_title: function() { |
5
|
154 |
$(document).on('keyup', '.option-tree-setting-title', function() { |
0
|
155 |
OT_UI.edit_title(this); |
|
156 |
}); |
5
|
157 |
// Automatically fill option IDs with clean versions of their respective option labels |
|
158 |
$(document).on('blur', '.option-tree-setting-title', function() { |
|
159 |
var optionId = $(this).parents('.option-tree-setting-body').find('[type="text"][name$="id]"]') |
|
160 |
if ( optionId.val() === '' ) { |
|
161 |
optionId.val($(this).val().replace(/[^a-z0-9]/gi,'_').toLowerCase()); |
|
162 |
} |
|
163 |
}); |
0
|
164 |
}, |
|
165 |
init_edit_id: function() { |
5
|
166 |
$(document).on('keyup', '.section-id', function(){ |
0
|
167 |
OT_UI.update_id(this); |
|
168 |
}); |
|
169 |
}, |
|
170 |
init_activate_layout: function() { |
5
|
171 |
$(document).on('click', '.option-tree-layout-activate', function() { |
0
|
172 |
var active = $(this).parents('.option-tree-setting').find('.open').text(); |
|
173 |
$('.option-tree-layout-activate').removeClass('active'); |
|
174 |
$(this).toggleClass('active'); |
|
175 |
$('.active-layout-input').attr({'value':active}); |
|
176 |
}); |
5
|
177 |
$(document).on('change', '#option-tree-options-layouts-form select', function() { |
0
|
178 |
var agree = confirm(option_tree.activate_layout_agree); |
|
179 |
if (agree) { |
|
180 |
$('#option-tree-options-layouts-form').submit(); |
|
181 |
} else { |
|
182 |
var active = $('#the_current_layout').attr('value'); |
|
183 |
$('#option-tree-options-layouts-form select option[value="' + active + '"]').attr({'selected':'selected'}); |
|
184 |
$('#option-tree-options-layouts-form select').prev('span').replaceWith('<span>' + active + '</span>'); |
|
185 |
} |
|
186 |
}); |
|
187 |
}, |
|
188 |
add: function(elm,type) { |
|
189 |
var self = this, |
|
190 |
list = '', |
|
191 |
list_class = '', |
|
192 |
name = '', |
|
193 |
post_id = 0, |
|
194 |
get_option = '', |
|
195 |
settings = ''; |
|
196 |
if ( type == 'the_contextual_help' ) { |
|
197 |
list = $(elm).parent().find('ul:last'); |
|
198 |
list_class = 'list-contextual-help'; |
|
199 |
} else if ( type == 'choice' ) { |
|
200 |
list = $(elm).parent().children('ul'); |
|
201 |
list_class = 'list-choice'; |
|
202 |
} else if ( type == 'list_item' ) { |
|
203 |
list = $(elm).parent().children('ul'); |
|
204 |
list_class = 'list-sub-setting'; |
|
205 |
} else if ( type == 'list_item_setting' ) { |
|
206 |
list = $(elm).parent().children('ul'); |
|
207 |
list_class = 'list-sub-setting'; |
5
|
208 |
} else if ( type == 'social_links' ) { |
|
209 |
list = $(elm).parent().children('ul'); |
|
210 |
list_class = 'list-sub-setting'; |
0
|
211 |
} else { |
|
212 |
list = $(elm).parent().find('ul:first'); |
|
213 |
list_class = ( type == 'section' ) ? 'list-section' : 'list-setting'; |
|
214 |
} |
|
215 |
name = list.data('name'); |
|
216 |
post_id = list.data('id'); |
|
217 |
get_option = list.data('getOption'); |
|
218 |
settings = $('#'+name+'_settings_array').val(); |
|
219 |
if ( this.processing === false ) { |
|
220 |
this.processing = true; |
|
221 |
var count = parseInt(list.children('li').length); |
5
|
222 |
if ( type == 'list_item' || type == 'social_links' ) { |
0
|
223 |
list.find('li input.option-tree-setting-title', self).each(function(){ |
|
224 |
var setting = $(this).attr('name'), |
|
225 |
regex = /\[([0-9]+)\]/, |
|
226 |
matches = setting.match(regex), |
|
227 |
id = null != matches ? parseInt(matches[1]) : 0; |
|
228 |
id++; |
|
229 |
if ( id > count) { |
|
230 |
count = id; |
|
231 |
} |
|
232 |
}); |
|
233 |
} |
|
234 |
$.ajax({ |
|
235 |
url: option_tree.ajax, |
|
236 |
type: 'post', |
|
237 |
data: { |
|
238 |
action: 'add_' + type, |
|
239 |
count: count, |
|
240 |
name: name, |
|
241 |
post_id: post_id, |
|
242 |
get_option: get_option, |
|
243 |
settings: settings, |
|
244 |
type: type |
|
245 |
}, |
|
246 |
complete: function( data ) { |
|
247 |
if ( type == 'choice' || type == 'list_item_setting' ) { |
|
248 |
OT_UI.init_remove_active(list,'child-add'); |
|
249 |
OT_UI.init_hide_body(list,'child-add'); |
|
250 |
} else { |
|
251 |
OT_UI.init_remove_active(); |
|
252 |
OT_UI.init_hide_body(); |
|
253 |
} |
5
|
254 |
var listItem = $('<li class="ui-state-default ' + list_class + '">' + data.responseText + '</li>'); |
|
255 |
list.append(listItem); |
0
|
256 |
list.children().last().find('.option-tree-setting-edit').toggleClass('active'); |
|
257 |
list.children().last().find('.option-tree-setting-body').toggle(); |
|
258 |
list.children().last().find('.option-tree-setting-title').focus(); |
|
259 |
if ( type != 'the_contextual_help' ) { |
|
260 |
OT_UI.update_ids(list); |
|
261 |
} |
5
|
262 |
OT_UI.init_sortable(listItem); |
|
263 |
OT_UI.init_select_wrapper(listItem); |
|
264 |
OT_UI.init_numeric_slider(listItem); |
|
265 |
OT_UI.parse_condition(); |
0
|
266 |
self.processing = false; |
|
267 |
} |
|
268 |
}); |
|
269 |
} |
|
270 |
}, |
|
271 |
remove: function(e) { |
|
272 |
$(e).parent().parent().parent('li').remove(); |
|
273 |
}, |
|
274 |
edit_title: function(e) { |
|
275 |
if ( this.timer ) { |
|
276 |
clearTimeout(e.timer); |
|
277 |
} |
|
278 |
this.timer = setTimeout( function() { |
|
279 |
$(e).parent().parent().parent().parent().parent().children('.open').text(e.value); |
|
280 |
}, 100); |
|
281 |
return true; |
|
282 |
}, |
|
283 |
update_id: function(e) { |
|
284 |
if ( this.timer ) { |
|
285 |
clearTimeout(e.timer); |
|
286 |
} |
|
287 |
this.timer = setTimeout( function() { |
|
288 |
OT_UI.update_ids($(e).parents('ul')); |
|
289 |
}, 100); |
|
290 |
return true; |
|
291 |
}, |
|
292 |
update_ids: function(list) { |
|
293 |
var last_section, section, list_items = list.children('li'); |
|
294 |
list_items.each(function(index) { |
|
295 |
if ( $(this).hasClass('list-section') ) { |
|
296 |
section = $(this).find('.section-id').val().trim().toLowerCase().replace(/[^a-z0-9]/gi,'_'); |
|
297 |
if (!section) { |
|
298 |
section = $(this).find('.section-title').val().trim().toLowerCase().replace(/[^a-z0-9]/gi,'_'); |
|
299 |
} |
|
300 |
if (!section) { |
|
301 |
section = last_section; |
|
302 |
} |
|
303 |
} |
|
304 |
if ($(this).hasClass('list-setting') ) { |
|
305 |
$(this).find('.hidden-section').attr({'value':section}); |
|
306 |
} |
|
307 |
last_section = section; |
|
308 |
}); |
|
309 |
}, |
5
|
310 |
condition_objects: function() { |
|
311 |
return 'select, input[type="radio"]:checked, input[type="text"], input[type="hidden"], input.ot-numeric-slider-hidden-input'; |
|
312 |
}, |
|
313 |
match_conditions: function(condition) { |
|
314 |
var match; |
|
315 |
var regex = /(.+?):(is|not|contains|less_than|less_than_or_equal_to|greater_than|greater_than_or_equal_to)\((.*?)\),?/g; |
|
316 |
var conditions = []; |
|
317 |
|
|
318 |
while( match = regex.exec( condition ) ) { |
|
319 |
conditions.push({ |
|
320 |
'check': match[1], |
|
321 |
'rule': match[2], |
|
322 |
'value': match[3] || '' |
|
323 |
}); |
|
324 |
} |
|
325 |
|
|
326 |
return conditions; |
|
327 |
}, |
|
328 |
parse_condition: function() { |
|
329 |
$( '.format-settings[id^="setting_"][data-condition]' ).each(function() { |
|
330 |
|
|
331 |
var passed; |
|
332 |
var conditions = OT_UI.match_conditions( $( this ).data( 'condition' ) ); |
|
333 |
var operator = ( $( this ).data( 'operator' ) || 'and' ).toLowerCase(); |
|
334 |
|
|
335 |
$.each( conditions, function( index, condition ) { |
|
336 |
|
|
337 |
var target = $( '#setting_' + condition.check ); |
|
338 |
var targetEl = !! target.length && target.find( OT_UI.condition_objects() ).first(); |
|
339 |
|
|
340 |
if ( ! target.length || ( ! targetEl.length && condition.value.toString() != '' ) ) { |
|
341 |
return; |
|
342 |
} |
|
343 |
|
|
344 |
var v1 = targetEl.length ? targetEl.val().toString() : ''; |
|
345 |
var v2 = condition.value.toString(); |
|
346 |
var result; |
|
347 |
|
|
348 |
switch ( condition.rule ) { |
|
349 |
case 'less_than': |
|
350 |
result = ( parseInt( v1 ) < parseInt( v2 ) ); |
|
351 |
break; |
|
352 |
case 'less_than_or_equal_to': |
|
353 |
result = ( parseInt( v1 ) <= parseInt( v2 ) ); |
|
354 |
break; |
|
355 |
case 'greater_than': |
|
356 |
result = ( parseInt( v1 ) > parseInt( v2 ) ); |
|
357 |
break; |
|
358 |
case 'greater_than_or_equal_to': |
|
359 |
result = ( parseInt( v1 ) >= parseInt( v2 ) ); |
|
360 |
break; |
|
361 |
case 'contains': |
|
362 |
result = ( v1.indexOf(v2) !== -1 ? true : false ); |
|
363 |
break; |
|
364 |
case 'is': |
|
365 |
result = ( v1 == v2 ); |
|
366 |
break; |
|
367 |
case 'not': |
|
368 |
result = ( v1 != v2 ); |
|
369 |
break; |
|
370 |
} |
|
371 |
|
|
372 |
if ( 'undefined' == typeof passed ) { |
|
373 |
passed = result; |
|
374 |
} |
|
375 |
|
|
376 |
switch ( operator ) { |
|
377 |
case 'or': |
|
378 |
passed = ( passed || result ); |
|
379 |
break; |
|
380 |
case 'and': |
|
381 |
default: |
|
382 |
passed = ( passed && result ); |
|
383 |
break; |
|
384 |
} |
|
385 |
|
|
386 |
}); |
|
387 |
|
|
388 |
if ( passed ) { |
|
389 |
$(this).animate({opacity: 'show' , height: 'show'}, 200); |
|
390 |
} else { |
|
391 |
$(this).animate({opacity: 'hide' , height: 'hide'}, 200); |
|
392 |
} |
|
393 |
|
|
394 |
delete passed; |
|
395 |
|
|
396 |
}); |
|
397 |
}, |
|
398 |
init_conditions: function() { |
|
399 |
var delay = (function() { |
|
400 |
var timer = 0; |
|
401 |
return function(callback, ms) { |
|
402 |
clearTimeout(timer); |
|
403 |
timer = setTimeout(callback, ms); |
|
404 |
}; |
|
405 |
})(); |
|
406 |
|
|
407 |
$('.format-settings[id^="setting_"]').on( 'change.conditionals, keyup.conditionals', OT_UI.condition_objects(), function(e) { |
|
408 |
if (e.type === 'keyup') { |
|
409 |
// handle keyup event only once every 500ms |
|
410 |
delay(function() { |
|
411 |
OT_UI.parse_condition(); |
|
412 |
}, 500); |
|
413 |
} else { |
|
414 |
OT_UI.parse_condition(); |
|
415 |
} |
|
416 |
OT_UI.load_editors(); |
|
417 |
}); |
|
418 |
OT_UI.parse_condition(); |
|
419 |
}, |
0
|
420 |
init_upload: function() { |
|
421 |
$(document).on('click', '.ot_upload_media', function() { |
5
|
422 |
var field_id = $(this).parent('.option-tree-ui-upload-parent').find('input').attr('id'), |
|
423 |
post_id = $(this).attr('rel'), |
|
424 |
save_attachment_id = $('#'+field_id).hasClass('ot-upload-attachment-id'), |
|
425 |
btnContent = ''; |
0
|
426 |
if ( window.wp && wp.media ) { |
|
427 |
window.ot_media_frame = window.ot_media_frame || new wp.media.view.MediaFrame.Select({ |
|
428 |
title: $(this).attr('title'), |
|
429 |
button: { |
|
430 |
text: option_tree.upload_text |
|
431 |
}, |
|
432 |
multiple: false |
|
433 |
}); |
|
434 |
window.ot_media_frame.on('select', function() { |
|
435 |
var attachment = window.ot_media_frame.state().get('selection').first(), |
5
|
436 |
href = attachment.attributes.url, |
|
437 |
attachment_id = attachment.attributes.id, |
0
|
438 |
mime = attachment.attributes.mime, |
|
439 |
regex = /^image\/(?:jpe?g|png|gif|x-icon)$/i; |
|
440 |
if ( mime.match(regex) ) { |
|
441 |
btnContent += '<div class="option-tree-ui-image-wrap"><img src="'+href+'" alt="" /></div>'; |
|
442 |
} |
5
|
443 |
btnContent += '<a href="javascript:(void);" class="option-tree-ui-remove-media option-tree-ui-button button button-secondary light" title="'+option_tree.remove_media_text+'"><span class="icon ot-icon-minus-circle"></span>'+option_tree.remove_media_text+'</a>'; |
|
444 |
$('#'+field_id).val( ( save_attachment_id ? attachment_id : href ) ); |
0
|
445 |
$('#'+field_id+'_media').remove(); |
|
446 |
$('#'+field_id).parent().parent('div').append('<div class="option-tree-ui-media-wrap" id="'+field_id+'_media" />'); |
|
447 |
$('#'+field_id+'_media').append(btnContent).slideDown(); |
|
448 |
window.ot_media_frame.off('select'); |
|
449 |
}).open(); |
|
450 |
} else { |
|
451 |
var backup = window.send_to_editor, |
|
452 |
intval = window.setInterval( |
|
453 |
function() { |
|
454 |
if ( $('#TB_iframeContent').length > 0 && $('#TB_iframeContent').attr('src').indexOf( "&field_id=" ) !== -1 ) { |
|
455 |
$('#TB_iframeContent').contents().find('#tab-type_url').hide(); |
|
456 |
} |
|
457 |
$('#TB_iframeContent').contents().find('.savesend .button').val(option_tree.upload_text); |
|
458 |
}, 50); |
|
459 |
tb_show('', 'media-upload.php?post_id='+post_id+'&field_id='+field_id+'&type=image&TB_iframe=1'); |
|
460 |
window.send_to_editor = function(html) { |
|
461 |
var href = $(html).find('img').attr('src'); |
|
462 |
if ( typeof href == 'undefined') { |
|
463 |
href = $(html).attr('src'); |
|
464 |
} |
|
465 |
if ( typeof href == 'undefined') { |
|
466 |
href = $(html).attr('href'); |
|
467 |
} |
|
468 |
var image = /\.(?:jpe?g|png|gif|ico)$/i; |
|
469 |
if (href.match(image) && OT_UI.url_exists(href)) { |
|
470 |
btnContent += '<div class="option-tree-ui-image-wrap"><img src="'+href+'" alt="" /></div>'; |
|
471 |
} |
5
|
472 |
btnContent += '<a href="javascript:(void);" class="option-tree-ui-remove-media option-tree-ui-button button button-secondary light" title="'+option_tree.remove_media_text+'"><span class="icon ot-icon-minus-circle"></span>'+option_tree.remove_media_text+'</a>'; |
0
|
473 |
$('#'+field_id).val(href); |
|
474 |
$('#'+field_id+'_media').remove(); |
|
475 |
$('#'+field_id).parent().parent('div').append('<div class="option-tree-ui-media-wrap" id="'+field_id+'_media" />'); |
|
476 |
$('#'+field_id+'_media').append(btnContent).slideDown(); |
|
477 |
OT_UI.fix_upload_parent(); |
|
478 |
tb_remove(); |
|
479 |
window.clearInterval(intval); |
|
480 |
window.send_to_editor = backup; |
|
481 |
}; |
|
482 |
} |
|
483 |
return false; |
|
484 |
}); |
|
485 |
}, |
|
486 |
init_upload_remove: function() { |
5
|
487 |
$(document).on('click', '.option-tree-ui-remove-media', function(event) { |
0
|
488 |
event.preventDefault(); |
|
489 |
var agree = confirm(option_tree.remove_agree); |
|
490 |
if (agree) { |
|
491 |
OT_UI.remove_image(this); |
|
492 |
return false; |
|
493 |
} |
|
494 |
return false; |
|
495 |
}); |
|
496 |
}, |
|
497 |
init_upload_fix: function(elm) { |
|
498 |
var id = $(elm).attr('id'), |
|
499 |
val = $(elm).val(), |
5
|
500 |
img = $(elm).parent().next('.option-tree-ui-media-wrap').find('img'), |
0
|
501 |
src = img.attr('src'), |
|
502 |
btnContent = ''; |
5
|
503 |
if ( val == src ) { |
|
504 |
return; |
|
505 |
} |
0
|
506 |
if ( val != src ) { |
|
507 |
img.attr('src', val); |
|
508 |
} |
|
509 |
if ( val !== '' && ( typeof src == 'undefined' || src == false ) && OT_UI.url_exists(val) ) { |
|
510 |
var image = /\.(?:jpe?g|png|gif|ico)$/i; |
|
511 |
if (val.match(image)) { |
|
512 |
btnContent += '<div class="option-tree-ui-image-wrap"><img src="'+val+'" alt="" /></div>'; |
|
513 |
} |
5
|
514 |
btnContent += '<a href="javascript:(void);" class="option-tree-ui-remove-media option-tree-ui-button button button-secondary light" title="'+option_tree.remove_media_text+'"><span class="icon ot-icon-minus-circle">'+option_tree.remove_media_text+'</span></a>'; |
0
|
515 |
$('#'+id).val(val); |
|
516 |
$('#'+id+'_media').remove(); |
|
517 |
$('#'+id).parent().parent('div').append('<div class="option-tree-ui-media-wrap" id="'+id+'_media" />'); |
|
518 |
$('#'+id+'_media').append(btnContent).slideDown(); |
|
519 |
} else if ( val == '' || ! OT_UI.url_exists(val) ) { |
|
520 |
$(elm).parent().next('.option-tree-ui-media-wrap').remove(); |
|
521 |
} |
|
522 |
}, |
5
|
523 |
init_numeric_slider: function(scope) { |
|
524 |
scope = scope || document; |
|
525 |
$(".ot-numeric-slider-wrap", scope).each(function() { |
0
|
526 |
var hidden = $(".ot-numeric-slider-hidden-input", this), |
|
527 |
value = hidden.val(), |
|
528 |
helper = $(".ot-numeric-slider-helper-input", this); |
|
529 |
if ( ! value ) { |
|
530 |
value = hidden.data("min"); |
|
531 |
helper.val(value) |
|
532 |
} |
|
533 |
$(".ot-numeric-slider", this).slider({ |
|
534 |
min: hidden.data("min"), |
|
535 |
max: hidden.data("max"), |
|
536 |
step: hidden.data("step"), |
|
537 |
value: value, |
|
538 |
slide: function(event, ui) { |
5
|
539 |
hidden.add(helper).val(ui.value).trigger('change'); |
|
540 |
}, |
|
541 |
create: function()Â { |
|
542 |
hidden.val($(this).slider('value')); |
|
543 |
}, |
|
544 |
change: function() { |
|
545 |
OT_UI.parse_condition(); |
0
|
546 |
} |
|
547 |
}); |
|
548 |
}); |
|
549 |
}, |
|
550 |
init_tabs: function() { |
|
551 |
$(".wrap.settings-wrap .ui-tabs").tabs({ |
|
552 |
fx: { |
|
553 |
opacity: "toggle", |
|
554 |
duration: "fast" |
|
555 |
} |
|
556 |
}); |
|
557 |
$(".wrap.settings-wrap .ui-tabs a.ui-tabs-anchor").on("click", function(event, ui) { |
|
558 |
var obj = "input[name='_wp_http_referer']"; |
|
559 |
if ( $(obj).length > 0 ) { |
|
560 |
var url = $(obj).val(), |
|
561 |
hash = $(this).attr('href'); |
|
562 |
if ( url.indexOf("#") != -1 ) { |
|
563 |
var o = url.split("#")[1], |
|
564 |
n = hash.split("#")[1]; |
|
565 |
url = url.replace(o, n); |
|
566 |
} else { |
|
567 |
url = url + hash; |
|
568 |
} |
|
569 |
$(obj).val(url); |
|
570 |
} |
|
571 |
}); |
|
572 |
}, |
|
573 |
init_radio_image_select: function() { |
5
|
574 |
$(document).on('click', '.option-tree-ui-radio-image', function() { |
0
|
575 |
$(this).closest('.type-radio-image').find('.option-tree-ui-radio-image').removeClass('option-tree-ui-radio-image-selected'); |
|
576 |
$(this).toggleClass('option-tree-ui-radio-image-selected'); |
5
|
577 |
$(this).parent().find('.option-tree-ui-radio').prop('checked', true).trigger('change'); |
0
|
578 |
}); |
|
579 |
}, |
5
|
580 |
init_select_wrapper: function(scope) { |
|
581 |
scope = scope || document; |
|
582 |
$('.option-tree-ui-select', scope).each(function () { |
0
|
583 |
if ( ! $(this).parent().hasClass('select-wrapper') ) { |
|
584 |
$(this).wrap('<div class="select-wrapper" />'); |
|
585 |
$(this).parent('.select-wrapper').prepend('<span>' + $(this).find('option:selected').text() + '</span>'); |
|
586 |
} |
|
587 |
}); |
5
|
588 |
}, |
|
589 |
bind_select_wrapper: function() { |
|
590 |
$(document).on('change', '.option-tree-ui-select', function () { |
0
|
591 |
$(this).prev('span').replaceWith('<span>' + $(this).find('option:selected').text() + '</span>'); |
|
592 |
}); |
5
|
593 |
}, |
|
594 |
init_google_fonts: function() { |
|
595 |
var update_items = function(input, items, element) { |
|
596 |
var itemsUI = input.closest('.type-google-font-group').find(element); |
|
597 |
if ( itemsUI.length ) { |
|
598 |
itemsUI.empty(); |
|
599 |
itemsUI.append($.map(items, function(item) { |
|
600 |
var input = document.createElement('input'), |
|
601 |
label = document.createElement('label'); |
|
602 |
input.type = 'checkbox'; |
|
603 |
input.id = ( itemsUI.data('field-id-prefix') || '' ) + item; |
|
604 |
input.name = ( itemsUI.data('field-name') || '' ) + '[]'; |
|
605 |
input.value = item; |
|
606 |
label.innerHTML = item; |
|
607 |
$( label ).attr( 'for', input.id ); |
|
608 |
return $( document.createElement('p') ).addClass('checkbox-wrap').append([input, label]); |
|
609 |
})); |
|
610 |
} |
|
611 |
}; |
|
612 |
$(document).on('change', '.option-tree-google-font-family select', function() { |
|
613 |
var input = $(this); |
|
614 |
$.ajax({ |
|
615 |
url: option_tree.ajax, |
|
616 |
type: 'POST', |
|
617 |
dataType: 'json', |
|
618 |
data: { |
|
619 |
action: 'ot_google_font', |
|
620 |
family: input.val(), |
|
621 |
field_id: input.attr('id') |
|
622 |
} |
|
623 |
}).done(function(response) { |
|
624 |
if ( response.hasOwnProperty('variants') ) { |
|
625 |
update_items( input, response.variants, '.option-tree-google-font-variants' ); |
|
626 |
} |
|
627 |
if ( response.hasOwnProperty('subsets') ) { |
|
628 |
update_items( input, response.subsets, '.option-tree-google-font-subsets' ); |
|
629 |
} |
|
630 |
}); |
|
631 |
}); |
|
632 |
$('.js-add-google-font').on('click', function (event) { |
|
633 |
var $group = $(this).parent('.format-setting-inner').find('.type-google-font-group'), |
|
634 |
$el_clone = $(this).prev('.type-google-font-group-clone'), |
|
635 |
$clone = $el_clone.clone(true), |
|
636 |
$count = $group.length ? $group.length : 0; |
|
637 |
$clone.attr('class', 'type-google-font-group'); |
|
638 |
var replacer = function(index, elm) { |
|
639 |
return elm.replace('%key%', $count); |
|
640 |
} |
|
641 |
$('select', $clone).each( function() { |
|
642 |
$(this).attr('id', replacer ).attr('name', replacer ); |
|
643 |
}); |
|
644 |
$('.option-tree-google-font-variants', $clone).each( function() { |
|
645 |
$(this).attr('data-field-id-prefix', replacer ).attr('data-field-name', replacer ); |
|
646 |
}); |
|
647 |
$('.option-tree-google-font-subsets', $clone).each( function() { |
|
648 |
$(this).attr('data-field-id-prefix', replacer ).attr('data-field-name', replacer ); |
|
649 |
}); |
|
650 |
$el_clone.before($clone) |
|
651 |
event.preventDefault() |
|
652 |
}); |
|
653 |
$('.js-remove-google-font').on('click', function (event) { |
|
654 |
$(this).parents('.type-google-font-group').remove(); |
|
655 |
event.preventDefault(); |
0
|
656 |
}); |
|
657 |
}, |
|
658 |
bind_colorpicker: function(field_id) { |
5
|
659 |
$('#'+field_id).wpColorPicker({ |
|
660 |
change: function() { |
|
661 |
OT_UI.parse_condition(); |
|
662 |
}, |
|
663 |
clear: function() { |
|
664 |
OT_UI.parse_condition(); |
0
|
665 |
} |
5
|
666 |
}); |
|
667 |
}, |
|
668 |
bind_date_picker: function(field_id, date_format) { |
|
669 |
$('#'+field_id).datepicker({ |
|
670 |
showOtherMonths: true, |
|
671 |
showButtonPanel: true, |
|
672 |
currentText: option_tree.date_current, |
|
673 |
closeText: option_tree.date_close, |
|
674 |
dateFormat: date_format |
|
675 |
}); |
|
676 |
}, |
|
677 |
bind_date_time_picker: function(field_id, date_format) { |
|
678 |
$('#'+field_id).datetimepicker({ |
|
679 |
showOtherMonths: true, |
|
680 |
closeText: option_tree.date_close, |
|
681 |
dateFormat: date_format |
0
|
682 |
}); |
|
683 |
}, |
|
684 |
fix_upload_parent: function() { |
5
|
685 |
$('.option-tree-ui-upload-input').not('.ot-upload-attachment-id').on('focus blur', function(){ |
0
|
686 |
$(this).parent('.option-tree-ui-upload-parent').toggleClass('focus'); |
|
687 |
OT_UI.init_upload_fix(this); |
|
688 |
}); |
|
689 |
}, |
|
690 |
remove_image: function(e) { |
|
691 |
$(e).parent().parent().find('.option-tree-ui-upload-input').attr('value',''); |
|
692 |
$(e).parent('.option-tree-ui-media-wrap').remove(); |
|
693 |
}, |
|
694 |
fix_textarea: function() { |
|
695 |
$('.wp-editor-area').focus( function(){ |
|
696 |
$(this).parent('div').css({borderColor:'#bbb'}); |
|
697 |
}).blur( function(){ |
|
698 |
$(this).parent('div').css({borderColor:'#ccc'}); |
|
699 |
}); |
|
700 |
}, |
|
701 |
replicate_ajax: function() { |
|
702 |
if (location.href.indexOf("#") != -1) { |
|
703 |
var url = $("input[name=\'_wp_http_referer\']").val(), |
|
704 |
hash = location.href.substr(location.href.indexOf("#")); |
|
705 |
$("input[name=\'_wp_http_referer\']").val( url + hash ); |
|
706 |
this.scroll_to_top(); |
|
707 |
} |
|
708 |
setTimeout( function() { |
|
709 |
$(".wrap.settings-wrap .fade").fadeOut("fast"); |
|
710 |
}, 3000 ); |
|
711 |
}, |
|
712 |
reset_settings: function() { |
5
|
713 |
$(document).on("click", ".reset-settings", function(event){ |
0
|
714 |
var agree = confirm(option_tree.reset_agree); |
|
715 |
if (agree) { |
|
716 |
return true; |
|
717 |
} else { |
|
718 |
return false; |
|
719 |
} |
|
720 |
event.preventDefault(); |
|
721 |
}); |
|
722 |
}, |
5
|
723 |
css_editor_mode: function() { |
|
724 |
$('.ot-css-editor').each(function() { |
|
725 |
var editor = ace.edit($(this).attr('id')); |
|
726 |
var this_textarea = $('#textarea_' + $(this).attr('id')); |
|
727 |
editor.setTheme("ace/theme/chrome"); |
|
728 |
editor.getSession().setMode("ace/mode/css"); |
|
729 |
editor.setShowPrintMargin( false ); |
|
730 |
|
|
731 |
editor.getSession().setValue(this_textarea.val()); |
|
732 |
editor.getSession().on('change', function(){ |
|
733 |
this_textarea.val(editor.getSession().getValue()); |
|
734 |
}); |
|
735 |
this_textarea.on('change', function(){ |
|
736 |
editor.getSession().setValue(this_textarea.val()); |
|
737 |
}); |
|
738 |
}); |
|
739 |
}, |
|
740 |
javascript_editor_mode: function() { |
|
741 |
$('.ot-javascript-editor').each(function() { |
|
742 |
var editor = ace.edit($(this).attr('id')); |
|
743 |
var this_textarea = $('#textarea_' + $(this).attr('id')); |
|
744 |
editor.setTheme("ace/theme/chrome"); |
|
745 |
editor.getSession().setMode("ace/mode/javascript"); |
|
746 |
editor.setShowPrintMargin( false ); |
|
747 |
|
|
748 |
editor.getSession().setValue(this_textarea.val()); |
|
749 |
editor.getSession().on('change', function(){ |
|
750 |
this_textarea.val(editor.getSession().getValue()); |
|
751 |
}); |
|
752 |
this_textarea.on('change', function(){ |
|
753 |
editor.getSession().setValue(this_textarea.val()); |
|
754 |
}); |
|
755 |
}); |
|
756 |
}, |
|
757 |
load_editors: function() { |
|
758 |
OT_UI.css_editor_mode(); |
|
759 |
OT_UI.javascript_editor_mode(); |
|
760 |
}, |
0
|
761 |
url_exists: function(url) { |
5
|
762 |
var link = document.createElement('a') |
|
763 |
link.href = url |
|
764 |
if ( link.hostname != window.location.hostname ) { |
|
765 |
return true; // Stop the code from checking across domains. |
|
766 |
} |
0
|
767 |
var http = new XMLHttpRequest(); |
|
768 |
http.open('HEAD', url, false); |
|
769 |
http.send(); |
|
770 |
return http.status!=404; |
|
771 |
}, |
|
772 |
scroll_to_top: function() { |
|
773 |
setTimeout( function() { |
|
774 |
$(this).scrollTop(0); |
|
775 |
}, 50 ); |
|
776 |
} |
|
777 |
}; |
|
778 |
$(document).ready( function() { |
|
779 |
OT_UI.init(); |
|
780 |
}); |
5
|
781 |
})(jQuery); |
|
782 |
|
|
783 |
/* Gallery */ |
|
784 |
!function ($) { |
|
785 |
|
|
786 |
ot_gallery = { |
|
787 |
|
|
788 |
frame: function (elm) { |
|
789 |
|
|
790 |
var selection = this.select(elm) |
|
791 |
|
|
792 |
this._frame = wp.media({ |
|
793 |
id: 'ot-gallery-frame' |
|
794 |
, frame: 'post' |
|
795 |
, state: 'gallery-edit' |
|
796 |
, title: wp.media.view.l10n.editGalleryTitle |
|
797 |
, editing: true |
|
798 |
, multiple: true |
|
799 |
, selection: selection |
|
800 |
}) |
|
801 |
|
|
802 |
this._frame.on('update', function () { |
|
803 |
var controller = ot_gallery._frame.states.get('gallery-edit') |
|
804 |
, library = controller.get('library') |
|
805 |
, ids = library.pluck('id') |
|
806 |
, parent = $(elm).parents('.format-setting-inner') |
|
807 |
, input = parent.children('.ot-gallery-value') |
|
808 |
, shortcode = wp.media.gallery.shortcode( selection ).string().replace(/\"/g,"'") |
|
809 |
|
|
810 |
input.attr('value', ids) |
|
811 |
|
|
812 |
if ( parent.children('.ot-gallery-list').length <= 0 ) |
|
813 |
input.after('<ul class="ot-gallery-list" />') |
|
814 |
|
|
815 |
$.ajax({ |
|
816 |
type: 'POST', |
|
817 |
url: ajaxurl, |
|
818 |
dataType: 'html', |
|
819 |
data: { |
|
820 |
action: 'gallery_update' |
|
821 |
, ids: ids |
|
822 |
}, |
|
823 |
success: function(res) { |
|
824 |
parent.children('.ot-gallery-list').html(res); |
|
825 |
if ( input.hasClass('ot-gallery-shortcode') ) { |
|
826 |
input.val(shortcode); |
|
827 |
} |
|
828 |
if ( $(elm).parent().children('.ot-gallery-delete').length <= 0 ) { |
|
829 |
$(elm).parent().append('<a href="#" class="option-tree-ui-button button button-secondary hug-left ot-gallery-delete">' + option_tree.delete + '</a>'); |
|
830 |
} |
|
831 |
$(elm).text(option_tree.edit); |
|
832 |
OT_UI.parse_condition(); |
|
833 |
} |
|
834 |
}) |
|
835 |
}) |
|
836 |
|
|
837 |
return this._frame |
|
838 |
|
|
839 |
} |
|
840 |
|
|
841 |
, select: function (elm) { |
|
842 |
var input = $(elm).parents('.format-setting-inner').children('.ot-gallery-value') |
|
843 |
, ids = input.attr('value') |
|
844 |
, _shortcode = input.hasClass('ot-gallery-shortcode') ? ids : '[gallery ids=\'' + ids + '\]' |
|
845 |
, shortcode = wp.shortcode.next('gallery', ( ids ? _shortcode : wp.media.view.settings.ot_gallery.shortcode ) ) |
|
846 |
, defaultPostId = wp.media.gallery.defaults.id |
|
847 |
, attachments |
|
848 |
, selection |
|
849 |
|
|
850 |
// Bail if we didn't match the shortcode or all of the content. |
|
851 |
if ( ! shortcode ) |
|
852 |
return |
|
853 |
|
|
854 |
// Ignore the rest of the match object. |
|
855 |
shortcode = shortcode.shortcode |
|
856 |
|
|
857 |
if ( _.isUndefined( shortcode.get('id') ) && ! _.isUndefined( defaultPostId ) ) |
|
858 |
shortcode.set( 'id', defaultPostId ) |
|
859 |
|
|
860 |
if ( _.isUndefined( shortcode.get('ids') ) && ! input.hasClass('ot-gallery-shortcode') && ids ) |
|
861 |
shortcode.set( 'ids', ids ) |
|
862 |
|
|
863 |
if ( _.isUndefined( shortcode.get('ids') ) ) |
|
864 |
shortcode.set( 'ids', '0' ) |
|
865 |
|
|
866 |
attachments = wp.media.gallery.attachments( shortcode ) |
|
867 |
|
|
868 |
selection = new wp.media.model.Selection( attachments.models, { |
|
869 |
props: attachments.props.toJSON() |
|
870 |
, multiple: true |
|
871 |
}) |
|
872 |
|
|
873 |
selection.gallery = attachments.gallery |
|
874 |
|
|
875 |
// Fetch the query's attachments, and then break ties from the query to allow for sorting. |
|
876 |
selection.more().done( function () { |
|
877 |
selection.props.set({ query: false }) |
|
878 |
selection.unmirror() |
|
879 |
selection.props.unset('orderby') |
|
880 |
}) |
|
881 |
|
|
882 |
return selection |
|
883 |
|
|
884 |
} |
|
885 |
|
|
886 |
, open: function (elm) { |
|
887 |
|
|
888 |
ot_gallery.frame(elm).open() |
|
889 |
|
|
890 |
} |
|
891 |
|
|
892 |
, remove: function (elm) { |
|
893 |
|
|
894 |
if ( confirm( option_tree.confirm ) ) { |
|
895 |
|
|
896 |
$(elm).parents('.format-setting-inner').children('.ot-gallery-value').attr('value', ''); |
|
897 |
$(elm).parents('.format-setting-inner').children('.ot-gallery-list').remove(); |
|
898 |
$(elm).next('.ot-gallery-edit').text( option_tree.create ); |
|
899 |
$(elm).remove(); |
|
900 |
OT_UI.parse_condition(); |
|
901 |
|
|
902 |
} |
|
903 |
|
|
904 |
} |
|
905 |
|
|
906 |
} |
|
907 |
|
|
908 |
// Gallery delete |
|
909 |
$(document).on('click.ot_gallery.data-api', '.ot-gallery-delete', function (e) { |
|
910 |
e.preventDefault() |
|
911 |
ot_gallery.remove($(this)) |
|
912 |
}) |
|
913 |
|
|
914 |
// Gallery edit |
|
915 |
$(document).on('click.ot_gallery.data-api', '.ot-gallery-edit', function (e) { |
|
916 |
e.preventDefault() |
|
917 |
ot_gallery.open($(this)) |
|
918 |
}) |
|
919 |
|
|
920 |
}(window.jQuery); |
|
921 |
|
|
922 |
/*! |
|
923 |
* Adds metabox tabs |
|
924 |
*/ |
|
925 |
!function ($) { |
|
926 |
|
|
927 |
$(document).on('ready', function () { |
|
928 |
|
|
929 |
// Loop over the metaboxes |
|
930 |
$('.ot-metabox-wrapper').each( function() { |
|
931 |
|
|
932 |
// Only if there is a tab option |
|
933 |
if ( $(this).find('.type-tab').length ) { |
|
934 |
|
|
935 |
// Add .ot-metabox-panels |
|
936 |
$(this).find('.type-tab').parents('.ot-metabox-wrapper').wrapInner('<div class="ot-metabox-panels" />') |
|
937 |
|
|
938 |
// Wrapp with .ot-metabox-tabs & add .ot-metabox-nav before .ot-metabox-panels |
|
939 |
$(this).find('.ot-metabox-panels').wrap('<div class="ot-metabox-tabs" />').before('<ul class="ot-metabox-nav" />') |
|
940 |
|
|
941 |
// Loop over settings and build the tabs nav |
|
942 |
$(this).find('.format-settings').each( function() { |
|
943 |
|
|
944 |
if ( $(this).find('.type-tab').length > 0 ) { |
|
945 |
var title = $(this).find('.type-tab').prev().find('label').text() |
|
946 |
, id = $(this).attr('id') |
|
947 |
|
|
948 |
// Add a class, hide & append nav item |
|
949 |
$(this).addClass('is-panel').hide() |
|
950 |
$(this).parents('.ot-metabox-panels').prev('.ot-metabox-nav').append('<li><a href="#' + id + '">' + title + '</a></li>') |
|
951 |
|
|
952 |
} |
|
953 |
|
|
954 |
}) |
|
955 |
|
|
956 |
// Loop over the panels and wrap and ID them. |
|
957 |
$(this).find('.is-panel').each( function() { |
|
958 |
var id = $(this).attr('id') |
|
959 |
|
|
960 |
$(this).add( $(this).nextUntil('.is-panel') ).wrapAll('<div id="' + id + '" class="tab-content" />') |
|
961 |
|
|
962 |
}) |
|
963 |
|
|
964 |
// Create the tabs |
|
965 |
$(this).find('.ot-metabox-tabs').tabs({ |
|
966 |
activate: function( event, ui ) { |
|
967 |
var parent = $(this).outerHeight(), |
|
968 |
child = $(this).find('.ot-metabox-panels').outerHeight() + 8, |
|
969 |
minHeight = parent - 34 |
|
970 |
if ( $(this).find('.ot-metabox-panels').css('padding') == '12px' && child < parent ) { |
|
971 |
$(this).find('.ot-metabox-panels').css({ minHeight: minHeight }) |
|
972 |
} |
|
973 |
OT_UI.load_editors(); |
|
974 |
} |
|
975 |
}) |
|
976 |
|
|
977 |
// Move the orphaned settings to the top |
|
978 |
$(this).find('.ot-metabox-panels > .format-settings').prependTo($(this)) |
|
979 |
|
|
980 |
// Remove a bunch of classes to stop style conflicts. |
|
981 |
$(this).find('.ot-metabox-tabs').removeClass('ui-widget ui-widget-content ui-corner-all') |
|
982 |
$(this).find('.ot-metabox-nav').removeClass('ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all') |
|
983 |
$(this).find('.ot-metabox-nav li').removeClass('ui-state-default ui-corner-top ui-tabs-active ui-tabs-active') |
|
984 |
$(this).find('.ot-metabox-nav li').on('mouseenter mouseleave', function() { $(this).removeClass('ui-state-hover') }) |
|
985 |
|
|
986 |
} |
|
987 |
|
|
988 |
}) |
|
989 |
|
|
990 |
}) |
|
991 |
|
|
992 |
}(window.jQuery); |
|
993 |
|
|
994 |
/*! |
|
995 |
* Adds theme option tabs |
|
996 |
*/ |
|
997 |
!function ($) { |
|
998 |
|
|
999 |
$(document).on('ready', function () { |
|
1000 |
|
|
1001 |
// Loop over the theme options |
|
1002 |
$('#option-tree-settings-api .inside').each( function() { |
|
1003 |
|
|
1004 |
// Only if there is a tab option |
|
1005 |
if ( $(this).find('.type-tab').length ) { |
|
1006 |
|
|
1007 |
// Add .ot-theme-option-panels |
|
1008 |
$(this).find('.type-tab').parents('.inside').wrapInner('<div class="ot-theme-option-panels" />') |
|
1009 |
|
|
1010 |
// Wrap with .ot-theme-option-tabs & add .ot-theme-option-nav before .ot-theme-option-panels |
|
1011 |
$(this).find('.ot-theme-option-panels').wrap('<div class="ot-theme-option-tabs" />').before('<ul class="ot-theme-option-nav" />') |
|
1012 |
|
|
1013 |
// Loop over settings and build the tabs nav |
|
1014 |
$(this).find('.format-settings').each( function() { |
|
1015 |
|
|
1016 |
if ( $(this).find('.type-tab').length > 0 ) { |
|
1017 |
var title = $(this).find('.type-tab').prev().find('.label').text() |
|
1018 |
, id = $(this).attr('id') |
|
1019 |
|
|
1020 |
// Add a class, hide & append nav item |
|
1021 |
$(this).addClass('is-panel').hide() |
|
1022 |
$(this).parents('.ot-theme-option-panels').prev('.ot-theme-option-nav').append('<li><a href="#' + id + '">' + title + '</a></li>') |
|
1023 |
|
|
1024 |
} else { |
|
1025 |
|
|
1026 |
} |
|
1027 |
|
|
1028 |
}) |
|
1029 |
|
|
1030 |
// Loop over the panels and wrap and ID them. |
|
1031 |
$(this).find('.is-panel').each( function() { |
|
1032 |
var id = $(this).attr('id') |
|
1033 |
|
|
1034 |
$(this).add( $(this).nextUntil('.is-panel') ).wrapAll('<div id="' + id + '" class="tab-content" />') |
|
1035 |
|
|
1036 |
}) |
|
1037 |
|
|
1038 |
// Create the tabs |
|
1039 |
$(this).find('.ot-theme-option-tabs').tabs({ |
|
1040 |
activate: function( event, ui ) { |
|
1041 |
OT_UI.load_editors(); |
|
1042 |
} |
|
1043 |
}) |
|
1044 |
|
|
1045 |
// Move the orphaned settings to the top |
|
1046 |
$(this).find('.ot-theme-option-panels > .format-settings').prependTo($(this).find('.ot-theme-option-tabs')) |
|
1047 |
|
|
1048 |
} |
|
1049 |
|
|
1050 |
}) |
|
1051 |
|
|
1052 |
}) |
|
1053 |
|
|
1054 |
}(window.jQuery); |
|
1055 |
|
|
1056 |
/*! |
|
1057 |
* Fixes the state of metabox radio buttons after a Drag & Drop event. |
|
1058 |
*/ |
|
1059 |
!function ($) { |
|
1060 |
|
|
1061 |
$(document).on('ready', function () { |
|
1062 |
|
|
1063 |
// detect mousedown and store all checked radio buttons |
|
1064 |
$('.hndle').on('mousedown', function () { |
|
1065 |
|
|
1066 |
// get parent element of .hndle selected. |
|
1067 |
// We only need to monitor radios insde the object that is being moved. |
|
1068 |
var parent_id = $(this).closest('div').attr('id') |
|
1069 |
|
|
1070 |
// set live event listener for mouse up on the content .wrap |
|
1071 |
// then give the dragged div time to settle before firing the reclick function |
|
1072 |
$('.wrap').on('mouseup', function () { |
|
1073 |
|
|
1074 |
var ot_checked_radios = {} |
|
1075 |
|
|
1076 |
// loop over all checked radio buttons inside of parent element |
|
1077 |
$('#' + parent_id + ' input[type="radio"]').each( function () { |
|
1078 |
|
|
1079 |
// stores checked radio buttons |
|
1080 |
if ( $(this).is(':checked') ) { |
|
1081 |
|
|
1082 |
ot_checked_radios[$(this).attr('name')] = $(this).val() |
|
1083 |
|
|
1084 |
} |
|
1085 |
|
|
1086 |
// write to the object |
|
1087 |
$(document).data('ot_checked_radios', ot_checked_radios) |
|
1088 |
|
|
1089 |
}) |
|
1090 |
|
|
1091 |
// restore all checked radio buttons |
|
1092 |
setTimeout( function () { |
|
1093 |
|
|
1094 |
// get object of checked radio button names and values |
|
1095 |
var checked = $(document).data('ot_checked_radios') |
|
1096 |
|
|
1097 |
// step thru each object element and trigger a click on it's corresponding radio button |
|
1098 |
for ( key in checked ) { |
|
1099 |
|
|
1100 |
$('input[name="' + key + '"]').filter('[value="' + checked[key] + '"]').trigger('click') |
|
1101 |
|
|
1102 |
} |
|
1103 |
|
|
1104 |
$('.wrap').unbind('mouseup') |
|
1105 |
|
|
1106 |
}, 50 ) |
|
1107 |
|
|
1108 |
}) |
|
1109 |
|
|
1110 |
}) |
|
1111 |
|
|
1112 |
}) |
|
1113 |
|
|
1114 |
}(window.jQuery); |
|
1115 |
|
|
1116 |
/*! |
|
1117 |
* Adds opacity to the default colorpicker |
|
1118 |
* |
|
1119 |
* Derivative work of the Codestar WP Color Picker. |
|
1120 |
*/ |
|
1121 |
;(function ( $, window, document, undefined ) { |
|
1122 |
'use strict'; |
|
1123 |
|
|
1124 |
// adding alpha support for Automattic Color.js toString function. |
|
1125 |
if( typeof Color.fn.toString !== undefined ) { |
|
1126 |
|
|
1127 |
Color.fn.toString = function () { |
|
1128 |
|
|
1129 |
// check for alpha |
|
1130 |
if ( this._alpha < 1 ) { |
|
1131 |
return this.toCSS('rgba', this._alpha).replace(/\s+/g, ''); |
|
1132 |
} |
|
1133 |
|
|
1134 |
var hex = parseInt( this._color, 10 ).toString( 16 ); |
|
1135 |
|
|
1136 |
if ( this.error ) { return ''; } |
|
1137 |
|
|
1138 |
// maybe left pad it |
|
1139 |
if ( hex.length < 6 ) { |
|
1140 |
for (var i = 6 - hex.length - 1; i >= 0; i--) { |
|
1141 |
hex = '0' + hex; |
|
1142 |
} |
|
1143 |
} |
|
1144 |
|
|
1145 |
return '#' + hex; |
|
1146 |
|
|
1147 |
}; |
|
1148 |
|
|
1149 |
} |
|
1150 |
|
|
1151 |
$.ot_ParseColorValue = function( val ) { |
|
1152 |
|
|
1153 |
var value = val.replace(/\s+/g, ''), |
|
1154 |
alpha = ( value.indexOf('rgba') !== -1 ) ? parseFloat( value.replace(/^.*,(.+)\)/, '$1') * 100 ) : 100, |
|
1155 |
rgba = ( alpha < 100 ) ? true : false; |
|
1156 |
|
|
1157 |
return { value: value, alpha: alpha, rgba: rgba }; |
|
1158 |
|
|
1159 |
}; |
|
1160 |
|
|
1161 |
$.fn.ot_wpColorPicker = function() { |
|
1162 |
|
|
1163 |
return this.each(function() { |
|
1164 |
|
|
1165 |
var $this = $(this); |
|
1166 |
|
|
1167 |
// check for rgba enabled/disable |
|
1168 |
if( $this.data('rgba') !== false ) { |
|
1169 |
|
|
1170 |
// parse value |
|
1171 |
var picker = $.ot_ParseColorValue( $this.val() ); |
|
1172 |
|
|
1173 |
// wpColorPicker core |
|
1174 |
$this.wpColorPicker({ |
|
1175 |
|
|
1176 |
// wpColorPicker: change |
|
1177 |
change: function( event, ui ) { |
|
1178 |
|
|
1179 |
// update checkerboard background color |
|
1180 |
$this.closest('.wp-picker-container').find('.option-tree-opacity-slider-offset').css('background-color', ui.color.toString()); |
|
1181 |
$this.trigger('keyup'); |
|
1182 |
|
|
1183 |
}, |
|
1184 |
|
|
1185 |
// wpColorPicker: create |
|
1186 |
create: function( event, ui ) { |
|
1187 |
|
|
1188 |
// set variables for alpha slider |
|
1189 |
var a8cIris = $this.data('a8cIris'), |
|
1190 |
$container = $this.closest('.wp-picker-container'), |
|
1191 |
|
|
1192 |
// appending alpha wrapper |
|
1193 |
$alpha_wrap = $('<div class="option-tree-opacity-wrap">' + |
|
1194 |
'<div class="option-tree-opacity-slider"></div>' + |
|
1195 |
'<div class="option-tree-opacity-slider-offset"></div>' + |
|
1196 |
'<div class="option-tree-opacity-text"></div>' + |
|
1197 |
'</div>').appendTo( $container.find('.wp-picker-holder') ), |
|
1198 |
|
|
1199 |
$alpha_slider = $alpha_wrap.find('.option-tree-opacity-slider'), |
|
1200 |
$alpha_text = $alpha_wrap.find('.option-tree-opacity-text'), |
|
1201 |
$alpha_offset = $alpha_wrap.find('.option-tree-opacity-slider-offset'); |
|
1202 |
|
|
1203 |
// alpha slider |
|
1204 |
$alpha_slider.slider({ |
|
1205 |
|
|
1206 |
// slider: slide |
|
1207 |
slide: function( event, ui ) { |
|
1208 |
|
|
1209 |
var slide_value = parseFloat( ui.value / 100 ); |
|
1210 |
|
|
1211 |
// update iris data alpha && wpColorPicker color option && alpha text |
|
1212 |
a8cIris._color._alpha = slide_value; |
|
1213 |
$this.wpColorPicker( 'color', a8cIris._color.toString() ); |
|
1214 |
$alpha_text.text( ( slide_value < 1 ? slide_value : '' ) ); |
|
1215 |
|
|
1216 |
}, |
|
1217 |
|
|
1218 |
// slider: create |
|
1219 |
create: function() { |
|
1220 |
|
|
1221 |
var slide_value = parseFloat( picker.alpha / 100 ), |
|
1222 |
alpha_text_value = slide_value < 1 ? slide_value : ''; |
|
1223 |
|
|
1224 |
// update alpha text && checkerboard background color |
|
1225 |
$alpha_text.text(alpha_text_value); |
|
1226 |
$alpha_offset.css('background-color', picker.value); |
|
1227 |
|
|
1228 |
// wpColorPicker clear button for update iris data alpha && alpha text && slider color option |
|
1229 |
$container.on('click', '.wp-picker-clear', function() { |
|
1230 |
|
|
1231 |
a8cIris._color._alpha = 1; |
|
1232 |
$alpha_text.text(''); |
|
1233 |
$alpha_slider.slider('option', 'value', 100).trigger('slide'); |
|
1234 |
|
|
1235 |
}); |
|
1236 |
|
|
1237 |
// wpColorPicker default button for update iris data alpha && alpha text && slider color option |
|
1238 |
$container.on('click', '.wp-picker-default', function() { |
|
1239 |
|
|
1240 |
var default_picker = $.ot_ParseColorValue( $this.data('default-color') ), |
|
1241 |
default_value = parseFloat( default_picker.alpha / 100 ), |
|
1242 |
default_text = default_value < 1 ? default_value : ''; |
|
1243 |
|
|
1244 |
a8cIris._color._alpha = default_value; |
|
1245 |
$alpha_text.text(default_text); |
|
1246 |
$alpha_slider.slider('option', 'value', default_picker.alpha).trigger('slide'); |
|
1247 |
|
|
1248 |
}); |
|
1249 |
|
|
1250 |
// show alpha wrapper on click color picker button |
|
1251 |
$container.on('click', '.wp-color-result', function() { |
|
1252 |
$alpha_wrap.toggle(); |
|
1253 |
}); |
|
1254 |
|
|
1255 |
// hide alpha wrapper on click body |
|
1256 |
$('body').on( 'click.wpcolorpicker', function() { |
|
1257 |
$alpha_wrap.hide(); |
|
1258 |
}); |
|
1259 |
|
|
1260 |
}, |
|
1261 |
|
|
1262 |
// slider: options |
|
1263 |
value: picker.alpha, |
|
1264 |
step: 1, |
|
1265 |
min: 1, |
|
1266 |
max: 100 |
|
1267 |
|
|
1268 |
}); |
|
1269 |
} |
|
1270 |
|
|
1271 |
}); |
|
1272 |
|
|
1273 |
} else { |
|
1274 |
|
|
1275 |
// wpColorPicker default picker |
|
1276 |
$this.wpColorPicker({ |
|
1277 |
change: function() { |
|
1278 |
$this.trigger('keyup'); |
|
1279 |
} |
|
1280 |
}); |
|
1281 |
|
|
1282 |
} |
|
1283 |
|
|
1284 |
}); |
|
1285 |
|
|
1286 |
}; |
|
1287 |
|
|
1288 |
$(document).ready( function(){ |
|
1289 |
$('.hide-color-picker.ot-colorpicker-opacity').ot_wpColorPicker(); |
|
1290 |
}); |
|
1291 |
|
|
1292 |
})( jQuery, window, document ); |