| @@ -1,123 +1,121 @@ | ||
| 1 | -(function() { | |
| 2 | - 'use strict'; | |
| 1 | +'use strict'; | |
| 3 | 2 | |
| 4 | - var $ = window.jQuery; | |
| 5 | - var Option = require('./_option.js'); | |
| 6 | - var optionControls = document.getElementById('boxzilla-box-options-controls'); | |
| 7 | - var $optionControls = $(optionControls); | |
| 3 | +var $ = window.jQuery; | |
| 4 | +var Option = require('./_option.js'); | |
| 5 | +var optionControls = document.getElementById('boxzilla-box-options-controls'); | |
| 6 | +var $optionControls = $(optionControls); | |
| 8 | 7 | |
| 9 | - // sanity check, are we on the correct page? | |
| 10 | - if( $optionControls.length === 0 ) { | |
| 11 | - return; | |
| 12 | - } | |
| 8 | +// sanity check, are we on the correct page? | |
| 9 | +if( $optionControls.length === 0 ) { | |
| 10 | + return; | |
| 11 | +} | |
| 13 | 12 | |
| 14 | - var EventEmitter = require('wolfy87-eventemitter'); | |
| 15 | - var events = new EventEmitter(); | |
| 16 | - var Designer = require('./_designer.js')($, Option, events); | |
| 17 | - var rowTemplate = wp.template('rule-row-template'); | |
| 18 | - var i18n = boxzilla_i18n; | |
| 13 | +var EventEmitter = require('wolfy87-eventemitter'); | |
| 14 | +var events = new EventEmitter(); | |
| 15 | +var Designer = require('./_designer.js')($, Option, events); | |
| 16 | +var rowTemplate = wp.template('rule-row-template'); | |
| 17 | +var i18n = boxzilla_i18n; | |
| 19 | 18 | |
| 20 | - // events | |
| 21 | - $optionControls.on('click', ".boxzilla-add-rule", addRuleFields); | |
| 22 | - $optionControls.on('click', ".boxzilla-remove-rule", removeRule); | |
| 23 | - $optionControls.on('change', ".boxzilla-rule-condition", setContextualHelpers); | |
| 24 | - $optionControls.find('.boxzilla-auto-show-trigger').on('change', toggleTriggerOptions ); | |
| 19 | +// events | |
| 20 | +$optionControls.on('click', ".boxzilla-add-rule", addRuleFields); | |
| 21 | +$optionControls.on('click', ".boxzilla-remove-rule", removeRule); | |
| 22 | +$optionControls.on('change', ".boxzilla-rule-condition", setContextualHelpers); | |
| 23 | +$optionControls.find('.boxzilla-auto-show-trigger').on('change', toggleTriggerOptions ); | |
| 25 | 24 | |
| 26 | - $(window).load(function() { | |
| 27 | - if( typeof(window.tinyMCE) === "undefined" ) { | |
| 28 | - document.getElementById('notice-notinymce').style.display = ''; | |
| 29 | - } | |
| 30 | - }); | |
| 25 | +$(window).load(function() { | |
| 26 | + if( typeof(window.tinyMCE) === "undefined" ) { | |
| 27 | + document.getElementById('notice-notinymce').style.display = ''; | |
| 28 | + } | |
| 29 | +}); | |
| 31 | 30 | |
| 32 | - // call contextual helper method for each row | |
| 33 | - $('.boxzilla-rule-row').each(setContextualHelpers); | |
| 31 | +// call contextual helper method for each row | |
| 32 | +$('.boxzilla-rule-row').each(setContextualHelpers); | |
| 34 | 33 | |
| 35 | - function toggleTriggerOptions() { | |
| 36 | - $optionControls.find('.boxzilla-trigger-options').toggle( this.value !== '' ); | |
| 37 | - } | |
| 34 | +function toggleTriggerOptions() { | |
| 35 | + $optionControls.find('.boxzilla-trigger-options').toggle( this.value !== '' ); | |
| 36 | +} | |
| 38 | 37 | |
| 39 | - function removeRule() { | |
| 40 | - $(this).parents('tr').remove(); | |
| 41 | - } | |
| 38 | +function removeRule() { | |
| 39 | + $(this).parents('tr').remove(); | |
| 40 | +} | |
| 42 | 41 | |
| 43 | - function setContextualHelpers() { | |
| 42 | +function setContextualHelpers() { | |
| 44 | 43 | |
| 45 | - var context = ( this.tagName.toLowerCase() === "tr" ) ? this : $(this).parents('tr').get(0); | |
| 46 | - var condition = context.querySelector('.boxzilla-rule-condition').value; | |
| 47 | - var valueInput = context.querySelector('.boxzilla-rule-value'); | |
| 48 | - var qualifierInput = context.querySelector('.boxzilla-rule-qualifier'); | |
| 49 | - var betterInput = valueInput.cloneNode(true); | |
| 50 | - var $betterInput = $(betterInput); | |
| 44 | + var context = ( this.tagName.toLowerCase() === "tr" ) ? this : $(this).parents('tr').get(0); | |
| 45 | + var condition = context.querySelector('.boxzilla-rule-condition').value; | |
| 46 | + var valueInput = context.querySelector('.boxzilla-rule-value'); | |
| 47 | + var qualifierInput = context.querySelector('.boxzilla-rule-qualifier'); | |
| 48 | + var betterInput = valueInput.cloneNode(true); | |
| 49 | + var $betterInput = $(betterInput); | |
| 51 | 50 | |
| 52 | - // remove previously added helpers | |
| 53 | - $(context.querySelectorAll('.boxzilla-helper')).remove(); | |
| 51 | + // remove previously added helpers | |
| 52 | + $(context.querySelectorAll('.boxzilla-helper')).remove(); | |
| 54 | 53 | |
| 55 | - // prepare better input | |
| 56 | - betterInput.removeAttribute('name'); | |
| 57 | - betterInput.className = betterInput.className + ' boxzilla-helper'; | |
| 58 | - valueInput.parentNode.insertBefore(betterInput, valueInput.nextSibling); | |
| 59 | - $betterInput.change(function() { valueInput.value = this.value; }); | |
| 54 | + // prepare better input | |
| 55 | + betterInput.removeAttribute('name'); | |
| 56 | + betterInput.className = betterInput.className + ' boxzilla-helper'; | |
| 57 | + valueInput.parentNode.insertBefore(betterInput, valueInput.nextSibling); | |
| 58 | + $betterInput.change(function() { valueInput.value = this.value; }); | |
| 60 | 59 | |
| 61 | - betterInput.style.display = ''; | |
| 62 | - valueInput.style.display = 'none'; | |
| 63 | - qualifierInput.style.display = ''; | |
| 60 | + betterInput.style.display = ''; | |
| 61 | + valueInput.style.display = 'none'; | |
| 62 | + qualifierInput.style.display = ''; | |
| 64 | 63 | |
| 65 | - // change placeholder for textual help | |
| 66 | - switch(condition) { | |
| 67 | - default: | |
| 68 | - betterInput.placeholder = i18n.enterCommaSeparatedValues; | |
| 69 | - break; | |
| 64 | + // change placeholder for textual help | |
| 65 | + switch(condition) { | |
| 66 | + default: | |
| 67 | + betterInput.placeholder = i18n.enterCommaSeparatedValues; | |
| 68 | + break; | |
| 70 | 69 | |
| 71 | - case '': | |
| 72 | - case 'everywhere': | |
| 73 | - qualifierInput.value = '1'; | |
| 74 | - valueInput.value = ''; | |
| 75 | - betterInput.style.display = 'none'; | |
| 76 | - qualifierInput.style.display = 'none'; | |
| 77 | - break; | |
| 70 | + case '': | |
| 71 | + case 'everywhere': | |
| 72 | + qualifierInput.value = '1'; | |
| 73 | + valueInput.value = ''; | |
| 74 | + betterInput.style.display = 'none'; | |
| 75 | + qualifierInput.style.display = 'none'; | |
| 76 | + break; | |
| 78 | 77 | |
| 79 | - case 'is_single': | |
| 80 | - case 'is_post': | |
| 81 | - betterInput.placeholder = i18n.enterCommaSeparatedPosts; | |
| 82 | - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post", {multiple:true, multipleSep: ","}); | |
| 83 | - break; | |
| 78 | + case 'is_single': | |
| 79 | + case 'is_post': | |
| 80 | + betterInput.placeholder = i18n.enterCommaSeparatedPosts; | |
| 81 | + $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post", {multiple:true, multipleSep: ","}); | |
| 82 | + break; | |
| 84 | 83 | |
| 85 | - case 'is_page': | |
| 86 | - betterInput.placeholder = i18n.enterCommaSeparatedPages; | |
| 87 | - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=page", {multiple:true, multipleSep: ","}); | |
| 88 | - break; | |
| 84 | + case 'is_page': | |
| 85 | + betterInput.placeholder = i18n.enterCommaSeparatedPages; | |
| 86 | + $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=page", {multiple:true, multipleSep: ","}); | |
| 87 | + break; | |
| 89 | 88 | |
| 90 | - case 'is_post_type': | |
| 91 | - betterInput.placeholder = i18n.enterCommaSeparatedPostTypes; | |
| 92 | - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post_type", {multiple:true, multipleSep: ","}); | |
| 93 | - break; | |
| 89 | + case 'is_post_type': | |
| 90 | + betterInput.placeholder = i18n.enterCommaSeparatedPostTypes; | |
| 91 | + $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post_type", {multiple:true, multipleSep: ","}); | |
| 92 | + break; | |
| 94 | 93 | |
| 95 | - case 'is_url': | |
| 96 | - betterInput.placeholder = i18n.enterCommaSeparatedRelativeUrls; | |
| 97 | - break; | |
| 94 | + case 'is_url': | |
| 95 | + betterInput.placeholder = i18n.enterCommaSeparatedRelativeUrls; | |
| 96 | + break; | |
| 98 | 97 | |
| 99 | - case 'is_post_in_category': | |
| 100 | - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=category", {multiple:true, multipleSep: ","}); | |
| 101 | - break; | |
| 98 | + case 'is_post_in_category': | |
| 99 | + $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=category", {multiple:true, multipleSep: ","}); | |
| 100 | + break; | |
| 102 | 101 | |
| 103 | - case 'is_post_with_tag': | |
| 104 | - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post_tag", {multiple:true, multipleSep: ","}); | |
| 105 | - break; | |
| 106 | - } | |
| 102 | + case 'is_post_with_tag': | |
| 103 | + $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post_tag", {multiple:true, multipleSep: ","}); | |
| 104 | + break; | |
| 107 | 105 | } |
| 106 | +} | |
| 108 | 107 | |
| 109 | - function addRuleFields() { | |
| 110 | - var data = { | |
| 111 | - 'key': optionControls.querySelectorAll('.boxzilla-rule-row').length | |
| 112 | - }; | |
| 113 | - var html = rowTemplate(data); | |
| 114 | - $(document.getElementById('boxzilla-box-rules')).after(html); | |
| 115 | - return false; | |
| 116 | - } | |
| 108 | +function addRuleFields() { | |
| 109 | + var data = { | |
| 110 | + 'key': optionControls.querySelectorAll('.boxzilla-rule-row').length | |
| 111 | + }; | |
| 112 | + var html = rowTemplate(data); | |
| 113 | + $(document.getElementById('boxzilla-box-rules')).after(html); | |
| 114 | + return false; | |
| 115 | +} | |
| 117 | 116 | |
| 118 | - module.exports = { | |
| 119 | - 'Designer': Designer, | |
| 120 | - 'Option': Option, | |
| 121 | - 'events': events | |
| 122 | - }; | |
| 123 | -})(); | |
| 117 | +module.exports = { | |
| 118 | + 'Designer': Designer, | |
| 119 | + 'Option': Option, | |
| 120 | + 'events': events | |
| 121 | +}; | |