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 +282 -231 3.1.143.2.21 View file →
@@ -1,307 +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);
11 +var Option = require('./_option.js');
16 12
17 - // sanity check, are we on the correct page?
18 - if ($optionControls.length === 0) {
19 - return;
20 - }
13 +var optionControls = document.getElementById('boxzilla-box-options-controls');
14 +var $optionControls = $(optionControls);
15 +var tnLoggedIn = document.createTextNode(' logged in');
21 16
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;
17 +var EventEmitter = require('wolfy87-eventemitter');
27 18
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);
19 +var events = new EventEmitter();
33 20
34 - $(window).load(function () {
35 - if (typeof window.tinyMCE === "undefined") {
36 - document.getElementById('notice-notinymce').style.display = '';
37 - }
38 - });
21 +var Designer = require('./_designer.js')($, Option, events);
39 22
40 - // call contextual helper method for each row
41 - $('.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
42 28
43 - function toggleTriggerOptions() {
44 - $optionControls.find('.boxzilla-trigger-options').toggle(this.value !== '');
45 - }
29 +$(window).load(function () {
30 + if (typeof window.tinyMCE === 'undefined') {
31 + document.getElementById('notice-notinymce').style.display = '';
32 + }
46 33
47 - function removeRule() {
48 - $(this).parents('tr').remove();
49 - }
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 +});
50 41
51 - function setContextualHelpers() {
42 +function toggleAndOrTexts() {
43 + var newText = ruleComparisonEl.value === 'any' ? i18n.or : i18n.and;
44 + $('.boxzilla-andor').text(newText);
45 +}
52 46
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);
47 +function toggleTriggerOptions() {
48 + $optionControls.find('.boxzilla-trigger-options').toggle(this.value !== '');
49 +}
59 50
60 - // remove previously added helpers
61 - $(context.querySelectorAll('.boxzilla-helper')).remove();
51 +function removeRule() {
52 + var row = $(this).parents('tr'); // delete andor row
62 53
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 - });
54 + row.prev().remove(); // delete rule row
70 55
71 - betterInput.style.display = '';
72 - valueInput.style.display = 'none';
73 - qualifierInput.style.display = '';
56 + row.remove();
57 +}
74 58
75 - // change placeholder for textual help
76 - switch (condition) {
77 - default:
78 - betterInput.placeholder = i18n.enterCommaSeparatedValues;
79 - 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
80 66
81 - case '':
82 - case 'everywhere':
83 - qualifierInput.value = '1';
84 - valueInput.value = '';
85 - betterInput.style.display = 'none';
86 - qualifierInput.style.display = 'none';
87 - break;
67 + $(context.querySelectorAll('.boxzilla-helper')).remove(); // prepare better input
88 68
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;
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';
94 80
95 - case 'is_page':
96 - betterInput.placeholder = i18n.enterCommaSeparatedPages;
97 - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=page", { multiple: true, multipleSep: "," });
98 - break;
81 + if (tnLoggedIn.parentNode) {
82 + tnLoggedIn.parentNode.removeChild(tnLoggedIn);
83 + } // change placeholder for textual help
99 84
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;
104 85
105 - case 'is_url':
106 - betterInput.placeholder = i18n.enterCommaSeparatedRelativeUrls;
107 - break;
86 + switch (condition) {
87 + default:
88 + betterInput.placeholder = i18n.enterCommaSeparatedValues;
89 + break;
108 90
109 - case 'is_post_in_category':
110 - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=category", { multiple: true, multipleSep: "," });
111 - 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;
112 98
113 - case 'is_post_with_tag':
114 - $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post_tag", { multiple: true, multipleSep: "," });
115 - break;
116 - }
117 - }
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;
118 107
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 - }
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;
127 115
128 - module.exports = {
129 - 'Designer': Designer,
130 - 'Option': Option,
131 - 'events': events
132 - };
133 -})();
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;
134 123
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;
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 +
135 172 },{"./_designer.js":3,"./_option.js":4,"wolfy87-eventemitter":5}],3:[function(require,module,exports){
136 -'use strict';
173 +"use strict";
137 174
138 -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); }
139 176
140 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
141 186
142 - // vars
143 - var boxId = document.getElementById('post_ID').value || 0,
144 - $editor,
145 - $editorFrame,
146 - $innerEditor,
147 - options = {},
148 - 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
149 192
150 - var $appearanceControls = $("#boxzilla-box-appearance-controls");
151 193
152 - // create Option objects
153 - options.borderColor = new Option('border-color');
154 - options.borderWidth = new Option('border-width');
155 - options.borderStyle = new Option('border-style');
156 - options.backgroundColor = new Option('background-color');
157 - options.width = new Option('width');
158 - 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>
159 200
160 - // functions
161 - 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>
162 206
163 - // Only run if TinyMCE has actually inited
164 - if (_typeof(window.tinyMCE) !== "object" || tinyMCE.get('content') === null) {
165 - return;
166 - }
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 */
167 220
168 - // add classes to TinyMCE <html>
169 - $editorFrame = $("#content_ifr");
170 - $editor = $editorFrame.contents().find('html');
171 - $editor.css({
172 - 'background': 'white'
173 - });
221 + events.trigger('editor.init');
222 + }
223 + /**
224 + * Applies the styles from the options to the TinyMCE Editor
225 + *
226 + * @return bool
227 + */
174 228
175 - // add content class and padding to TinyMCE <body>
176 - $innerEditor = $editor.find('#tinymce');
177 - $innerEditor.addClass('boxzilla boxzilla-' + boxId);
178 - $innerEditor.css({
179 - 'margin': 0,
180 - 'background': 'white',
181 - 'display': 'inline-block',
182 - 'width': 'auto',
183 - 'min-width': '240px',
184 - 'position': 'relative'
185 - });
186 - $innerEditor.get(0).style.cssText += ';padding: 25px !important;';
187 229
188 - 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.
189 235
190 - /* @since 2.0.3 */
191 - events.trigger('editor.init');
192 - }
193 236
194 - /**
195 - * Applies the styles from the options to the TinyMCE Editor
196 - *
197 - * @return bool
198 - */
199 - 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', '' )
200 250
201 - if (!visualEditorInitialised) {
202 - return false;
203 - }
251 + });
252 + /* @since 2.0.3 */
204 253
205 - // apply styles from CSS editor
206 - $innerEditor.css({
207 - 'border-color': options.borderColor.getColorValue(), //getColorValue( 'borderColor', '' ),
208 - 'border-width': options.borderWidth.getPxValue(), //getPxValue( 'borderWidth', '' ),
209 - 'border-style': options.borderStyle.getValue(), //getValue('borderStyle', '' ),
210 - 'background-color': options.backgroundColor.getColorValue(), //getColorValue( 'backgroundColor', ''),
211 - 'width': options.width.getPxValue(), //getPxValue( 'width', 'auto' ),
212 - 'color': options.color.getColorValue() // getColorValue( 'color', '' )
213 - });
254 + events.trigger('editor.styles.apply');
255 + }, 10);
256 + return true;
257 + }
214 258
215 - /* @since 2.0.3 */
216 - events.trigger('editor.styles.apply');
259 + function resetStyles() {
260 + for (var key in options) {
261 + if (key.substring(0, 5) === 'theme') {
262 + continue;
263 + }
217 264
218 - return true;
219 - }
265 + options[key].clear();
266 + }
220 267
221 - function resetStyles() {
222 - for (var key in options) {
223 - if (key.substring(0, 5) === 'theme') {
224 - continue;
225 - }
268 + applyStyles();
269 + /* @since 2.0.3 */
226 270
227 - options[key].clear();
228 - }
229 - applyStyles();
271 + events.trigger('editor.styles.reset');
272 + } // event binders
230 273
231 - /* @since 2.0.3 */
232 - events.trigger('editor.styles.reset');
233 - }
234 274
235 - // event binders
236 - $appearanceControls.find('input.boxzilla-color-field').wpColorPicker({ change: applyStyles, clear: applyStyles });
237 - $appearanceControls.find(":input").not(".boxzilla-color-field").change(applyStyles);
238 - 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
239 281
240 - // public methods
241 - return {
242 - 'init': init,
243 - 'resetStyles': resetStyles,
244 - 'options': options
245 - };
282 + return {
283 + init: init,
284 + resetStyles: resetStyles,
285 + options: options
286 + };
246 287 };
247 288
248 289 module.exports = Designer;
249 290
250 291 },{}],4:[function(require,module,exports){
251 -'use strict';
292 +"use strict";
252 293
253 294 var $ = window.jQuery;
254 295
255 296 var Option = function Option(element) {
297 + // find corresponding element
298 + if (typeof element === 'string') {
299 + element = document.getElementById('boxzilla-' + element);
300 + }
256 301
257 - // find corresponding element
258 - if (typeof element == "string") {
259 - element = document.getElementById('boxzilla-' + element);
260 - }
302 + if (!element) {
303 + console.error('Unable to find option element.');
304 + }
261 305
262 - if (!element) {
263 - console.error("Unable to find option element.");
264 - }
265 -
266 - this.element = element;
306 + this.element = element;
267 307 };
268 308
269 309 Option.prototype.getColorValue = function () {
270 - if (this.element.value.length > 0) {
271 - if ($(this.element).hasClass('wp-color-field')) {
272 - return $(this.element).wpColorPicker('color');
273 - } else {
274 - return this.element.value;
275 - }
276 - }
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 + }
277 317
278 - return '';
318 + return '';
279 319 };
280 320
281 321 Option.prototype.getPxValue = function (fallbackValue) {
282 - if (this.element.value.length > 0) {
283 - return parseInt(this.element.value) + "px";
284 - }
322 + if (this.element.value.length > 0) {
323 + return parseInt(this.element.value) + 'px';
324 + }
285 325
286 - return fallbackValue || '';
326 + return fallbackValue || '';
287 327 };
288 328
289 329 Option.prototype.getValue = function (fallbackValue) {
330 + if (this.element.value.length > 0) {
331 + return this.element.value;
332 + }
290 333
291 - if (this.element.value.length > 0) {
292 - return this.element.value;
293 - }
294 -
295 - return fallbackValue || '';
334 + return fallbackValue || '';
296 335 };
297 336
298 337 Option.prototype.clear = function () {
299 - this.element.value = '';
338 + this.element.value = '';
300 339 };
301 340
302 341 Option.prototype.setValue = function (value) {
303 - this.element.value = value;
342 + this.element.value = value;
304 343 };
305 344
306 345 module.exports = Option;
307 346
@@ -306,15 +345,15 @@
306 345 module.exports = Option;
307 346
308 347 },{}],5:[function(require,module,exports){
309 348 /*!
310 - * EventEmitter v4.2.11 - git.io/ee
349 + * EventEmitter v5.2.9 - git.io/ee
311 350 * Unlicense - http://unlicense.org/
312 - * Oliver Caldwell - http://oli.me.uk/
351 + * Oliver Caldwell - https://oli.me.uk/
313 352 * @preserve
314 353 */
315 354
316 -;(function () {
355 +;(function (exports) {
317 356 'use strict';
318 357
319 358 /**
320 359 * Class for managing events.
@@ -325,9 +364,8 @@
325 364 function EventEmitter() {}
326 365
327 366 // Shortcuts to improve speed and size
328 367 var proto = EventEmitter.prototype;
329 - var exports = this;
330 368 var originalGlobalValue = exports.EventEmitter;
331 369
332 370 /**
333 371 * Finds the index of the listener for the event in its storage array.
@@ -426,8 +464,18 @@
426 464
427 465 return response || listeners;
428 466 };
429 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 +
430 478 /**
431 479 * Adds a listener function to the specified event.
432 480 * The listener will not be added if it is a duplicate.
433 481 * If the listener returns true then it will be removed after it is called.
@@ -437,8 +485,12 @@
437 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.
438 486 * @return {Object} Current instance of EventEmitter for chaining.
439 487 */
440 488 proto.addListener = function addListener(evt, listener) {
489 + if (!isValidListener(listener)) {
490 + throw new TypeError('listener must be a function');
491 + }
492 +
441 493 var listeners = this.getListenersAsObject(evt);
442 494 var listenerIsWrapped = typeof listener === 'object';
443 495 var key;
444 496
@@ -536,9 +588,9 @@
536 588 proto.off = alias('removeListener');
537 589
538 590 /**
539 591 * 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.
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.
541 593 * You can also pass it a regular expression to add the array of listeners to all events that match it.
542 594 * Yeah, this function does quite a bit. That's probably a bad thing.
543 595 *
544 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.
@@ -551,9 +603,9 @@
551 603 };
552 604
553 605 /**
554 606 * 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.
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.
556 608 * You can also pass it an event name and an array of listeners to be removed.
557 609 * You can also pass it a regular expression to remove the listeners from all events that match it.
558 610 *
559 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.
@@ -675,11 +727,10 @@
675 727
676 728 for (key in listenersMap) {
677 729 if (listenersMap.hasOwnProperty(key)) {
678 730 listeners = listenersMap[key].slice(0);
679 - i = listeners.length;
680 731
681 - while (i--) {
732 + for (i = 0; i < listeners.length; i++) {
682 733 // If the listener returns true then it shall be removed from the event
683 734 // The function is executed either with a basic call or an apply if there is an args array
684 735 listener = listeners[i];
685 736
@@ -778,8 +829,8 @@
778 829 }
779 830 else {
780 831 exports.EventEmitter = EventEmitter;
781 832 }
782 -}.call(this));
833 +}(typeof window !== 'undefined' ? window : this || {}));
783 834
784 835 },{}]},{},[1]);
785 836 ; })();