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

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