PluginProbe
Boxzilla – WordPress Popup Builder / 3.2.13
Boxzilla – WordPress Popup Builder v3.2.13
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
boxzilla / assets / js / admin-script.js

admin-script.js in Boxzilla – WordPress Popup Builder 3.2.13, at assets/js/admin-script.js

843 lines 29.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
4 window.Boxzilla_Admin = require('./admin/_admin.js');
5
6 },{"./admin/_admin.js":2}],2:[function(require,module,exports){
7 "use strict";
8
9 (function () {
10 'use strict';
11
12 var $ = window.jQuery;
13
14 var Option = require('./_option.js');
15
16 var optionControls = document.getElementById('boxzilla-box-options-controls');
17 var $optionControls = $(optionControls);
18 var tnLoggedIn = document.createTextNode(' logged in'); // sanity check, are we on the correct page?
19
20 if ($optionControls.length === 0) {
21 return;
22 }
23
24 var EventEmitter = require('wolfy87-eventemitter');
25
26 var events = new EventEmitter();
27
28 var Designer = require('./_designer.js')($, Option, events);
29
30 var rowTemplate = wp.template('rule-row-template');
31 var i18n = boxzilla_i18n;
32 var ruleComparisonEl = document.getElementById('boxzilla-rule-comparison');
33 var rulesContainerEl = document.getElementById('boxzilla-box-rules'); // events
34
35 $optionControls.on('click', ".boxzilla-add-rule", addRuleFields);
36 $optionControls.on('click', ".boxzilla-remove-rule", removeRule);
37 $optionControls.on('change', ".boxzilla-rule-condition", setContextualHelpers);
38 $optionControls.find('.boxzilla-auto-show-trigger').on('change', toggleTriggerOptions);
39 $(ruleComparisonEl).change(toggleAndOrTexts);
40 $(window).load(function () {
41 if (typeof window.tinyMCE === "undefined") {
42 document.getElementById('notice-notinymce').style.display = '';
43 }
44 }); // call contextual helper method for each row
45
46 $('.boxzilla-rule-row').each(setContextualHelpers);
47
48 function toggleAndOrTexts() {
49 var newText = ruleComparisonEl.value === 'any' ? i18n.or : i18n.and;
50 $('.boxzilla-andor').text(newText);
51 }
52
53 function toggleTriggerOptions() {
54 $optionControls.find('.boxzilla-trigger-options').toggle(this.value !== '');
55 }
56
57 function removeRule() {
58 var row = $(this).parents('tr'); // delete andor row
59
60 row.prev().remove(); // delete rule row
61
62 row.remove();
63 }
64
65 function setContextualHelpers() {
66 var context = this.tagName.toLowerCase() === "tr" ? this : $(this).parents('tr').get(0);
67 var condition = context.querySelector('.boxzilla-rule-condition').value;
68 var valueInput = context.querySelector('.boxzilla-rule-value');
69 var qualifierInput = context.querySelector('.boxzilla-rule-qualifier');
70 var betterInput = valueInput.cloneNode(true);
71 var $betterInput = $(betterInput); // remove previously added helpers
72
73 $(context.querySelectorAll('.boxzilla-helper')).remove(); // prepare better input
74
75 betterInput.removeAttribute('name');
76 betterInput.className = betterInput.className + ' boxzilla-helper';
77 valueInput.parentNode.insertBefore(betterInput, valueInput.nextSibling);
78 $betterInput.change(function () {
79 valueInput.value = this.value;
80 });
81 betterInput.style.display = '';
82 valueInput.style.display = 'none';
83 qualifierInput.style.display = '';
84 qualifierInput.querySelector('option[value="not_contains"]').style.display = 'none';
85 qualifierInput.querySelector('option[value="contains"]').style.display = 'none';
86
87 if (tnLoggedIn.parentNode) {
88 tnLoggedIn.parentNode.removeChild(tnLoggedIn);
89 } // change placeholder for textual help
90
91
92 switch (condition) {
93 default:
94 betterInput.placeholder = i18n.enterCommaSeparatedValues;
95 break;
96
97 case '':
98 case 'everywhere':
99 qualifierInput.value = '1';
100 valueInput.value = '';
101 betterInput.style.display = 'none';
102 qualifierInput.style.display = 'none';
103 break;
104
105 case 'is_single':
106 case 'is_post':
107 betterInput.placeholder = i18n.enterCommaSeparatedPosts;
108 $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post", {
109 multiple: true,
110 multipleSep: ","
111 });
112 break;
113
114 case 'is_page':
115 betterInput.placeholder = i18n.enterCommaSeparatedPages;
116 $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=page", {
117 multiple: true,
118 multipleSep: ","
119 });
120 break;
121
122 case 'is_post_type':
123 betterInput.placeholder = i18n.enterCommaSeparatedPostTypes;
124 $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post_type", {
125 multiple: true,
126 multipleSep: ","
127 });
128 break;
129
130 case 'is_url':
131 qualifierInput.querySelector('option[value="contains"]').style.display = '';
132 qualifierInput.querySelector('option[value="not_contains"]').style.display = '';
133 betterInput.placeholder = i18n.enterCommaSeparatedRelativeUrls;
134 break;
135
136 case 'is_post_in_category':
137 $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=category", {
138 multiple: true,
139 multipleSep: ","
140 });
141 break;
142
143 case 'is_post_with_tag':
144 $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post_tag", {
145 multiple: true,
146 multipleSep: ","
147 });
148 break;
149
150 case 'is_user_logged_in':
151 betterInput.style.display = 'none';
152 valueInput.parentNode.insertBefore(tnLoggedIn, valueInput.nextSibling);
153 break;
154
155 case 'is_referer':
156 qualifierInput.querySelector('option[value="contains"]').style.display = '';
157 qualifierInput.querySelector('option[value="not_contains"]').style.display = '';
158 break;
159 }
160 }
161
162 function addRuleFields() {
163 var data = {
164 'key': optionControls.querySelectorAll('.boxzilla-rule-row').length,
165 'andor': ruleComparisonEl.value === 'any' ? i18n.or : i18n.and
166 };
167 var html = rowTemplate(data);
168 $(rulesContainerEl).append(html);
169 return false;
170 }
171
172 module.exports = {
173 'Designer': Designer,
174 'Option': Option,
175 'events': events
176 };
177 })();
178
179 },{"./_designer.js":3,"./_option.js":4,"wolfy87-eventemitter":5}],3:[function(require,module,exports){
180 "use strict";
181
182 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); }
183
184 var Designer = function Designer($, Option, events) {
185 // vars
186 var boxId = document.getElementById('post_ID').value || 0,
187 $editor,
188 $editorFrame,
189 $innerEditor,
190 options = {},
191 visualEditorInitialised = false;
192 var $appearanceControls = $("#boxzilla-box-appearance-controls"); // create Option objects
193
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'); // functions
200
201 function init() {
202 // Only run if TinyMCE has actually inited
203 if (_typeof(window.tinyMCE) !== "object" || tinyMCE.get('content') === null) {
204 return;
205 } // add classes to TinyMCE <html>
206
207
208 $editorFrame = $("#content_ifr");
209 $editor = $editorFrame.contents().find('html');
210 $editor.css({
211 'background': 'white'
212 }); // add content class and padding to TinyMCE <body>
213
214 $innerEditor = $editor.find('#tinymce');
215 $innerEditor.addClass('boxzilla boxzilla-' + boxId);
216 $innerEditor.css({
217 'margin': 0,
218 'background': 'white',
219 'display': 'inline-block',
220 'width': 'auto',
221 'min-width': '240px',
222 'position': 'relative'
223 });
224 $innerEditor.get(0).style.cssText += ';padding: 25px !important;';
225 visualEditorInitialised = true;
226 /* @since 2.0.3 */
227
228 events.trigger('editor.init');
229 }
230 /**
231 * Applies the styles from the options to the TinyMCE Editor
232 *
233 * @return bool
234 */
235
236
237 function applyStyles() {
238 if (!visualEditorInitialised) {
239 return false;
240 } // Apply styles from CSS editor.
241 // Use short timeout to make sure color values are updated.
242
243
244 window.setTimeout(function () {
245 $innerEditor.css({
246 'border-color': options.borderColor.getColorValue(),
247 //getColorValue( 'borderColor', '' ),
248 'border-width': options.borderWidth.getPxValue(),
249 //getPxValue( 'borderWidth', '' ),
250 'border-style': options.borderStyle.getValue(),
251 //getValue('borderStyle', '' ),
252 'background-color': options.backgroundColor.getColorValue(),
253 //getColorValue( 'backgroundColor', ''),
254 'width': options.width.getPxValue(),
255 //getPxValue( 'width', 'auto' ),
256 'color': options.color.getColorValue() // getColorValue( 'color', '' )
257
258 });
259 /* @since 2.0.3 */
260
261 events.trigger('editor.styles.apply');
262 }, 10);
263 return true;
264 }
265
266 function resetStyles() {
267 for (var key in options) {
268 if (key.substring(0, 5) === 'theme') {
269 continue;
270 }
271
272 options[key].clear();
273 }
274
275 applyStyles();
276 /* @since 2.0.3 */
277
278 events.trigger('editor.styles.reset');
279 } // event binders
280
281
282 $appearanceControls.find('input.boxzilla-color-field').wpColorPicker({
283 change: applyStyles,
284 clear: applyStyles
285 });
286 $appearanceControls.find(":input").not(".boxzilla-color-field").change(applyStyles);
287 events.on('editor.init', applyStyles); // public methods
288
289 return {
290 'init': init,
291 'resetStyles': resetStyles,
292 'options': options
293 };
294 };
295
296 module.exports = Designer;
297
298 },{}],4:[function(require,module,exports){
299 'use strict';
300
301 var $ = window.jQuery;
302
303 var Option = function Option(element) {
304 // find corresponding element
305 if (typeof element == "string") {
306 element = document.getElementById('boxzilla-' + element);
307 }
308
309 if (!element) {
310 console.error("Unable to find option element.");
311 }
312
313 this.element = element;
314 };
315
316 Option.prototype.getColorValue = function () {
317 if (this.element.value.length > 0) {
318 if ($(this.element).hasClass('wp-color-field')) {
319 return $(this.element).wpColorPicker('color');
320 } else {
321 return this.element.value;
322 }
323 }
324
325 return '';
326 };
327
328 Option.prototype.getPxValue = function (fallbackValue) {
329 if (this.element.value.length > 0) {
330 return parseInt(this.element.value) + "px";
331 }
332
333 return fallbackValue || '';
334 };
335
336 Option.prototype.getValue = function (fallbackValue) {
337 if (this.element.value.length > 0) {
338 return this.element.value;
339 }
340
341 return fallbackValue || '';
342 };
343
344 Option.prototype.clear = function () {
345 this.element.value = '';
346 };
347
348 Option.prototype.setValue = function (value) {
349 this.element.value = value;
350 };
351
352 module.exports = Option;
353
354 },{}],5:[function(require,module,exports){
355 /*!
356 * EventEmitter v5.2.6 - git.io/ee
357 * Unlicense - http://unlicense.org/
358 * Oliver Caldwell - https://oli.me.uk/
359 * @preserve
360 */
361
362 ;(function (exports) {
363 'use strict';
364
365 /**
366 * Class for managing events.
367 * Can be extended to provide event functionality in other classes.
368 *
369 * @class EventEmitter Manages event registering and emitting.
370 */
371 function EventEmitter() {}
372
373 // Shortcuts to improve speed and size
374 var proto = EventEmitter.prototype;
375 var originalGlobalValue = exports.EventEmitter;
376
377 /**
378 * Finds the index of the listener for the event in its storage array.
379 *
380 * @param {Function[]} listeners Array of listeners to search through.
381 * @param {Function} listener Method to look for.
382 * @return {Number} Index of the specified listener, -1 if not found
383 * @api private
384 */
385 function indexOfListener(listeners, listener) {
386 var i = listeners.length;
387 while (i--) {
388 if (listeners[i].listener === listener) {
389 return i;
390 }
391 }
392
393 return -1;
394 }
395
396 /**
397 * Alias a method while keeping the context correct, to allow for overwriting of target method.
398 *
399 * @param {String} name The name of the target method.
400 * @return {Function} The aliased method
401 * @api private
402 */
403 function alias(name) {
404 return function aliasClosure() {
405 return this[name].apply(this, arguments);
406 };
407 }
408
409 /**
410 * Returns the listener array for the specified event.
411 * Will initialise the event object and listener arrays if required.
412 * Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them.
413 * Each property in the object response is an array of listener functions.
414 *
415 * @param {String|RegExp} evt Name of the event to return the listeners from.
416 * @return {Function[]|Object} All listener functions for the event.
417 */
418 proto.getListeners = function getListeners(evt) {
419 var events = this._getEvents();
420 var response;
421 var key;
422
423 // Return a concatenated array of all matching events if
424 // the selector is a regular expression.
425 if (evt instanceof RegExp) {
426 response = {};
427 for (key in events) {
428 if (events.hasOwnProperty(key) && evt.test(key)) {
429 response[key] = events[key];
430 }
431 }
432 }
433 else {
434 response = events[evt] || (events[evt] = []);
435 }
436
437 return response;
438 };
439
440 /**
441 * Takes a list of listener objects and flattens it into a list of listener functions.
442 *
443 * @param {Object[]} listeners Raw listener objects.
444 * @return {Function[]} Just the listener functions.
445 */
446 proto.flattenListeners = function flattenListeners(listeners) {
447 var flatListeners = [];
448 var i;
449
450 for (i = 0; i < listeners.length; i += 1) {
451 flatListeners.push(listeners[i].listener);
452 }
453
454 return flatListeners;
455 };
456
457 /**
458 * Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful.
459 *
460 * @param {String|RegExp} evt Name of the event to return the listeners from.
461 * @return {Object} All listener functions for an event in an object.
462 */
463 proto.getListenersAsObject = function getListenersAsObject(evt) {
464 var listeners = this.getListeners(evt);
465 var response;
466
467 if (listeners instanceof Array) {
468 response = {};
469 response[evt] = listeners;
470 }
471
472 return response || listeners;
473 };
474
475 function isValidListener (listener) {
476 if (typeof listener === 'function' || listener instanceof RegExp) {
477 return true
478 } else if (listener && typeof listener === 'object') {
479 return isValidListener(listener.listener)
480 } else {
481 return false
482 }
483 }
484
485 /**
486 * Adds a listener function to the specified event.
487 * The listener will not be added if it is a duplicate.
488 * If the listener returns true then it will be removed after it is called.
489 * If you pass a regular expression as the event name then the listener will be added to all events that match it.
490 *
491 * @param {String|RegExp} evt Name of the event to attach the listener to.
492 * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
493 * @return {Object} Current instance of EventEmitter for chaining.
494 */
495 proto.addListener = function addListener(evt, listener) {
496 if (!isValidListener(listener)) {
497 throw new TypeError('listener must be a function');
498 }
499
500 var listeners = this.getListenersAsObject(evt);
501 var listenerIsWrapped = typeof listener === 'object';
502 var key;
503
504 for (key in listeners) {
505 if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) {
506 listeners[key].push(listenerIsWrapped ? listener : {
507 listener: listener,
508 once: false
509 });
510 }
511 }
512
513 return this;
514 };
515
516 /**
517 * Alias of addListener
518 */
519 proto.on = alias('addListener');
520
521 /**
522 * Semi-alias of addListener. It will add a listener that will be
523 * automatically removed after its first execution.
524 *
525 * @param {String|RegExp} evt Name of the event to attach the listener to.
526 * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
527 * @return {Object} Current instance of EventEmitter for chaining.
528 */
529 proto.addOnceListener = function addOnceListener(evt, listener) {
530 return this.addListener(evt, {
531 listener: listener,
532 once: true
533 });
534 };
535
536 /**
537 * Alias of addOnceListener.
538 */
539 proto.once = alias('addOnceListener');
540
541 /**
542 * Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad.
543 * You need to tell it what event names should be matched by a regex.
544 *
545 * @param {String} evt Name of the event to create.
546 * @return {Object} Current instance of EventEmitter for chaining.
547 */
548 proto.defineEvent = function defineEvent(evt) {
549 this.getListeners(evt);
550 return this;
551 };
552
553 /**
554 * Uses defineEvent to define multiple events.
555 *
556 * @param {String[]} evts An array of event names to define.
557 * @return {Object} Current instance of EventEmitter for chaining.
558 */
559 proto.defineEvents = function defineEvents(evts) {
560 for (var i = 0; i < evts.length; i += 1) {
561 this.defineEvent(evts[i]);
562 }
563 return this;
564 };
565
566 /**
567 * Removes a listener function from the specified event.
568 * When passed a regular expression as the event name, it will remove the listener from all events that match it.
569 *
570 * @param {String|RegExp} evt Name of the event to remove the listener from.
571 * @param {Function} listener Method to remove from the event.
572 * @return {Object} Current instance of EventEmitter for chaining.
573 */
574 proto.removeListener = function removeListener(evt, listener) {
575 var listeners = this.getListenersAsObject(evt);
576 var index;
577 var key;
578
579 for (key in listeners) {
580 if (listeners.hasOwnProperty(key)) {
581 index = indexOfListener(listeners[key], listener);
582
583 if (index !== -1) {
584 listeners[key].splice(index, 1);
585 }
586 }
587 }
588
589 return this;
590 };
591
592 /**
593 * Alias of removeListener
594 */
595 proto.off = alias('removeListener');
596
597 /**
598 * Adds listeners in bulk using the manipulateListeners method.
599 * 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.
600 * You can also pass it a regular expression to add the array of listeners to all events that match it.
601 * Yeah, this function does quite a bit. That's probably a bad thing.
602 *
603 * @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.
604 * @param {Function[]} [listeners] An optional array of listener functions to add.
605 * @return {Object} Current instance of EventEmitter for chaining.
606 */
607 proto.addListeners = function addListeners(evt, listeners) {
608 // Pass through to manipulateListeners
609 return this.manipulateListeners(false, evt, listeners);
610 };
611
612 /**
613 * Removes listeners in bulk using the manipulateListeners method.
614 * 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.
615 * You can also pass it an event name and an array of listeners to be removed.
616 * You can also pass it a regular expression to remove the listeners from all events that match it.
617 *
618 * @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.
619 * @param {Function[]} [listeners] An optional array of listener functions to remove.
620 * @return {Object} Current instance of EventEmitter for chaining.
621 */
622 proto.removeListeners = function removeListeners(evt, listeners) {
623 // Pass through to manipulateListeners
624 return this.manipulateListeners(true, evt, listeners);
625 };
626
627 /**
628 * Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level.
629 * The first argument will determine if the listeners are removed (true) or added (false).
630 * If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
631 * You can also pass it an event name and an array of listeners to be added/removed.
632 * You can also pass it a regular expression to manipulate the listeners of all events that match it.
633 *
634 * @param {Boolean} remove True if you want to remove listeners, false if you want to add.
635 * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once.
636 * @param {Function[]} [listeners] An optional array of listener functions to add/remove.
637 * @return {Object} Current instance of EventEmitter for chaining.
638 */
639 proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) {
640 var i;
641 var value;
642 var single = remove ? this.removeListener : this.addListener;
643 var multiple = remove ? this.removeListeners : this.addListeners;
644
645 // If evt is an object then pass each of its properties to this method
646 if (typeof evt === 'object' && !(evt instanceof RegExp)) {
647 for (i in evt) {
648 if (evt.hasOwnProperty(i) && (value = evt[i])) {
649 // Pass the single listener straight through to the singular method
650 if (typeof value === 'function') {
651 single.call(this, i, value);
652 }
653 else {
654 // Otherwise pass back to the multiple function
655 multiple.call(this, i, value);
656 }
657 }
658 }
659 }
660 else {
661 // So evt must be a string
662 // And listeners must be an array of listeners
663 // Loop over it and pass each one to the multiple method
664 i = listeners.length;
665 while (i--) {
666 single.call(this, evt, listeners[i]);
667 }
668 }
669
670 return this;
671 };
672
673 /**
674 * Removes all listeners from a specified event.
675 * If you do not specify an event then all listeners will be removed.
676 * That means every event will be emptied.
677 * You can also pass a regex to remove all events that match it.
678 *
679 * @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed.
680 * @return {Object} Current instance of EventEmitter for chaining.
681 */
682 proto.removeEvent = function removeEvent(evt) {
683 var type = typeof evt;
684 var events = this._getEvents();
685 var key;
686
687 // Remove different things depending on the state of evt
688 if (type === 'string') {
689 // Remove all listeners for the specified event
690 delete events[evt];
691 }
692 else if (evt instanceof RegExp) {
693 // Remove all events matching the regex.
694 for (key in events) {
695 if (events.hasOwnProperty(key) && evt.test(key)) {
696 delete events[key];
697 }
698 }
699 }
700 else {
701 // Remove all listeners in all events
702 delete this._events;
703 }
704
705 return this;
706 };
707
708 /**
709 * Alias of removeEvent.
710 *
711 * Added to mirror the node API.
712 */
713 proto.removeAllListeners = alias('removeEvent');
714
715 /**
716 * Emits an event of your choice.
717 * When emitted, every listener attached to that event will be executed.
718 * If you pass the optional argument array then those arguments will be passed to every listener upon execution.
719 * Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately.
720 * So they will not arrive within the array on the other side, they will be separate.
721 * You can also pass a regular expression to emit to all events that match it.
722 *
723 * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
724 * @param {Array} [args] Optional array of arguments to be passed to each listener.
725 * @return {Object} Current instance of EventEmitter for chaining.
726 */
727 proto.emitEvent = function emitEvent(evt, args) {
728 var listenersMap = this.getListenersAsObject(evt);
729 var listeners;
730 var listener;
731 var i;
732 var key;
733 var response;
734
735 for (key in listenersMap) {
736 if (listenersMap.hasOwnProperty(key)) {
737 listeners = listenersMap[key].slice(0);
738
739 for (i = 0; i < listeners.length; i++) {
740 // If the listener returns true then it shall be removed from the event
741 // The function is executed either with a basic call or an apply if there is an args array
742 listener = listeners[i];
743
744 if (listener.once === true) {
745 this.removeListener(evt, listener.listener);
746 }
747
748 response = listener.listener.apply(this, args || []);
749
750 if (response === this._getOnceReturnValue()) {
751 this.removeListener(evt, listener.listener);
752 }
753 }
754 }
755 }
756
757 return this;
758 };
759
760 /**
761 * Alias of emitEvent
762 */
763 proto.trigger = alias('emitEvent');
764
765 /**
766 * Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on.
767 * As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.
768 *
769 * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
770 * @param {...*} Optional additional arguments to be passed to each listener.
771 * @return {Object} Current instance of EventEmitter for chaining.
772 */
773 proto.emit = function emit(evt) {
774 var args = Array.prototype.slice.call(arguments, 1);
775 return this.emitEvent(evt, args);
776 };
777
778 /**
779 * Sets the current value to check against when executing listeners. If a
780 * listeners return value matches the one set here then it will be removed
781 * after execution. This value defaults to true.
782 *
783 * @param {*} value The new value to check for when executing listeners.
784 * @return {Object} Current instance of EventEmitter for chaining.
785 */
786 proto.setOnceReturnValue = function setOnceReturnValue(value) {
787 this._onceReturnValue = value;
788 return this;
789 };
790
791 /**
792 * Fetches the current value to check against when executing listeners. If
793 * the listeners return value matches this one then it should be removed
794 * automatically. It will return true by default.
795 *
796 * @return {*|Boolean} The current value to check for or the default, true.
797 * @api private
798 */
799 proto._getOnceReturnValue = function _getOnceReturnValue() {
800 if (this.hasOwnProperty('_onceReturnValue')) {
801 return this._onceReturnValue;
802 }
803 else {
804 return true;
805 }
806 };
807
808 /**
809 * Fetches the events object and creates one if required.
810 *
811 * @return {Object} The events storage object.
812 * @api private
813 */
814 proto._getEvents = function _getEvents() {
815 return this._events || (this._events = {});
816 };
817
818 /**
819 * Reverts the global {@link EventEmitter} to its previous value and returns a reference to this version.
820 *
821 * @return {Function} Non conflicting EventEmitter class.
822 */
823 EventEmitter.noConflict = function noConflict() {
824 exports.EventEmitter = originalGlobalValue;
825 return EventEmitter;
826 };
827
828 // Expose the class either via AMD, CommonJS or the global object
829 if (typeof define === 'function' && define.amd) {
830 define(function () {
831 return EventEmitter;
832 });
833 }
834 else if (typeof module === 'object' && module.exports){
835 module.exports = EventEmitter;
836 }
837 else {
838 exports.EventEmitter = EventEmitter;
839 }
840 }(typeof window !== 'undefined' ? window : this || {}));
841
842 },{}]},{},[1]);
843 ; })();