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
boxzilla / assets / js / admin-script.js

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

836 lines 29.1 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 var $ = window.jQuery;
10
11 var Option = require('./_option.js');
12
13 var optionControls = document.getElementById('boxzilla-box-options-controls');
14 var $optionControls = $(optionControls);
15 var tnLoggedIn = document.createTextNode(' logged in');
16
17 var EventEmitter = require('wolfy87-eventemitter');
18
19 var events = new EventEmitter();
20
21 var Designer = require('./_designer.js')($, Option, events);
22
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
28
29 $(window).load(function () {
30 if (typeof window.tinyMCE === 'undefined') {
31 document.getElementById('notice-notinymce').style.display = '';
32 }
33
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 });
41
42 function toggleAndOrTexts() {
43 var newText = ruleComparisonEl.value === 'any' ? i18n.or : i18n.and;
44 $('.boxzilla-andor').text(newText);
45 }
46
47 function toggleTriggerOptions() {
48 $optionControls.find('.boxzilla-trigger-options').toggle(this.value !== '');
49 }
50
51 function removeRule() {
52 var row = $(this).parents('tr'); // delete andor row
53
54 row.prev().remove(); // delete rule row
55
56 row.remove();
57 }
58
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
66
67 $(context.querySelectorAll('.boxzilla-helper')).remove(); // prepare better input
68
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';
80
81 if (tnLoggedIn.parentNode) {
82 tnLoggedIn.parentNode.removeChild(tnLoggedIn);
83 } // change placeholder for textual help
84
85
86 switch (condition) {
87 default:
88 betterInput.placeholder = i18n.enterCommaSeparatedValues;
89 break;
90
91 case '':
92 case 'everywhere':
93 qualifierInput.value = '1';
94 valueInput.value = '';
95 betterInput.style.display = 'none';
96 qualifierInput.style.display = 'none';
97 break;
98
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;
107
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;
115
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;
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
172 },{"./_designer.js":3,"./_option.js":4,"wolfy87-eventemitter":5}],3:[function(require,module,exports){
173 "use strict";
174
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); }
176
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
186
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
192
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'); // add classes to TinyMCE <html>
200
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>
206
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 */
220
221 events.trigger('editor.init');
222 }
223 /**
224 * Applies the styles from the options to the TinyMCE Editor
225 *
226 * @return bool
227 */
228
229
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.
235
236
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', '' )
250
251 });
252 /* @since 2.0.3 */
253
254 events.trigger('editor.styles.apply');
255 }, 10);
256 return true;
257 }
258
259 function resetStyles() {
260 for (var key in options) {
261 if (key.substring(0, 5) === 'theme') {
262 continue;
263 }
264
265 options[key].clear();
266 }
267
268 applyStyles();
269 /* @since 2.0.3 */
270
271 events.trigger('editor.styles.reset');
272 } // event binders
273
274
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
281
282 return {
283 init: init,
284 resetStyles: resetStyles,
285 options: options
286 };
287 };
288
289 module.exports = Designer;
290
291 },{}],4:[function(require,module,exports){
292 "use strict";
293
294 var $ = window.jQuery;
295
296 var Option = function Option(element) {
297 // find corresponding element
298 if (typeof element === 'string') {
299 element = document.getElementById('boxzilla-' + element);
300 }
301
302 if (!element) {
303 console.error('Unable to find option element.');
304 }
305
306 this.element = element;
307 };
308
309 Option.prototype.getColorValue = function () {
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 }
317
318 return '';
319 };
320
321 Option.prototype.getPxValue = function (fallbackValue) {
322 if (this.element.value.length > 0) {
323 return parseInt(this.element.value) + 'px';
324 }
325
326 return fallbackValue || '';
327 };
328
329 Option.prototype.getValue = function (fallbackValue) {
330 if (this.element.value.length > 0) {
331 return this.element.value;
332 }
333
334 return fallbackValue || '';
335 };
336
337 Option.prototype.clear = function () {
338 this.element.value = '';
339 };
340
341 Option.prototype.setValue = function (value) {
342 this.element.value = value;
343 };
344
345 module.exports = Option;
346
347 },{}],5:[function(require,module,exports){
348 /*!
349 * EventEmitter v5.2.9 - git.io/ee
350 * Unlicense - http://unlicense.org/
351 * Oliver Caldwell - https://oli.me.uk/
352 * @preserve
353 */
354
355 ;(function (exports) {
356 'use strict';
357
358 /**
359 * Class for managing events.
360 * Can be extended to provide event functionality in other classes.
361 *
362 * @class EventEmitter Manages event registering and emitting.
363 */
364 function EventEmitter() {}
365
366 // Shortcuts to improve speed and size
367 var proto = EventEmitter.prototype;
368 var originalGlobalValue = exports.EventEmitter;
369
370 /**
371 * Finds the index of the listener for the event in its storage array.
372 *
373 * @param {Function[]} listeners Array of listeners to search through.
374 * @param {Function} listener Method to look for.
375 * @return {Number} Index of the specified listener, -1 if not found
376 * @api private
377 */
378 function indexOfListener(listeners, listener) {
379 var i = listeners.length;
380 while (i--) {
381 if (listeners[i].listener === listener) {
382 return i;
383 }
384 }
385
386 return -1;
387 }
388
389 /**
390 * Alias a method while keeping the context correct, to allow for overwriting of target method.
391 *
392 * @param {String} name The name of the target method.
393 * @return {Function} The aliased method
394 * @api private
395 */
396 function alias(name) {
397 return function aliasClosure() {
398 return this[name].apply(this, arguments);
399 };
400 }
401
402 /**
403 * Returns the listener array for the specified event.
404 * Will initialise the event object and listener arrays if required.
405 * 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.
406 * Each property in the object response is an array of listener functions.
407 *
408 * @param {String|RegExp} evt Name of the event to return the listeners from.
409 * @return {Function[]|Object} All listener functions for the event.
410 */
411 proto.getListeners = function getListeners(evt) {
412 var events = this._getEvents();
413 var response;
414 var key;
415
416 // Return a concatenated array of all matching events if
417 // the selector is a regular expression.
418 if (evt instanceof RegExp) {
419 response = {};
420 for (key in events) {
421 if (events.hasOwnProperty(key) && evt.test(key)) {
422 response[key] = events[key];
423 }
424 }
425 }
426 else {
427 response = events[evt] || (events[evt] = []);
428 }
429
430 return response;
431 };
432
433 /**
434 * Takes a list of listener objects and flattens it into a list of listener functions.
435 *
436 * @param {Object[]} listeners Raw listener objects.
437 * @return {Function[]} Just the listener functions.
438 */
439 proto.flattenListeners = function flattenListeners(listeners) {
440 var flatListeners = [];
441 var i;
442
443 for (i = 0; i < listeners.length; i += 1) {
444 flatListeners.push(listeners[i].listener);
445 }
446
447 return flatListeners;
448 };
449
450 /**
451 * 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.
452 *
453 * @param {String|RegExp} evt Name of the event to return the listeners from.
454 * @return {Object} All listener functions for an event in an object.
455 */
456 proto.getListenersAsObject = function getListenersAsObject(evt) {
457 var listeners = this.getListeners(evt);
458 var response;
459
460 if (listeners instanceof Array) {
461 response = {};
462 response[evt] = listeners;
463 }
464
465 return response || listeners;
466 };
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
478 /**
479 * Adds a listener function to the specified event.
480 * The listener will not be added if it is a duplicate.
481 * If the listener returns true then it will be removed after it is called.
482 * If you pass a regular expression as the event name then the listener will be added to all events that match it.
483 *
484 * @param {String|RegExp} evt Name of the event to attach the listener to.
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.
486 * @return {Object} Current instance of EventEmitter for chaining.
487 */
488 proto.addListener = function addListener(evt, listener) {
489 if (!isValidListener(listener)) {
490 throw new TypeError('listener must be a function');
491 }
492
493 var listeners = this.getListenersAsObject(evt);
494 var listenerIsWrapped = typeof listener === 'object';
495 var key;
496
497 for (key in listeners) {
498 if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) {
499 listeners[key].push(listenerIsWrapped ? listener : {
500 listener: listener,
501 once: false
502 });
503 }
504 }
505
506 return this;
507 };
508
509 /**
510 * Alias of addListener
511 */
512 proto.on = alias('addListener');
513
514 /**
515 * Semi-alias of addListener. It will add a listener that will be
516 * automatically removed after its first execution.
517 *
518 * @param {String|RegExp} evt Name of the event to attach the listener to.
519 * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
520 * @return {Object} Current instance of EventEmitter for chaining.
521 */
522 proto.addOnceListener = function addOnceListener(evt, listener) {
523 return this.addListener(evt, {
524 listener: listener,
525 once: true
526 });
527 };
528
529 /**
530 * Alias of addOnceListener.
531 */
532 proto.once = alias('addOnceListener');
533
534 /**
535 * 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.
536 * You need to tell it what event names should be matched by a regex.
537 *
538 * @param {String} evt Name of the event to create.
539 * @return {Object} Current instance of EventEmitter for chaining.
540 */
541 proto.defineEvent = function defineEvent(evt) {
542 this.getListeners(evt);
543 return this;
544 };
545
546 /**
547 * Uses defineEvent to define multiple events.
548 *
549 * @param {String[]} evts An array of event names to define.
550 * @return {Object} Current instance of EventEmitter for chaining.
551 */
552 proto.defineEvents = function defineEvents(evts) {
553 for (var i = 0; i < evts.length; i += 1) {
554 this.defineEvent(evts[i]);
555 }
556 return this;
557 };
558
559 /**
560 * Removes a listener function from the specified event.
561 * When passed a regular expression as the event name, it will remove the listener from all events that match it.
562 *
563 * @param {String|RegExp} evt Name of the event to remove the listener from.
564 * @param {Function} listener Method to remove from the event.
565 * @return {Object} Current instance of EventEmitter for chaining.
566 */
567 proto.removeListener = function removeListener(evt, listener) {
568 var listeners = this.getListenersAsObject(evt);
569 var index;
570 var key;
571
572 for (key in listeners) {
573 if (listeners.hasOwnProperty(key)) {
574 index = indexOfListener(listeners[key], listener);
575
576 if (index !== -1) {
577 listeners[key].splice(index, 1);
578 }
579 }
580 }
581
582 return this;
583 };
584
585 /**
586 * Alias of removeListener
587 */
588 proto.off = alias('removeListener');
589
590 /**
591 * Adds listeners in bulk using the manipulateListeners method.
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.
593 * You can also pass it a regular expression to add the array of listeners to all events that match it.
594 * Yeah, this function does quite a bit. That's probably a bad thing.
595 *
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.
597 * @param {Function[]} [listeners] An optional array of listener functions to add.
598 * @return {Object} Current instance of EventEmitter for chaining.
599 */
600 proto.addListeners = function addListeners(evt, listeners) {
601 // Pass through to manipulateListeners
602 return this.manipulateListeners(false, evt, listeners);
603 };
604
605 /**
606 * Removes listeners in bulk using the manipulateListeners method.
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.
608 * You can also pass it an event name and an array of listeners to be removed.
609 * You can also pass it a regular expression to remove the listeners from all events that match it.
610 *
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.
612 * @param {Function[]} [listeners] An optional array of listener functions to remove.
613 * @return {Object} Current instance of EventEmitter for chaining.
614 */
615 proto.removeListeners = function removeListeners(evt, listeners) {
616 // Pass through to manipulateListeners
617 return this.manipulateListeners(true, evt, listeners);
618 };
619
620 /**
621 * 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.
622 * The first argument will determine if the listeners are removed (true) or added (false).
623 * 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.
624 * You can also pass it an event name and an array of listeners to be added/removed.
625 * You can also pass it a regular expression to manipulate the listeners of all events that match it.
626 *
627 * @param {Boolean} remove True if you want to remove listeners, false if you want to add.
628 * @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.
629 * @param {Function[]} [listeners] An optional array of listener functions to add/remove.
630 * @return {Object} Current instance of EventEmitter for chaining.
631 */
632 proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) {
633 var i;
634 var value;
635 var single = remove ? this.removeListener : this.addListener;
636 var multiple = remove ? this.removeListeners : this.addListeners;
637
638 // If evt is an object then pass each of its properties to this method
639 if (typeof evt === 'object' && !(evt instanceof RegExp)) {
640 for (i in evt) {
641 if (evt.hasOwnProperty(i) && (value = evt[i])) {
642 // Pass the single listener straight through to the singular method
643 if (typeof value === 'function') {
644 single.call(this, i, value);
645 }
646 else {
647 // Otherwise pass back to the multiple function
648 multiple.call(this, i, value);
649 }
650 }
651 }
652 }
653 else {
654 // So evt must be a string
655 // And listeners must be an array of listeners
656 // Loop over it and pass each one to the multiple method
657 i = listeners.length;
658 while (i--) {
659 single.call(this, evt, listeners[i]);
660 }
661 }
662
663 return this;
664 };
665
666 /**
667 * Removes all listeners from a specified event.
668 * If you do not specify an event then all listeners will be removed.
669 * That means every event will be emptied.
670 * You can also pass a regex to remove all events that match it.
671 *
672 * @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed.
673 * @return {Object} Current instance of EventEmitter for chaining.
674 */
675 proto.removeEvent = function removeEvent(evt) {
676 var type = typeof evt;
677 var events = this._getEvents();
678 var key;
679
680 // Remove different things depending on the state of evt
681 if (type === 'string') {
682 // Remove all listeners for the specified event
683 delete events[evt];
684 }
685 else if (evt instanceof RegExp) {
686 // Remove all events matching the regex.
687 for (key in events) {
688 if (events.hasOwnProperty(key) && evt.test(key)) {
689 delete events[key];
690 }
691 }
692 }
693 else {
694 // Remove all listeners in all events
695 delete this._events;
696 }
697
698 return this;
699 };
700
701 /**
702 * Alias of removeEvent.
703 *
704 * Added to mirror the node API.
705 */
706 proto.removeAllListeners = alias('removeEvent');
707
708 /**
709 * Emits an event of your choice.
710 * When emitted, every listener attached to that event will be executed.
711 * If you pass the optional argument array then those arguments will be passed to every listener upon execution.
712 * Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately.
713 * So they will not arrive within the array on the other side, they will be separate.
714 * You can also pass a regular expression to emit to all events that match it.
715 *
716 * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
717 * @param {Array} [args] Optional array of arguments to be passed to each listener.
718 * @return {Object} Current instance of EventEmitter for chaining.
719 */
720 proto.emitEvent = function emitEvent(evt, args) {
721 var listenersMap = this.getListenersAsObject(evt);
722 var listeners;
723 var listener;
724 var i;
725 var key;
726 var response;
727
728 for (key in listenersMap) {
729 if (listenersMap.hasOwnProperty(key)) {
730 listeners = listenersMap[key].slice(0);
731
732 for (i = 0; i < listeners.length; i++) {
733 // If the listener returns true then it shall be removed from the event
734 // The function is executed either with a basic call or an apply if there is an args array
735 listener = listeners[i];
736
737 if (listener.once === true) {
738 this.removeListener(evt, listener.listener);
739 }
740
741 response = listener.listener.apply(this, args || []);
742
743 if (response === this._getOnceReturnValue()) {
744 this.removeListener(evt, listener.listener);
745 }
746 }
747 }
748 }
749
750 return this;
751 };
752
753 /**
754 * Alias of emitEvent
755 */
756 proto.trigger = alias('emitEvent');
757
758 /**
759 * 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.
760 * As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.
761 *
762 * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
763 * @param {...*} Optional additional arguments to be passed to each listener.
764 * @return {Object} Current instance of EventEmitter for chaining.
765 */
766 proto.emit = function emit(evt) {
767 var args = Array.prototype.slice.call(arguments, 1);
768 return this.emitEvent(evt, args);
769 };
770
771 /**
772 * Sets the current value to check against when executing listeners. If a
773 * listeners return value matches the one set here then it will be removed
774 * after execution. This value defaults to true.
775 *
776 * @param {*} value The new value to check for when executing listeners.
777 * @return {Object} Current instance of EventEmitter for chaining.
778 */
779 proto.setOnceReturnValue = function setOnceReturnValue(value) {
780 this._onceReturnValue = value;
781 return this;
782 };
783
784 /**
785 * Fetches the current value to check against when executing listeners. If
786 * the listeners return value matches this one then it should be removed
787 * automatically. It will return true by default.
788 *
789 * @return {*|Boolean} The current value to check for or the default, true.
790 * @api private
791 */
792 proto._getOnceReturnValue = function _getOnceReturnValue() {
793 if (this.hasOwnProperty('_onceReturnValue')) {
794 return this._onceReturnValue;
795 }
796 else {
797 return true;
798 }
799 };
800
801 /**
802 * Fetches the events object and creates one if required.
803 *
804 * @return {Object} The events storage object.
805 * @api private
806 */
807 proto._getEvents = function _getEvents() {
808 return this._events || (this._events = {});
809 };
810
811 /**
812 * Reverts the global {@link EventEmitter} to its previous value and returns a reference to this version.
813 *
814 * @return {Function} Non conflicting EventEmitter class.
815 */
816 EventEmitter.noConflict = function noConflict() {
817 exports.EventEmitter = originalGlobalValue;
818 return EventEmitter;
819 };
820
821 // Expose the class either via AMD, CommonJS or the global object
822 if (typeof define === 'function' && define.amd) {
823 define(function () {
824 return EventEmitter;
825 });
826 }
827 else if (typeof module === 'object' && module.exports){
828 module.exports = EventEmitter;
829 }
830 else {
831 exports.EventEmitter = EventEmitter;
832 }
833 }(typeof window !== 'undefined' ? window : this || {}));
834
835 },{}]},{},[1]);
836 ; })();