PluginProbe
Boxzilla – WordPress Popup Builder / 3.2.21
Boxzilla – WordPress Popup Builder v3.2.21
3.4.11 3.4.10 3.4.9 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 trunk 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 All 72 releases
← All changes | assets/js/admin-script.js +281 -254 3.1.173.2.21 View file →
@@ -1,331 +1,346 @@
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){
2 -'use strict';
1 +(function () { var require = undefined; var module = undefined; var exports = undefined; var define = undefined; (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2 +"use strict";
3 3
4 4 window.Boxzilla_Admin = require('./admin/_admin.js');
5 5
6 6 },{"./admin/_admin.js":2}],2:[function(require,module,exports){
7 -'use strict';
7 +"use strict";
8 8
9 -(function () {
10 - 'use strict';
9 +var $ = window.jQuery;
11 10
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');
11 +var Option = require('./_option.js');
17 12
18 - // sanity check, are we on the correct page?
19 - if ($optionControls.length === 0) {
20 - return;
21 - }
13 +var optionControls = document.getElementById('boxzilla-box-options-controls');
14 +var $optionControls = $(optionControls);
15 +var tnLoggedIn = document.createTextNode(' logged in');
22 16
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;
17 +var EventEmitter = require('wolfy87-eventemitter');
28 18
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);
19 +var events = new EventEmitter();
34 20
35 - $(window).load(function () {
36 - if (typeof window.tinyMCE === "undefined") {
37 - document.getElementById('notice-notinymce').style.display = '';
38 - }
39 - });
21 +var Designer = require('./_designer.js')($, Option, events);
40 22
41 - // call contextual helper method for each row
42 - $('.boxzilla-rule-row').each(setContextualHelpers);
23 +var rowTemplate = window.wp.template('rule-row-template');
24 +var i18n = window.boxzilla_i18n;
25 +var ruleComparisonEl = document.getElementById('boxzilla-rule-comparison');
26 +var rulesContainerEl = document.getElementById('boxzilla-box-rules');
27 +var ajaxurl = window.ajaxurl; // events
43 28
44 - function toggleTriggerOptions() {
45 - $optionControls.find('.boxzilla-trigger-options').toggle(this.value !== '');
46 - }
29 +$(window).load(function () {
30 + if (typeof window.tinyMCE === 'undefined') {
31 + document.getElementById('notice-notinymce').style.display = '';
32 + }
47 33
48 - function removeRule() {
49 - $(this).parents('tr').remove();
50 - }
34 + $optionControls.on('click', '.boxzilla-add-rule', addRuleFields);
35 + $optionControls.on('click', '.boxzilla-remove-rule', removeRule);
36 + $optionControls.on('change', '.boxzilla-rule-condition', setContextualHelpers);
37 + $optionControls.find('.boxzilla-auto-show-trigger').on('change', toggleTriggerOptions);
38 + $(ruleComparisonEl).change(toggleAndOrTexts);
39 + $('.boxzilla-rule-row').each(setContextualHelpers);
40 +});
51 41
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);
42 +function toggleAndOrTexts() {
43 + var newText = ruleComparisonEl.value === 'any' ? i18n.or : i18n.and;
44 + $('.boxzilla-andor').text(newText);
45 +}
59 46
60 - // remove previously added helpers
61 - $(context.querySelectorAll('.boxzilla-helper')).remove();
47 +function toggleTriggerOptions() {
48 + $optionControls.find('.boxzilla-trigger-options').toggle(this.value !== '');
49 +}
62 50
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 - });
51 +function removeRule() {
52 + var row = $(this).parents('tr'); // delete andor row
70 53
71 - betterInput.style.display = '';
72 - valueInput.style.display = 'none';
73 - qualifierInput.style.display = '';
74 - if (tnLoggedIn.parentNode) {
75 - tnLoggedIn.parentNode.removeChild(tnLoggedIn);
76 - }
54 + row.prev().remove(); // delete rule row
77 55
78 - // change placeholder for textual help
79 - switch (condition) {
80 - default:
81 - betterInput.placeholder = i18n.enterCommaSeparatedValues;
82 - break;
56 + row.remove();
57 +}
83 58
84 - case '':
85 - case 'everywhere':
86 - qualifierInput.value = '1';
87 - valueInput.value = '';
88 - betterInput.style.display = 'none';
89 - qualifierInput.style.display = 'none';
90 - break;
59 +function setContextualHelpers() {
60 + var context = this.tagName.toLowerCase() === 'tr' ? this : $(this).parents('tr').get(0);
61 + var condition = context.querySelector('.boxzilla-rule-condition').value;
62 + var valueInput = context.querySelector('.boxzilla-rule-value');
63 + var qualifierInput = context.querySelector('.boxzilla-rule-qualifier');
64 + var betterInput = valueInput.cloneNode(true);
65 + var $betterInput = $(betterInput); // remove previously added helpers
91 66
92 - case 'is_single':
93 - case 'is_post':
94 - betterInput.placeholder = i18n.enterCommaSeparatedPosts;
95 - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post", {
96 - multiple: true,
97 - multipleSep: ","
98 - });
99 - break;
67 + $(context.querySelectorAll('.boxzilla-helper')).remove(); // prepare better input
100 68
101 - case 'is_page':
102 - betterInput.placeholder = i18n.enterCommaSeparatedPages;
103 - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=page", {
104 - multiple: true,
105 - multipleSep: ","
106 - });
107 - break;
69 + betterInput.removeAttribute('name');
70 + betterInput.className = betterInput.className + ' boxzilla-helper';
71 + valueInput.parentNode.insertBefore(betterInput, valueInput.nextSibling);
72 + $betterInput.change(function () {
73 + valueInput.value = this.value;
74 + });
75 + betterInput.style.display = '';
76 + valueInput.style.display = 'none';
77 + qualifierInput.style.display = '';
78 + qualifierInput.querySelector('option[value="not_contains"]').style.display = 'none';
79 + qualifierInput.querySelector('option[value="contains"]').style.display = 'none';
108 80
109 - case 'is_post_type':
110 - betterInput.placeholder = i18n.enterCommaSeparatedPostTypes;
111 - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post_type", {
112 - multiple: true,
113 - multipleSep: ","
114 - });
115 - break;
81 + if (tnLoggedIn.parentNode) {
82 + tnLoggedIn.parentNode.removeChild(tnLoggedIn);
83 + } // change placeholder for textual help
116 84
117 - case 'is_url':
118 - betterInput.placeholder = i18n.enterCommaSeparatedRelativeUrls;
119 - break;
120 85
121 - case 'is_post_in_category':
122 - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=category", {
123 - multiple: true,
124 - multipleSep: ","
125 - });
126 - break;
86 + switch (condition) {
87 + default:
88 + betterInput.placeholder = i18n.enterCommaSeparatedValues;
89 + break;
127 90
128 - case 'is_post_with_tag':
129 - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post_tag", {
130 - multiple: true,
131 - multipleSep: ","
132 - });
133 - break;
91 + case '':
92 + case 'everywhere':
93 + qualifierInput.value = '1';
94 + valueInput.value = '';
95 + betterInput.style.display = 'none';
96 + qualifierInput.style.display = 'none';
97 + break;
134 98
135 - case 'is_user_logged_in':
136 - betterInput.style.display = 'none';
137 - valueInput.parentNode.insertBefore(tnLoggedIn, valueInput.nextSibling);
138 - break;
99 + case 'is_single':
100 + case 'is_post':
101 + betterInput.placeholder = i18n.enterCommaSeparatedPosts;
102 + $betterInput.suggest(ajaxurl + '?action=boxzilla_autocomplete&type=post', {
103 + multiple: true,
104 + multipleSep: ','
105 + });
106 + break;
139 107
140 - }
141 - }
108 + case 'is_page':
109 + betterInput.placeholder = i18n.enterCommaSeparatedPages;
110 + $betterInput.suggest(ajaxurl + '?action=boxzilla_autocomplete&type=page', {
111 + multiple: true,
112 + multipleSep: ','
113 + });
114 + break;
142 115
143 - function addRuleFields() {
144 - var data = {
145 - 'key': optionControls.querySelectorAll('.boxzilla-rule-row').length
146 - };
147 - var html = rowTemplate(data);
148 - $(document.getElementById('boxzilla-box-rules')).after(html);
149 - return false;
150 - }
116 + case 'is_post_type':
117 + betterInput.placeholder = i18n.enterCommaSeparatedPostTypes;
118 + $betterInput.suggest(ajaxurl + '?action=boxzilla_autocomplete&type=post_type', {
119 + multiple: true,
120 + multipleSep: ','
121 + });
122 + break;
151 123
152 - module.exports = {
153 - 'Designer': Designer,
154 - 'Option': Option,
155 - 'events': events
156 - };
157 -})();
124 + case 'is_url':
125 + qualifierInput.querySelector('option[value="contains"]').style.display = '';
126 + qualifierInput.querySelector('option[value="not_contains"]').style.display = '';
127 + betterInput.placeholder = i18n.enterCommaSeparatedRelativeUrls;
128 + break;
158 129
130 + case 'is_post_in_category':
131 + $betterInput.suggest(ajaxurl + '?action=boxzilla_autocomplete&type=category', {
132 + multiple: true,
133 + multipleSep: ','
134 + });
135 + break;
136 +
137 + case 'is_post_with_tag':
138 + $betterInput.suggest(ajaxurl + '?action=boxzilla_autocomplete&type=post_tag', {
139 + multiple: true,
140 + multipleSep: ','
141 + });
142 + break;
143 +
144 + case 'is_user_logged_in':
145 + betterInput.style.display = 'none';
146 + valueInput.parentNode.insertBefore(tnLoggedIn, valueInput.nextSibling);
147 + break;
148 +
149 + case 'is_referer':
150 + qualifierInput.querySelector('option[value="contains"]').style.display = '';
151 + qualifierInput.querySelector('option[value="not_contains"]').style.display = '';
152 + break;
153 + }
154 +}
155 +
156 +function addRuleFields() {
157 + var data = {
158 + key: optionControls.querySelectorAll('.boxzilla-rule-row').length,
159 + andor: ruleComparisonEl.value === 'any' ? i18n.or : i18n.and
160 + };
161 + var html = rowTemplate(data);
162 + $(rulesContainerEl).append(html);
163 + return false;
164 +}
165 +
166 +module.exports = {
167 + Designer: Designer,
168 + Option: Option,
169 + events: events
170 +};
171 +
159 172 },{"./_designer.js":3,"./_option.js":4,"wolfy87-eventemitter":5}],3:[function(require,module,exports){
160 -'use strict';
173 +"use strict";
161 174
162 -var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
175 +function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
163 176
164 177 var Designer = function Designer($, Option, events) {
178 + // vars
179 + var boxId = document.getElementById('post_ID').value || 0;
180 + var $editor;
181 + var $editorFrame;
182 + var $innerEditor;
183 + var options = {};
184 + var visualEditorInitialised = false;
185 + var $appearanceControls = $('#boxzilla-box-appearance-controls'); // functions
165 186
166 - // vars
167 - var boxId = document.getElementById('post_ID').value || 0,
168 - $editor,
169 - $editorFrame,
170 - $innerEditor,
171 - options = {},
172 - visualEditorInitialised = false;
187 + function init() {
188 + // Only run if TinyMCE has actually inited
189 + if (_typeof(window.tinyMCE) !== 'object' || window.tinyMCE.get('content') === null) {
190 + return;
191 + } // create Option objects
173 192
174 - var $appearanceControls = $("#boxzilla-box-appearance-controls");
175 193
176 - // create Option objects
177 - options.borderColor = new Option('border-color');
178 - options.borderWidth = new Option('border-width');
179 - options.borderStyle = new Option('border-style');
180 - options.backgroundColor = new Option('background-color');
181 - options.width = new Option('width');
182 - options.color = new Option('color');
194 + options.borderColor = new Option('border-color');
195 + options.borderWidth = new Option('border-width');
196 + options.borderStyle = new Option('border-style');
197 + options.backgroundColor = new Option('background-color');
198 + options.width = new Option('width');
199 + options.color = new Option('color'); // add classes to TinyMCE <html>
183 200
184 - // functions
185 - function init() {
201 + $editorFrame = $('#content_ifr');
202 + $editor = $editorFrame.contents().find('html');
203 + $editor.css({
204 + background: 'white'
205 + }); // add content class and padding to TinyMCE <body>
186 206
187 - // Only run if TinyMCE has actually inited
188 - if (_typeof(window.tinyMCE) !== "object" || tinyMCE.get('content') === null) {
189 - return;
190 - }
207 + $innerEditor = $editor.find('#tinymce');
208 + $innerEditor.addClass('boxzilla boxzilla-' + boxId);
209 + $innerEditor.css({
210 + margin: 0,
211 + background: 'white',
212 + display: 'inline-block',
213 + width: 'auto',
214 + 'min-width': '240px',
215 + position: 'relative'
216 + });
217 + $innerEditor.get(0).style.cssText += ';padding: 25px !important;';
218 + visualEditorInitialised = true;
219 + /* @since 2.0.3 */
191 220
192 - // add classes to TinyMCE <html>
193 - $editorFrame = $("#content_ifr");
194 - $editor = $editorFrame.contents().find('html');
195 - $editor.css({
196 - 'background': 'white'
197 - });
221 + events.trigger('editor.init');
222 + }
223 + /**
224 + * Applies the styles from the options to the TinyMCE Editor
225 + *
226 + * @return bool
227 + */
198 228
199 - // add content class and padding to TinyMCE <body>
200 - $innerEditor = $editor.find('#tinymce');
201 - $innerEditor.addClass('boxzilla boxzilla-' + boxId);
202 - $innerEditor.css({
203 - 'margin': 0,
204 - 'background': 'white',
205 - 'display': 'inline-block',
206 - 'width': 'auto',
207 - 'min-width': '240px',
208 - 'position': 'relative'
209 - });
210 - $innerEditor.get(0).style.cssText += ';padding: 25px !important;';
211 229
212 - visualEditorInitialised = true;
230 + function applyStyles() {
231 + if (!visualEditorInitialised) {
232 + return false;
233 + } // Apply styles from CSS editor.
234 + // Use short timeout to make sure color values are updated.
213 235
214 - /* @since 2.0.3 */
215 - events.trigger('editor.init');
216 - }
217 236
218 - /**
219 - * Applies the styles from the options to the TinyMCE Editor
220 - *
221 - * @return bool
222 - */
223 - function applyStyles() {
237 + window.setTimeout(function () {
238 + $innerEditor.css({
239 + 'border-color': options.borderColor.getColorValue(),
240 + // getColorValue( 'borderColor', '' ),
241 + 'border-width': options.borderWidth.getPxValue(),
242 + // getPxValue( 'borderWidth', '' ),
243 + 'border-style': options.borderStyle.getValue(),
244 + // getValue('borderStyle', '' ),
245 + 'background-color': options.backgroundColor.getColorValue(),
246 + // getColorValue( 'backgroundColor', ''),
247 + width: options.width.getPxValue(),
248 + // getPxValue( 'width', 'auto' ),
249 + color: options.color.getColorValue() // getColorValue( 'color', '' )
224 250
225 - if (!visualEditorInitialised) {
226 - return false;
227 - }
251 + });
252 + /* @since 2.0.3 */
228 253
229 - // apply styles from CSS editor
230 - $innerEditor.css({
231 - 'border-color': options.borderColor.getColorValue(), //getColorValue( 'borderColor', '' ),
232 - 'border-width': options.borderWidth.getPxValue(), //getPxValue( 'borderWidth', '' ),
233 - 'border-style': options.borderStyle.getValue(), //getValue('borderStyle', '' ),
234 - 'background-color': options.backgroundColor.getColorValue(), //getColorValue( 'backgroundColor', ''),
235 - 'width': options.width.getPxValue(), //getPxValue( 'width', 'auto' ),
236 - 'color': options.color.getColorValue() // getColorValue( 'color', '' )
237 - });
254 + events.trigger('editor.styles.apply');
255 + }, 10);
256 + return true;
257 + }
238 258
239 - /* @since 2.0.3 */
240 - events.trigger('editor.styles.apply');
259 + function resetStyles() {
260 + for (var key in options) {
261 + if (key.substring(0, 5) === 'theme') {
262 + continue;
263 + }
241 264
242 - return true;
243 - }
265 + options[key].clear();
266 + }
244 267
245 - function resetStyles() {
246 - for (var key in options) {
247 - if (key.substring(0, 5) === 'theme') {
248 - continue;
249 - }
268 + applyStyles();
269 + /* @since 2.0.3 */
250 270
251 - options[key].clear();
252 - }
253 - applyStyles();
271 + events.trigger('editor.styles.reset');
272 + } // event binders
254 273
255 - /* @since 2.0.3 */
256 - events.trigger('editor.styles.reset');
257 - }
258 274
259 - // event binders
260 - $appearanceControls.find('input.boxzilla-color-field').wpColorPicker({ change: applyStyles, clear: applyStyles });
261 - $appearanceControls.find(":input").not(".boxzilla-color-field").change(applyStyles);
262 - events.on('editor.init', applyStyles);
275 + $appearanceControls.find('input.boxzilla-color-field').wpColorPicker({
276 + change: applyStyles,
277 + clear: applyStyles
278 + });
279 + $appearanceControls.find(':input').not('.boxzilla-color-field').change(applyStyles);
280 + events.on('editor.init', applyStyles); // public methods
263 281
264 - // public methods
265 - return {
266 - 'init': init,
267 - 'resetStyles': resetStyles,
268 - 'options': options
269 - };
282 + return {
283 + init: init,
284 + resetStyles: resetStyles,
285 + options: options
286 + };
270 287 };
271 288
272 289 module.exports = Designer;
273 290
274 291 },{}],4:[function(require,module,exports){
275 -'use strict';
292 +"use strict";
276 293
277 294 var $ = window.jQuery;
278 295
279 296 var Option = function Option(element) {
297 + // find corresponding element
298 + if (typeof element === 'string') {
299 + element = document.getElementById('boxzilla-' + element);
300 + }
280 301
281 - // find corresponding element
282 - if (typeof element == "string") {
283 - element = document.getElementById('boxzilla-' + element);
284 - }
302 + if (!element) {
303 + console.error('Unable to find option element.');
304 + }
285 305
286 - if (!element) {
287 - console.error("Unable to find option element.");
288 - }
289 -
290 - this.element = element;
306 + this.element = element;
291 307 };
292 308
293 309 Option.prototype.getColorValue = function () {
294 - if (this.element.value.length > 0) {
295 - if ($(this.element).hasClass('wp-color-field')) {
296 - return $(this.element).wpColorPicker('color');
297 - } else {
298 - return this.element.value;
299 - }
300 - }
310 + if (this.element.value.length > 0) {
311 + if ($(this.element).hasClass('wp-color-field')) {
312 + return $(this.element).wpColorPicker('color');
313 + } else {
314 + return this.element.value;
315 + }
316 + }
301 317
302 - return '';
318 + return '';
303 319 };
304 320
305 321 Option.prototype.getPxValue = function (fallbackValue) {
306 - if (this.element.value.length > 0) {
307 - return parseInt(this.element.value) + "px";
308 - }
322 + if (this.element.value.length > 0) {
323 + return parseInt(this.element.value) + 'px';
324 + }
309 325
310 - return fallbackValue || '';
326 + return fallbackValue || '';
311 327 };
312 328
313 329 Option.prototype.getValue = function (fallbackValue) {
330 + if (this.element.value.length > 0) {
331 + return this.element.value;
332 + }
314 333
315 - if (this.element.value.length > 0) {
316 - return this.element.value;
317 - }
318 -
319 - return fallbackValue || '';
334 + return fallbackValue || '';
320 335 };
321 336
322 337 Option.prototype.clear = function () {
323 - this.element.value = '';
338 + this.element.value = '';
324 339 };
325 340
326 341 Option.prototype.setValue = function (value) {
327 - this.element.value = value;
342 + this.element.value = value;
328 343 };
329 344
330 345 module.exports = Option;
331 346
@@ -330,15 +345,15 @@
330 345 module.exports = Option;
331 346
332 347 },{}],5:[function(require,module,exports){
333 348 /*!
334 - * EventEmitter v4.2.11 - git.io/ee
349 + * EventEmitter v5.2.9 - git.io/ee
335 350 * Unlicense - http://unlicense.org/
336 - * Oliver Caldwell - http://oli.me.uk/
351 + * Oliver Caldwell - https://oli.me.uk/
337 352 * @preserve
338 353 */
339 354
340 -;(function () {
355 +;(function (exports) {
341 356 'use strict';
342 357
343 358 /**
344 359 * Class for managing events.
@@ -349,9 +364,8 @@
349 364 function EventEmitter() {}
350 365
351 366 // Shortcuts to improve speed and size
352 367 var proto = EventEmitter.prototype;
353 - var exports = this;
354 368 var originalGlobalValue = exports.EventEmitter;
355 369
356 370 /**
357 371 * Finds the index of the listener for the event in its storage array.
@@ -450,8 +464,18 @@
450 464
451 465 return response || listeners;
452 466 };
453 467
468 + function isValidListener (listener) {
469 + if (typeof listener === 'function' || listener instanceof RegExp) {
470 + return true
471 + } else if (listener && typeof listener === 'object') {
472 + return isValidListener(listener.listener)
473 + } else {
474 + return false
475 + }
476 + }
477 +
454 478 /**
455 479 * Adds a listener function to the specified event.
456 480 * The listener will not be added if it is a duplicate.
457 481 * If the listener returns true then it will be removed after it is called.
@@ -461,8 +485,12 @@
461 485 * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
462 486 * @return {Object} Current instance of EventEmitter for chaining.
463 487 */
464 488 proto.addListener = function addListener(evt, listener) {
489 + if (!isValidListener(listener)) {
490 + throw new TypeError('listener must be a function');
491 + }
492 +
465 493 var listeners = this.getListenersAsObject(evt);
466 494 var listenerIsWrapped = typeof listener === 'object';
467 495 var key;
468 496
@@ -560,9 +588,9 @@
560 588 proto.off = alias('removeListener');
561 589
562 590 /**
563 591 * Adds listeners in bulk using the manipulateListeners method.
564 - * 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.
592 + * 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.
565 593 * You can also pass it a regular expression to add the array of listeners to all events that match it.
566 594 * Yeah, this function does quite a bit. That's probably a bad thing.
567 595 *
568 596 * @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.
@@ -575,9 +603,9 @@
575 603 };
576 604
577 605 /**
578 606 * Removes listeners in bulk using the manipulateListeners method.
579 - * 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.
607 + * 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.
580 608 * You can also pass it an event name and an array of listeners to be removed.
581 609 * You can also pass it a regular expression to remove the listeners from all events that match it.
582 610 *
583 611 * @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.
@@ -699,11 +727,10 @@
699 727
700 728 for (key in listenersMap) {
701 729 if (listenersMap.hasOwnProperty(key)) {
702 730 listeners = listenersMap[key].slice(0);
703 - i = listeners.length;
704 731
705 - while (i--) {
732 + for (i = 0; i < listeners.length; i++) {
706 733 // If the listener returns true then it shall be removed from the event
707 734 // The function is executed either with a basic call or an apply if there is an args array
708 735 listener = listeners[i];
709 736
@@ -802,8 +829,8 @@
802 829 }
803 830 else {
804 831 exports.EventEmitter = EventEmitter;
805 832 }
806 -}.call(this));
833 +}(typeof window !== 'undefined' ? window : this || {}));
807 834
808 835 },{}]},{},[1]);
809 836 ; })();