PluginProbe
Boxzilla – WordPress Popup Builder / 3.2
Boxzilla – WordPress Popup Builder v3.2
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, at assets/js/admin-script.js

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