| @@ -1,5 +1,5 @@ | ||
| 1 | -(function () { var require = undefined; var module = undefined; var exports = undefined; var define = undefined; (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | |
| 1 | +(function () { var require = undefined; var module = undefined; var exports = undefined; var define = undefined; (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){ | |
| 2 | 2 | 'use strict'; |
| 3 | 3 | |
| 4 | 4 | window.Boxzilla_Admin = require('./admin/_admin.js'); |
| 5 | 5 | |
| @@ -6,131 +6,161 @@ | ||
| 6 | 6 | },{"./admin/_admin.js":2}],2:[function(require,module,exports){ |
| 7 | 7 | 'use strict'; |
| 8 | 8 | |
| 9 | 9 | (function () { |
| 10 | - 'use strict'; | |
| 10 | + 'use strict'; | |
| 11 | 11 | |
| 12 | - var $ = window.jQuery; | |
| 13 | - var Option = require('./_option.js'); | |
| 14 | - var optionControls = document.getElementById('boxzilla-box-options-controls'); | |
| 15 | - var $optionControls = $(optionControls); | |
| 12 | + var $ = window.jQuery; | |
| 13 | + var Option = require('./_option.js'); | |
| 14 | + var optionControls = document.getElementById('boxzilla-box-options-controls'); | |
| 15 | + var $optionControls = $(optionControls); | |
| 16 | + var tnLoggedIn = document.createTextNode(' logged in'); | |
| 16 | 17 | |
| 17 | - // sanity check, are we on the correct page? | |
| 18 | - if ($optionControls.length === 0) { | |
| 19 | - return; | |
| 20 | - } | |
| 18 | + // sanity check, are we on the correct page? | |
| 19 | + if ($optionControls.length === 0) { | |
| 20 | + return; | |
| 21 | + } | |
| 21 | 22 | |
| 22 | - var EventEmitter = require('wolfy87-eventemitter'); | |
| 23 | - var events = new EventEmitter(); | |
| 24 | - var Designer = require('./_designer.js')($, Option, events); | |
| 25 | - var rowTemplate = wp.template('rule-row-template'); | |
| 26 | - var i18n = boxzilla_i18n; | |
| 23 | + var EventEmitter = require('wolfy87-eventemitter'); | |
| 24 | + var events = new EventEmitter(); | |
| 25 | + var Designer = require('./_designer.js')($, Option, events); | |
| 26 | + var rowTemplate = wp.template('rule-row-template'); | |
| 27 | + var i18n = boxzilla_i18n; | |
| 27 | 28 | |
| 28 | - // events | |
| 29 | - $optionControls.on('click', ".boxzilla-add-rule", addRuleFields); | |
| 30 | - $optionControls.on('click', ".boxzilla-remove-rule", removeRule); | |
| 31 | - $optionControls.on('change', ".boxzilla-rule-condition", setContextualHelpers); | |
| 32 | - $optionControls.find('.boxzilla-auto-show-trigger').on('change', toggleTriggerOptions); | |
| 29 | + // events | |
| 30 | + $optionControls.on('click', ".boxzilla-add-rule", addRuleFields); | |
| 31 | + $optionControls.on('click', ".boxzilla-remove-rule", removeRule); | |
| 32 | + $optionControls.on('change', ".boxzilla-rule-condition", setContextualHelpers); | |
| 33 | + $optionControls.find('.boxzilla-auto-show-trigger').on('change', toggleTriggerOptions); | |
| 33 | 34 | |
| 34 | - $(window).load(function () { | |
| 35 | - if (typeof window.tinyMCE === "undefined") { | |
| 36 | - document.getElementById('notice-notinymce').style.display = ''; | |
| 37 | - } | |
| 38 | - }); | |
| 35 | + $(window).load(function () { | |
| 36 | + if (typeof window.tinyMCE === "undefined") { | |
| 37 | + document.getElementById('notice-notinymce').style.display = ''; | |
| 38 | + } | |
| 39 | + }); | |
| 39 | 40 | |
| 40 | - // call contextual helper method for each row | |
| 41 | - $('.boxzilla-rule-row').each(setContextualHelpers); | |
| 41 | + // call contextual helper method for each row | |
| 42 | + $('.boxzilla-rule-row').each(setContextualHelpers); | |
| 42 | 43 | |
| 43 | - function toggleTriggerOptions() { | |
| 44 | - $optionControls.find('.boxzilla-trigger-options').toggle(this.value !== ''); | |
| 45 | - } | |
| 44 | + function toggleTriggerOptions() { | |
| 45 | + $optionControls.find('.boxzilla-trigger-options').toggle(this.value !== ''); | |
| 46 | + } | |
| 46 | 47 | |
| 47 | - function removeRule() { | |
| 48 | - $(this).parents('tr').remove(); | |
| 49 | - } | |
| 48 | + function removeRule() { | |
| 49 | + $(this).parents('tr').remove(); | |
| 50 | + } | |
| 50 | 51 | |
| 51 | - function setContextualHelpers() { | |
| 52 | + function setContextualHelpers() { | |
| 53 | + var context = this.tagName.toLowerCase() === "tr" ? this : $(this).parents('tr').get(0); | |
| 54 | + var condition = context.querySelector('.boxzilla-rule-condition').value; | |
| 55 | + var valueInput = context.querySelector('.boxzilla-rule-value'); | |
| 56 | + var qualifierInput = context.querySelector('.boxzilla-rule-qualifier'); | |
| 57 | + var betterInput = valueInput.cloneNode(true); | |
| 58 | + var $betterInput = $(betterInput); | |
| 52 | 59 | |
| 53 | - var context = this.tagName.toLowerCase() === "tr" ? this : $(this).parents('tr').get(0); | |
| 54 | - var condition = context.querySelector('.boxzilla-rule-condition').value; | |
| 55 | - var valueInput = context.querySelector('.boxzilla-rule-value'); | |
| 56 | - var qualifierInput = context.querySelector('.boxzilla-rule-qualifier'); | |
| 57 | - var betterInput = valueInput.cloneNode(true); | |
| 58 | - var $betterInput = $(betterInput); | |
| 60 | + // remove previously added helpers | |
| 61 | + $(context.querySelectorAll('.boxzilla-helper')).remove(); | |
| 59 | 62 | |
| 60 | - // remove previously added helpers | |
| 61 | - $(context.querySelectorAll('.boxzilla-helper')).remove(); | |
| 63 | + // prepare better input | |
| 64 | + betterInput.removeAttribute('name'); | |
| 65 | + betterInput.className = betterInput.className + ' boxzilla-helper'; | |
| 66 | + valueInput.parentNode.insertBefore(betterInput, valueInput.nextSibling); | |
| 67 | + $betterInput.change(function () { | |
| 68 | + valueInput.value = this.value; | |
| 69 | + }); | |
| 62 | 70 | |
| 63 | - // prepare better input | |
| 64 | - betterInput.removeAttribute('name'); | |
| 65 | - betterInput.className = betterInput.className + ' boxzilla-helper'; | |
| 66 | - valueInput.parentNode.insertBefore(betterInput, valueInput.nextSibling); | |
| 67 | - $betterInput.change(function () { | |
| 68 | - valueInput.value = this.value; | |
| 69 | - }); | |
| 71 | + betterInput.style.display = ''; | |
| 72 | + valueInput.style.display = 'none'; | |
| 73 | + qualifierInput.style.display = ''; | |
| 74 | + qualifierInput.querySelector('option[value="contains"]').style.display = 'none'; | |
| 75 | + if (tnLoggedIn.parentNode) { | |
| 76 | + tnLoggedIn.parentNode.removeChild(tnLoggedIn); | |
| 77 | + } | |
| 70 | 78 | |
| 71 | - betterInput.style.display = ''; | |
| 72 | - valueInput.style.display = 'none'; | |
| 73 | - qualifierInput.style.display = ''; | |
| 79 | + // change placeholder for textual help | |
| 80 | + switch (condition) { | |
| 81 | + default: | |
| 82 | + betterInput.placeholder = i18n.enterCommaSeparatedValues; | |
| 83 | + break; | |
| 74 | 84 | |
| 75 | - // change placeholder for textual help | |
| 76 | - switch (condition) { | |
| 77 | - default: | |
| 78 | - betterInput.placeholder = i18n.enterCommaSeparatedValues; | |
| 79 | - break; | |
| 85 | + case '': | |
| 86 | + case 'everywhere': | |
| 87 | + qualifierInput.value = '1'; | |
| 88 | + valueInput.value = ''; | |
| 89 | + betterInput.style.display = 'none'; | |
| 90 | + qualifierInput.style.display = 'none'; | |
| 91 | + break; | |
| 80 | 92 | |
| 81 | - case '': | |
| 82 | - case 'everywhere': | |
| 83 | - qualifierInput.value = '1'; | |
| 84 | - valueInput.value = ''; | |
| 85 | - betterInput.style.display = 'none'; | |
| 86 | - qualifierInput.style.display = 'none'; | |
| 87 | - break; | |
| 93 | + case 'is_single': | |
| 94 | + case 'is_post': | |
| 95 | + betterInput.placeholder = i18n.enterCommaSeparatedPosts; | |
| 96 | + $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post", { | |
| 97 | + multiple: true, | |
| 98 | + multipleSep: "," | |
| 99 | + }); | |
| 100 | + break; | |
| 88 | 101 | |
| 89 | - case 'is_single': | |
| 90 | - case 'is_post': | |
| 91 | - betterInput.placeholder = i18n.enterCommaSeparatedPosts; | |
| 92 | - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post", { multiple: true, multipleSep: "," }); | |
| 93 | - break; | |
| 102 | + case 'is_page': | |
| 103 | + betterInput.placeholder = i18n.enterCommaSeparatedPages; | |
| 104 | + $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=page", { | |
| 105 | + multiple: true, | |
| 106 | + multipleSep: "," | |
| 107 | + }); | |
| 108 | + break; | |
| 94 | 109 | |
| 95 | - case 'is_page': | |
| 96 | - betterInput.placeholder = i18n.enterCommaSeparatedPages; | |
| 97 | - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=page", { multiple: true, multipleSep: "," }); | |
| 98 | - break; | |
| 110 | + case 'is_post_type': | |
| 111 | + betterInput.placeholder = i18n.enterCommaSeparatedPostTypes; | |
| 112 | + $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post_type", { | |
| 113 | + multiple: true, | |
| 114 | + multipleSep: "," | |
| 115 | + }); | |
| 116 | + break; | |
| 99 | 117 | |
| 100 | - case 'is_post_type': | |
| 101 | - betterInput.placeholder = i18n.enterCommaSeparatedPostTypes; | |
| 102 | - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post_type", { multiple: true, multipleSep: "," }); | |
| 103 | - break; | |
| 118 | + case 'is_url': | |
| 119 | + qualifierInput.querySelector('option[value="contains"]').style.display = ''; | |
| 120 | + betterInput.placeholder = i18n.enterCommaSeparatedRelativeUrls; | |
| 121 | + break; | |
| 104 | 122 | |
| 105 | - case 'is_url': | |
| 106 | - betterInput.placeholder = i18n.enterCommaSeparatedRelativeUrls; | |
| 107 | - break; | |
| 123 | + case 'is_post_in_category': | |
| 124 | + $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=category", { | |
| 125 | + multiple: true, | |
| 126 | + multipleSep: "," | |
| 127 | + }); | |
| 128 | + break; | |
| 108 | 129 | |
| 109 | - case 'is_post_in_category': | |
| 110 | - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=category", { multiple: true, multipleSep: "," }); | |
| 111 | - break; | |
| 130 | + case 'is_post_with_tag': | |
| 131 | + $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post_tag", { | |
| 132 | + multiple: true, | |
| 133 | + multipleSep: "," | |
| 134 | + }); | |
| 135 | + break; | |
| 112 | 136 | |
| 113 | - case 'is_post_with_tag': | |
| 114 | - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post_tag", { multiple: true, multipleSep: "," }); | |
| 115 | - break; | |
| 116 | - } | |
| 117 | - } | |
| 137 | + case 'is_user_logged_in': | |
| 138 | + betterInput.style.display = 'none'; | |
| 139 | + valueInput.parentNode.insertBefore(tnLoggedIn, valueInput.nextSibling); | |
| 140 | + break; | |
| 118 | 141 | |
| 119 | - function addRuleFields() { | |
| 120 | - var data = { | |
| 121 | - 'key': optionControls.querySelectorAll('.boxzilla-rule-row').length | |
| 122 | - }; | |
| 123 | - var html = rowTemplate(data); | |
| 124 | - $(document.getElementById('boxzilla-box-rules')).after(html); | |
| 125 | - return false; | |
| 126 | - } | |
| 142 | + case 'is_referer': | |
| 143 | + qualifierInput.querySelector('option[value="contains"]').style.display = ''; | |
| 144 | + break; | |
| 127 | 145 | |
| 128 | - module.exports = { | |
| 129 | - 'Designer': Designer, | |
| 130 | - 'Option': Option, | |
| 131 | - 'events': events | |
| 132 | - }; | |
| 146 | + } | |
| 147 | + } | |
| 148 | + | |
| 149 | + function addRuleFields() { | |
| 150 | + var data = { | |
| 151 | + 'key': optionControls.querySelectorAll('.boxzilla-rule-row').length | |
| 152 | + }; | |
| 153 | + var html = rowTemplate(data); | |
| 154 | + $(document.getElementById('boxzilla-box-rules')).after(html); | |
| 155 | + return false; | |
| 156 | + } | |
| 157 | + | |
| 158 | + module.exports = { | |
| 159 | + 'Designer': Designer, | |
| 160 | + 'Option': Option, | |
| 161 | + 'events': events | |
| 162 | + }; | |
| 133 | 163 | })(); |
| 134 | 164 | |
| 135 | 165 | },{"./_designer.js":3,"./_option.js":4,"wolfy87-eventemitter":5}],3:[function(require,module,exports){ |
| 136 | 166 | 'use strict'; |
| @@ -306,15 +336,15 @@ | ||
| 306 | 336 | module.exports = Option; |
| 307 | 337 | |
| 308 | 338 | },{}],5:[function(require,module,exports){ |
| 309 | 339 | /*! |
| 310 | - * EventEmitter v4.2.11 - git.io/ee | |
| 340 | + * EventEmitter v5.2.4 - git.io/ee | |
| 311 | 341 | * Unlicense - http://unlicense.org/ |
| 312 | 342 | * Oliver Caldwell - http://oli.me.uk/ |
| 313 | 343 | * @preserve |
| 314 | 344 | */ |
| 315 | 345 | |
| 316 | -;(function () { | |
| 346 | +;(function (exports) { | |
| 317 | 347 | 'use strict'; |
| 318 | 348 | |
| 319 | 349 | /** |
| 320 | 350 | * Class for managing events. |
| @@ -325,9 +355,8 @@ | ||
| 325 | 355 | function EventEmitter() {} |
| 326 | 356 | |
| 327 | 357 | // Shortcuts to improve speed and size |
| 328 | 358 | var proto = EventEmitter.prototype; |
| 329 | - var exports = this; | |
| 330 | 359 | var originalGlobalValue = exports.EventEmitter; |
| 331 | 360 | |
| 332 | 361 | /** |
| 333 | 362 | * Finds the index of the listener for the event in its storage array. |
| @@ -426,8 +455,18 @@ | ||
| 426 | 455 | |
| 427 | 456 | return response || listeners; |
| 428 | 457 | }; |
| 429 | 458 | |
| 459 | + function isValidListener (listener) { | |
| 460 | + if (typeof listener === 'function' || listener instanceof RegExp) { | |
| 461 | + return true | |
| 462 | + } else if (listener && typeof listener === 'object') { | |
| 463 | + return isValidListener(listener.listener) | |
| 464 | + } else { | |
| 465 | + return false | |
| 466 | + } | |
| 467 | + } | |
| 468 | + | |
| 430 | 469 | /** |
| 431 | 470 | * Adds a listener function to the specified event. |
| 432 | 471 | * The listener will not be added if it is a duplicate. |
| 433 | 472 | * If the listener returns true then it will be removed after it is called. |
| @@ -437,8 +476,12 @@ | ||
| 437 | 476 | * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling. |
| 438 | 477 | * @return {Object} Current instance of EventEmitter for chaining. |
| 439 | 478 | */ |
| 440 | 479 | proto.addListener = function addListener(evt, listener) { |
| 480 | + if (!isValidListener(listener)) { | |
| 481 | + throw new TypeError('listener must be a function'); | |
| 482 | + } | |
| 483 | + | |
| 441 | 484 | var listeners = this.getListenersAsObject(evt); |
| 442 | 485 | var listenerIsWrapped = typeof listener === 'object'; |
| 443 | 486 | var key; |
| 444 | 487 | |
| @@ -536,9 +579,9 @@ | ||
| 536 | 579 | proto.off = alias('removeListener'); |
| 537 | 580 | |
| 538 | 581 | /** |
| 539 | 582 | * Adds listeners in bulk using the manipulateListeners method. |
| 540 | - * If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added. | |
| 583 | + * If you pass an object as the first argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added. | |
| 541 | 584 | * You can also pass it a regular expression to add the array of listeners to all events that match it. |
| 542 | 585 | * Yeah, this function does quite a bit. That's probably a bad thing. |
| 543 | 586 | * |
| 544 | 587 | * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once. |
| @@ -551,9 +594,9 @@ | ||
| 551 | 594 | }; |
| 552 | 595 | |
| 553 | 596 | /** |
| 554 | 597 | * Removes listeners in bulk using the manipulateListeners method. |
| 555 | - * If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. | |
| 598 | + * If you pass an object as the first argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. | |
| 556 | 599 | * You can also pass it an event name and an array of listeners to be removed. |
| 557 | 600 | * You can also pass it a regular expression to remove the listeners from all events that match it. |
| 558 | 601 | * |
| 559 | 602 | * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once. |
| @@ -675,11 +718,10 @@ | ||
| 675 | 718 | |
| 676 | 719 | for (key in listenersMap) { |
| 677 | 720 | if (listenersMap.hasOwnProperty(key)) { |
| 678 | 721 | listeners = listenersMap[key].slice(0); |
| 679 | - i = listeners.length; | |
| 680 | 722 | |
| 681 | - while (i--) { | |
| 723 | + for (i = 0; i < listeners.length; i++) { | |
| 682 | 724 | // If the listener returns true then it shall be removed from the event |
| 683 | 725 | // The function is executed either with a basic call or an apply if there is an args array |
| 684 | 726 | listener = listeners[i]; |
| 685 | 727 | |
| @@ -778,8 +820,8 @@ | ||
| 778 | 820 | } |
| 779 | 821 | else { |
| 780 | 822 | exports.EventEmitter = EventEmitter; |
| 781 | 823 | } |
| 782 | -}.call(this)); | |
| 824 | +}(this || {})); | |
| 783 | 825 | |
| 784 | 826 | },{}]},{},[1]); |
| 785 | 827 | ; })(); |