78 }); |
83 }); |
79 } |
84 } |
80 }); |
85 }); |
81 }, |
86 }, |
82 init_add: function() { |
87 init_add: function() { |
83 $('.option-tree-section-add').live('click', function(e) { |
88 $(document).on('click', '.option-tree-section-add', function(e) { |
84 e.preventDefault(); |
89 e.preventDefault(); |
85 OT_UI.add(this,'section'); |
90 OT_UI.add(this,'section'); |
86 }); |
91 }); |
87 $('.option-tree-setting-add').live('click', function(e) { |
92 $(document).on('click', '.option-tree-setting-add', function(e) { |
88 e.preventDefault(); |
93 e.preventDefault(); |
89 OT_UI.add(this,'setting'); |
94 OT_UI.add(this,'setting'); |
90 }); |
95 }); |
91 $('.option-tree-help-add').live('click', function(e) { |
96 $(document).on('click', '.option-tree-help-add', function(e) { |
92 e.preventDefault(); |
97 e.preventDefault(); |
93 OT_UI.add(this,'the_contextual_help'); |
98 OT_UI.add(this,'the_contextual_help'); |
94 }); |
99 }); |
95 $('.option-tree-choice-add').live('click', function(e) { |
100 $(document).on('click', '.option-tree-choice-add', function(e) { |
96 e.preventDefault(); |
101 e.preventDefault(); |
97 OT_UI.add(this,'choice'); |
102 OT_UI.add(this,'choice'); |
98 }); |
103 }); |
99 $('.option-tree-list-item-add').live('click', function(e) { |
104 $(document).on('click', '.option-tree-list-item-add', function(e) { |
100 e.preventDefault(); |
105 e.preventDefault(); |
101 OT_UI.add(this,'list_item'); |
106 OT_UI.add(this,'list_item'); |
102 }); |
107 }); |
103 $('.option-tree-list-item-setting-add').live('click', function(e) { |
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) { |
104 e.preventDefault(); |
113 e.preventDefault(); |
105 if ( $(this).parents('ul').parents('ul').hasClass('ui-sortable') ) { |
114 if ( $(this).parents('ul').parents('ul').hasClass('ui-sortable') ) { |
106 alert(option_tree.setting_limit); |
115 alert(option_tree.setting_limit); |
107 return false; |
116 return false; |
108 } |
117 } |
109 OT_UI.add(this,'list_item_setting'); |
118 OT_UI.add(this,'list_item_setting'); |
110 }); |
119 }); |
111 }, |
120 }, |
112 init_edit: function() { |
121 init_edit: function() { |
113 $('.option-tree-setting-edit').live('click', function(e) { |
122 $(document).on('click', '.option-tree-setting-edit', function(e) { |
114 e.preventDefault(); |
123 e.preventDefault(); |
115 if ( $(this).parents().hasClass('option-tree-setting-body') ) { |
124 if ( $(this).parents().hasClass('option-tree-setting-body') ) { |
116 OT_UI.init_remove_active($(this),'child'); |
125 OT_UI.init_remove_active($(this),'child'); |
117 OT_UI.init_hide_body($(this),'child'); |
126 OT_UI.init_hide_body($(this),'child'); |
118 } else { |
127 } else { |
286 $(this).find('.hidden-section').attr({'value':section}); |
305 $(this).find('.hidden-section').attr({'value':section}); |
287 } |
306 } |
288 last_section = section; |
307 last_section = section; |
289 }); |
308 }); |
290 }, |
309 }, |
|
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 }, |
291 init_upload: function() { |
420 init_upload: function() { |
292 $(document).on('click', '.ot_upload_media', function() { |
421 $(document).on('click', '.ot_upload_media', function() { |
293 var field_id = $(this).parent('.option-tree-ui-upload-parent').find('input').attr('id'), |
422 var field_id = $(this).parent('.option-tree-ui-upload-parent').find('input').attr('id'), |
294 post_id = $(this).attr('rel'), |
423 post_id = $(this).attr('rel'), |
295 btnContent = ''; |
424 save_attachment_id = $('#'+field_id).hasClass('ot-upload-attachment-id'), |
|
425 btnContent = ''; |
296 if ( window.wp && wp.media ) { |
426 if ( window.wp && wp.media ) { |
297 window.ot_media_frame = window.ot_media_frame || new wp.media.view.MediaFrame.Select({ |
427 window.ot_media_frame = window.ot_media_frame || new wp.media.view.MediaFrame.Select({ |
298 title: $(this).attr('title'), |
428 title: $(this).attr('title'), |
299 button: { |
429 button: { |
300 text: option_tree.upload_text |
430 text: option_tree.upload_text |
301 }, |
431 }, |
302 multiple: false |
432 multiple: false |
303 }); |
433 }); |
304 window.ot_media_frame.on('select', function() { |
434 window.ot_media_frame.on('select', function() { |
305 var attachment = window.ot_media_frame.state().get('selection').first(), |
435 var attachment = window.ot_media_frame.state().get('selection').first(), |
306 href = attachment.attributes.url, |
436 href = attachment.attributes.url, |
|
437 attachment_id = attachment.attributes.id, |
307 mime = attachment.attributes.mime, |
438 mime = attachment.attributes.mime, |
308 regex = /^image\/(?:jpe?g|png|gif|x-icon)$/i; |
439 regex = /^image\/(?:jpe?g|png|gif|x-icon)$/i; |
309 if ( mime.match(regex) ) { |
440 if ( mime.match(regex) ) { |
310 btnContent += '<div class="option-tree-ui-image-wrap"><img src="'+href+'" alt="" /></div>'; |
441 btnContent += '<div class="option-tree-ui-image-wrap"><img src="'+href+'" alt="" /></div>'; |
311 } |
442 } |
312 btnContent += '<a href="javascript:(void);" class="option-tree-ui-remove-media option-tree-ui-button red light" title="'+option_tree.remove_media_text+'"><span class="icon trash-can">'+option_tree.remove_media_text+'</span></a>'; |
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>'; |
313 $('#'+field_id).val(href); |
444 $('#'+field_id).val( ( save_attachment_id ? attachment_id : href ) ); |
314 $('#'+field_id+'_media').remove(); |
445 $('#'+field_id+'_media').remove(); |
315 $('#'+field_id).parent().parent('div').append('<div class="option-tree-ui-media-wrap" id="'+field_id+'_media" />'); |
446 $('#'+field_id).parent().parent('div').append('<div class="option-tree-ui-media-wrap" id="'+field_id+'_media" />'); |
316 $('#'+field_id+'_media').append(btnContent).slideDown(); |
447 $('#'+field_id+'_media').append(btnContent).slideDown(); |
317 window.ot_media_frame.off('select'); |
448 window.ot_media_frame.off('select'); |
318 }).open(); |
449 }).open(); |
364 }); |
495 }); |
365 }, |
496 }, |
366 init_upload_fix: function(elm) { |
497 init_upload_fix: function(elm) { |
367 var id = $(elm).attr('id'), |
498 var id = $(elm).attr('id'), |
368 val = $(elm).val(), |
499 val = $(elm).val(), |
369 img = $(elm).parent().next('option-tree-ui-media-wrap').find('img'), |
500 img = $(elm).parent().next('.option-tree-ui-media-wrap').find('img'), |
370 src = img.attr('src'), |
501 src = img.attr('src'), |
371 btnContent = ''; |
502 btnContent = ''; |
|
503 if ( val == src ) { |
|
504 return; |
|
505 } |
372 if ( val != src ) { |
506 if ( val != src ) { |
373 img.attr('src', val); |
507 img.attr('src', val); |
374 } |
508 } |
375 if ( val !== '' && ( typeof src == 'undefined' || src == false ) && OT_UI.url_exists(val) ) { |
509 if ( val !== '' && ( typeof src == 'undefined' || src == false ) && OT_UI.url_exists(val) ) { |
376 var image = /\.(?:jpe?g|png|gif|ico)$/i; |
510 var image = /\.(?:jpe?g|png|gif|ico)$/i; |
377 if (val.match(image)) { |
511 if (val.match(image)) { |
378 btnContent += '<div class="option-tree-ui-image-wrap"><img src="'+val+'" alt="" /></div>'; |
512 btnContent += '<div class="option-tree-ui-image-wrap"><img src="'+val+'" alt="" /></div>'; |
379 } |
513 } |
380 btnContent += '<a href="javascript:(void);" class="option-tree-ui-remove-media option-tree-ui-button red light" title="'+option_tree.remove_media_text+'"><span class="icon trash-can">'+option_tree.remove_media_text+'</span></a>'; |
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>'; |
381 $('#'+id).val(val); |
515 $('#'+id).val(val); |
382 $('#'+id+'_media').remove(); |
516 $('#'+id+'_media').remove(); |
383 $('#'+id).parent().parent('div').append('<div class="option-tree-ui-media-wrap" id="'+id+'_media" />'); |
517 $('#'+id).parent().parent('div').append('<div class="option-tree-ui-media-wrap" id="'+id+'_media" />'); |
384 $('#'+id+'_media').append(btnContent).slideDown(); |
518 $('#'+id+'_media').append(btnContent).slideDown(); |
385 } else if ( val == '' || ! OT_UI.url_exists(val) ) { |
519 } else if ( val == '' || ! OT_UI.url_exists(val) ) { |
386 $(elm).parent().next('.option-tree-ui-media-wrap').remove(); |
520 $(elm).parent().next('.option-tree-ui-media-wrap').remove(); |
387 } |
521 } |
388 }, |
522 }, |
389 init_numeric_slider: function() { |
523 init_numeric_slider: function(scope) { |
390 $(".ot-numeric-slider-wrap").each(function() { |
524 scope = scope || document; |
|
525 $(".ot-numeric-slider-wrap", scope).each(function() { |
391 var hidden = $(".ot-numeric-slider-hidden-input", this), |
526 var hidden = $(".ot-numeric-slider-hidden-input", this), |
392 value = hidden.val(), |
527 value = hidden.val(), |
393 helper = $(".ot-numeric-slider-helper-input", this); |
528 helper = $(".ot-numeric-slider-helper-input", this); |
394 if ( ! value ) { |
529 if ( ! value ) { |
395 value = hidden.data("min"); |
530 value = hidden.data("min"); |
428 $(obj).val(url); |
569 $(obj).val(url); |
429 } |
570 } |
430 }); |
571 }); |
431 }, |
572 }, |
432 init_radio_image_select: function() { |
573 init_radio_image_select: function() { |
433 $('.option-tree-ui-radio-image').live('click', function() { |
574 $(document).on('click', '.option-tree-ui-radio-image', function() { |
434 $(this).closest('.type-radio-image').find('.option-tree-ui-radio-image').removeClass('option-tree-ui-radio-image-selected'); |
575 $(this).closest('.type-radio-image').find('.option-tree-ui-radio-image').removeClass('option-tree-ui-radio-image-selected'); |
435 $(this).toggleClass('option-tree-ui-radio-image-selected'); |
576 $(this).toggleClass('option-tree-ui-radio-image-selected'); |
436 $(this).parent().find('.option-tree-ui-radio').attr('checked', true); |
577 $(this).parent().find('.option-tree-ui-radio').prop('checked', true).trigger('change'); |
437 }); |
578 }); |
438 }, |
579 }, |
439 init_select_wrapper: function() { |
580 init_select_wrapper: function(scope) { |
440 $('.option-tree-ui-select').each(function () { |
581 scope = scope || document; |
|
582 $('.option-tree-ui-select', scope).each(function () { |
441 if ( ! $(this).parent().hasClass('select-wrapper') ) { |
583 if ( ! $(this).parent().hasClass('select-wrapper') ) { |
442 $(this).wrap('<div class="select-wrapper" />'); |
584 $(this).wrap('<div class="select-wrapper" />'); |
443 $(this).parent('.select-wrapper').prepend('<span>' + $(this).find('option:selected').text() + '</span>'); |
585 $(this).parent('.select-wrapper').prepend('<span>' + $(this).find('option:selected').text() + '</span>'); |
444 } |
586 } |
445 }); |
587 }); |
446 $('.option-tree-ui-select').live('change', function () { |
588 }, |
|
589 bind_select_wrapper: function() { |
|
590 $(document).on('change', '.option-tree-ui-select', function () { |
447 $(this).prev('span').replaceWith('<span>' + $(this).find('option:selected').text() + '</span>'); |
591 $(this).prev('span').replaceWith('<span>' + $(this).find('option:selected').text() + '</span>'); |
448 }); |
592 }); |
449 $('.option-tree-ui-select').bind($.browser.msie ? 'click' : 'change', function(event) { |
593 }, |
450 $(this).prev('span').replaceWith('<span>' + $(this).find('option:selected').text() + '</span>'); |
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(); |
451 }); |
656 }); |
452 }, |
657 }, |
453 bind_colorpicker: function(field_id) { |
658 bind_colorpicker: function(field_id) { |
454 $('#'+field_id).ColorPicker({ |
659 $('#'+field_id).wpColorPicker({ |
455 onSubmit: function(hsb, hex, rgb) { |
660 change: function() { |
456 $('#'+field_id).val('#'+hex); |
661 OT_UI.parse_condition(); |
457 }, |
662 }, |
458 onBeforeShow: function () { |
663 clear: function() { |
459 $(this).ColorPickerSetColor(this.value); |
664 OT_UI.parse_condition(); |
460 return false; |
665 } |
461 }, |
666 }); |
462 onChange: function (hsb, hex, rgb) { |
667 }, |
463 var bc = $.inArray(hex, [ 'FFFFFF', 'FFF', 'ffffff', 'fff' ]) != -1 ? 'ccc' : hex; |
668 bind_date_picker: function(field_id, date_format) { |
464 $('#cp_'+field_id).css({'backgroundColor':'#'+hex,'borderColor':'#'+bc}); |
669 $('#'+field_id).datepicker({ |
465 $('#cp_'+field_id).prev('input').attr('value', '#'+hex); |
670 showOtherMonths: true, |
466 } |
671 showButtonPanel: true, |
467 }) |
672 currentText: option_tree.date_current, |
468 .bind('keyup', function(){ |
673 closeText: option_tree.date_close, |
469 $(this).ColorPickerSetColor(this.value); |
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 |
470 }); |
682 }); |
471 }, |
683 }, |
472 fix_upload_parent: function() { |
684 fix_upload_parent: function() { |
473 $('.option-tree-ui-upload-input').live('focus blur', function(){ |
685 $('.option-tree-ui-upload-input').not('.ot-upload-attachment-id').on('focus blur', function(){ |
474 $(this).parent('.option-tree-ui-upload-parent').toggleClass('focus'); |
686 $(this).parent('.option-tree-ui-upload-parent').toggleClass('focus'); |
475 OT_UI.init_upload_fix(this); |
687 OT_UI.init_upload_fix(this); |
476 }); |
688 }); |
477 }, |
689 }, |
478 remove_image: function(e) { |
690 remove_image: function(e) { |
479 $(e).parent().parent().find('.option-tree-ui-upload-input').attr('value',''); |
691 $(e).parent().parent().find('.option-tree-ui-upload-input').attr('value',''); |
480 $(e).parent('.option-tree-ui-media-wrap').remove(); |
692 $(e).parent('.option-tree-ui-media-wrap').remove(); |
481 }, |
|
482 fix_colorpicker: function() { |
|
483 $('.cp_input').live('blur', function() { |
|
484 $('.cp_input').each( function(index, el) { |
|
485 var val = $(el).val(); |
|
486 var reg = /^[A-Fa-f0-9]{6}$/; |
|
487 if( reg.test(val) && val != '' ) { |
|
488 $(el).attr('value', '#'+val) |
|
489 } else if ( val == '' ) { |
|
490 $(this).next('.cp_box').css({'background':'#f1f1f1','border-color':'#ccc'}); |
|
491 } |
|
492 }); |
|
493 }); |
|
494 }, |
693 }, |
495 fix_textarea: function() { |
694 fix_textarea: function() { |
496 $('.wp-editor-area').focus( function(){ |
695 $('.wp-editor-area').focus( function(){ |
497 $(this).parent('div').css({borderColor:'#bbb'}); |
696 $(this).parent('div').css({borderColor:'#bbb'}); |
498 }).blur( function(){ |
697 }).blur( function(){ |
535 }; |
777 }; |
536 $(document).ready( function() { |
778 $(document).ready( function() { |
537 OT_UI.init(); |
779 OT_UI.init(); |
538 }); |
780 }); |
539 })(jQuery); |
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 ); |