kono_utils 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +5 -5
  2. data/README.rdoc +0 -76
  3. data/app/assets/javascripts/kono_utils/core.coffee +477 -0
  4. data/app/assets/stylesheets/kono_utils/{_kono_styles.css.scss → core.css.scss} +1 -16
  5. data/app/policies/kono_utils/base_editing_policy_concern.rb +52 -3
  6. data/app/policies/kono_utils/base_search_form_policy_concern.rb +25 -0
  7. data/config/locales/it.yml +3 -1
  8. data/lib/generators/kono_utils/install/install_generator.rb +40 -3
  9. data/lib/generators/templates/base_editing_controller.template +3 -0
  10. data/lib/generators/templates/base_editing_helper.template +3 -0
  11. data/lib/generators/templates/base_editing_policy.template +4 -0
  12. data/lib/generators/templates/initializer.rb +3 -1
  13. data/lib/kono_utils.rb +20 -22
  14. data/lib/kono_utils/application_core_helper.rb +524 -0
  15. data/lib/kono_utils/application_enum_helper.rb +53 -0
  16. data/lib/kono_utils/application_helper.rb +4 -578
  17. data/lib/kono_utils/base_editing_core_helper.rb +194 -0
  18. data/lib/kono_utils/base_editing_helper.rb +3 -186
  19. data/lib/kono_utils/base_search.rb +32 -19
  20. data/lib/kono_utils/concerns/active_record_translation.rb +8 -4
  21. data/lib/kono_utils/concerns/active_storage_remover_helper.rb +61 -0
  22. data/lib/kono_utils/concerns/base_editing.rb +199 -53
  23. data/lib/kono_utils/configuration.rb +18 -0
  24. data/lib/kono_utils/engine.rb +15 -7
  25. data/lib/kono_utils/paginate_proxer.rb +17 -0
  26. data/lib/kono_utils/search_form_builder.rb +24 -0
  27. data/lib/kono_utils/version.rb +1 -1
  28. data/spec/dummy/app/assets/config/manifest.js +2 -0
  29. data/spec/dummy/app/assets/javascripts/application.js +1 -0
  30. data/spec/dummy/app/controllers/application_controller.rb +10 -0
  31. data/spec/dummy/app/controllers/base_editing_controller.rb +3 -0
  32. data/spec/dummy/app/controllers/users_controller.rb +2 -0
  33. data/spec/dummy/app/helpers/application_helper.rb +1 -0
  34. data/spec/dummy/app/helpers/base_editing_helper.rb +3 -0
  35. data/spec/dummy/app/models/application_record.rb +5 -0
  36. data/spec/dummy/app/models/user.rb +2 -0
  37. data/spec/dummy/app/policies/application_policy.rb +49 -0
  38. data/spec/dummy/app/policies/base_editing_policy.rb +4 -0
  39. data/spec/dummy/app/policies/user_policy.rb +23 -0
  40. data/spec/dummy/config/application.rb +1 -1
  41. data/spec/dummy/config/initializers/kono_utils.rb +3 -1
  42. data/spec/dummy/config/routes.rb +4 -0
  43. data/spec/dummy/db/migrate/20190716093114_create_users.rb +11 -0
  44. data/spec/dummy/db/schema.rb +23 -0
  45. data/spec/dummy/spec/models/user_spec.rb +5 -0
  46. metadata +63 -131
  47. data/app/assets/javascripts/kono_utils/utilities.coffee +0 -480
  48. data/app/assets/stylesheets/kono_utils/utils.css.scss +0 -4
  49. data/app/input/bs_aceeditor_input.rb +0 -53
  50. data/app/input/bs_autocomplete_input.rb +0 -60
  51. data/app/input/bs_datepicker_input.rb +0 -16
  52. data/app/input/bs_datetimepicker_input.rb +0 -80
  53. data/app/input/bs_file_download_input.rb +0 -35
  54. data/app/input/bs_image_input.rb +0 -35
  55. data/app/input/bs_label_with_container_input.rb +0 -22
  56. data/app/input/bs_location_picker_input.rb +0 -95
  57. data/app/input/bs_readonly_input.rb +0 -52
  58. data/app/input/bs_timepicker_input.rb +0 -14
  59. data/app/views/kono_utils/application/_search_panel.html.erb +0 -36
  60. data/app/views/kono_utils/base_editing/_edit.html.erb +0 -3
  61. data/app/views/kono_utils/base_editing/_edit_page_side_title_header.html.erb +0 -3
  62. data/app/views/kono_utils/base_editing/_edit_page_title_header.html.erb +0 -3
  63. data/app/views/kono_utils/base_editing/_form.html.erb +0 -15
  64. data/app/views/kono_utils/base_editing/_index_buttons.html.erb +0 -2
  65. data/app/views/kono_utils/base_editing/_index_page_side_title_header.html.erb +0 -3
  66. data/app/views/kono_utils/base_editing/_index_page_title_header.html.erb +0 -3
  67. data/app/views/kono_utils/base_editing/_index_tfoot.html.erb +0 -0
  68. data/app/views/kono_utils/base_editing/_new.html.erb +0 -3
  69. data/app/views/kono_utils/base_editing/_new_page_side_title_header.html.erb +0 -3
  70. data/app/views/kono_utils/base_editing/_new_page_title_header.html.erb +0 -3
  71. data/app/views/kono_utils/base_editing/_search_form.html.erb +0 -1
  72. data/app/views/kono_utils/base_editing/application/_edit_page_side_title_header.html.erb +0 -1
  73. data/app/views/kono_utils/base_editing/application/_edit_page_title_header.html.erb +0 -1
  74. data/app/views/kono_utils/base_editing/application/_index_page_side_title_header.html.erb +0 -1
  75. data/app/views/kono_utils/base_editing/application/_index_page_title_header.html.erb +0 -1
  76. data/app/views/kono_utils/base_editing/application/_new_page_side_title_header.html.erb +0 -1
  77. data/app/views/kono_utils/base_editing/application/_new_page_title_header.html.erb +0 -1
  78. data/app/views/kono_utils/base_editing/application/edit.html.erb +0 -1
  79. data/app/views/kono_utils/base_editing/application/new.html.erb +0 -1
  80. data/app/views/kono_utils/base_editing/edit.html.erb +0 -1
  81. data/app/views/kono_utils/base_editing/index.html.erb +0 -36
  82. data/app/views/kono_utils/base_editing/new.html.erb +0 -1
  83. data/lib/kono_utils/concerns.rb +0 -10
  84. data/lib/kono_utils/encoder.rb +0 -47
  85. data/lib/kono_utils/fiscal_code.rb +0 -47
  86. data/lib/kono_utils/params_hash_array.rb +0 -37
  87. data/lib/kono_utils/percentage.rb +0 -60
  88. data/lib/kono_utils/tmp_file.rb +0 -81
  89. data/lib/kono_utils/virtual_model.rb +0 -22
  90. data/lib/tasks/kono_utils_tasks.rake +0 -4
  91. data/spec/lib/kono_utils/fiscal_code_spec.rb +0 -56
  92. data/vendor/assets/javascripts/EventEmitter.js +0 -473
@@ -1,22 +0,0 @@
1
- require 'active_type'
2
- module KonoUtils
3
- class VirtualModel < ActiveType::Object
4
-
5
- # include ActiveModel::Validations
6
- # include ActiveModel::Conversion
7
- # extend ActiveModel::Naming
8
- #
9
- # def initialize(attributes = {})
10
- # attributes = [] if attributes.nil?
11
- # attributes.each do |name, value|
12
- # send("#{name}=", value)
13
- # end
14
- # end
15
- #
16
- # def persisted?
17
- # false
18
- # end
19
-
20
-
21
- end
22
- end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :kono_utils do
3
- # # Task goes here
4
- # end
@@ -1,56 +0,0 @@
1
- require_relative '../../rails_helper'
2
-
3
- #cd KonoUtils/spec && rspec lib/kono_utils/fiscal_code_spec.rb
4
-
5
- module KonoUtils
6
- describe FiscalCode do
7
-
8
- it "ControllaCF" do
9
-
10
- expect {
11
- KonoUtils::FiscalCode::ControllaCF.valid?("")
12
- }.to raise_error(KonoUtils::FiscalCode::ControllaCF::EmptyString)
13
-
14
- expect {
15
- KonoUtils::FiscalCode::ControllaCF.valid?("GHDJRU")
16
- }.to raise_error(KonoUtils::FiscalCode::ControllaCF::InvalidLength)
17
-
18
- expect {
19
- KonoUtils::FiscalCode::ControllaCF.valid?("rssmra80a01h501u", true)
20
- }.to raise_error(KonoUtils::FiscalCode::ControllaCF::CaseError)
21
-
22
- expect(
23
- KonoUtils::FiscalCode::ControllaCF.valid?("RSSMRA80A01H501U", true)
24
- ).to be_truthy
25
-
26
- expect(
27
- KonoUtils::FiscalCode::ControllaCF.valid?("RSSMRA80A01H501J", true)
28
- ).to be_falsey
29
-
30
- expect(
31
- KonoUtils::FiscalCode::ControllaCF.valid?("RSSMRA43S18L750G", true)
32
- ).to be_truthy
33
- end
34
-
35
- it "ControllaPI" do
36
- expect {
37
- KonoUtils::FiscalCode::ControllaPI.valid?("")
38
- }.to raise_error(KonoUtils::FiscalCode::ControllaPI::EmptyString)
39
-
40
- expect {
41
- KonoUtils::FiscalCode::ControllaPI.valid?("020405902")
42
- }.to raise_error(KonoUtils::FiscalCode::ControllaPI::InvalidLength)
43
-
44
- expect(
45
- KonoUtils::FiscalCode::ControllaPI.valid?("02040830982")
46
- ).to be_truthy
47
-
48
- expect(
49
- KonoUtils::FiscalCode::ControllaPI.valid?("02040830989")
50
- ).to be_falsey
51
-
52
- end
53
-
54
-
55
- end
56
- end
@@ -1,473 +0,0 @@
1
- /*!
2
- * EventEmitter v4.2.11 - git.io/ee
3
- * Unlicense - http://unlicense.org/
4
- * Oliver Caldwell - http://oli.me.uk/
5
- * https://github.com/Olical/EventEmitter
6
- * @preserve
7
- */
8
-
9
- ;(function () {
10
- 'use strict';
11
-
12
- /**
13
- * Class for managing events.
14
- * Can be extended to provide event functionality in other classes.
15
- *
16
- * @class EventEmitter Manages event registering and emitting.
17
- */
18
- function EventEmitter() {}
19
-
20
- // Shortcuts to improve speed and size
21
- var proto = EventEmitter.prototype;
22
- var exports = this;
23
- var originalGlobalValue = exports.EventEmitter;
24
-
25
- /**
26
- * Finds the index of the listener for the event in its storage array.
27
- *
28
- * @param {Function[]} listeners Array of listeners to search through.
29
- * @param {Function} listener Method to look for.
30
- * @return {Number} Index of the specified listener, -1 if not found
31
- * @api private
32
- */
33
- function indexOfListener(listeners, listener) {
34
- var i = listeners.length;
35
- while (i--) {
36
- if (listeners[i].listener === listener) {
37
- return i;
38
- }
39
- }
40
-
41
- return -1;
42
- }
43
-
44
- /**
45
- * Alias a method while keeping the context correct, to allow for overwriting of target method.
46
- *
47
- * @param {String} name The name of the target method.
48
- * @return {Function} The aliased method
49
- * @api private
50
- */
51
- function alias(name) {
52
- return function aliasClosure() {
53
- return this[name].apply(this, arguments);
54
- };
55
- }
56
-
57
- /**
58
- * Returns the listener array for the specified event.
59
- * Will initialise the event object and listener arrays if required.
60
- * 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.
61
- * Each property in the object response is an array of listener functions.
62
- *
63
- * @param {String|RegExp} evt Name of the event to return the listeners from.
64
- * @return {Function[]|Object} All listener functions for the event.
65
- */
66
- proto.getListeners = function getListeners(evt) {
67
- var events = this._getEvents();
68
- var response;
69
- var key;
70
-
71
- // Return a concatenated array of all matching events if
72
- // the selector is a regular expression.
73
- if (evt instanceof RegExp) {
74
- response = {};
75
- for (key in events) {
76
- if (events.hasOwnProperty(key) && evt.test(key)) {
77
- response[key] = events[key];
78
- }
79
- }
80
- }
81
- else {
82
- response = events[evt] || (events[evt] = []);
83
- }
84
-
85
- return response;
86
- };
87
-
88
- /**
89
- * Takes a list of listener objects and flattens it into a list of listener functions.
90
- *
91
- * @param {Object[]} listeners Raw listener objects.
92
- * @return {Function[]} Just the listener functions.
93
- */
94
- proto.flattenListeners = function flattenListeners(listeners) {
95
- var flatListeners = [];
96
- var i;
97
-
98
- for (i = 0; i < listeners.length; i += 1) {
99
- flatListeners.push(listeners[i].listener);
100
- }
101
-
102
- return flatListeners;
103
- };
104
-
105
- /**
106
- * 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.
107
- *
108
- * @param {String|RegExp} evt Name of the event to return the listeners from.
109
- * @return {Object} All listener functions for an event in an object.
110
- */
111
- proto.getListenersAsObject = function getListenersAsObject(evt) {
112
- var listeners = this.getListeners(evt);
113
- var response;
114
-
115
- if (listeners instanceof Array) {
116
- response = {};
117
- response[evt] = listeners;
118
- }
119
-
120
- return response || listeners;
121
- };
122
-
123
- /**
124
- * Adds a listener function to the specified event.
125
- * The listener will not be added if it is a duplicate.
126
- * If the listener returns true then it will be removed after it is called.
127
- * If you pass a regular expression as the event name then the listener will be added to all events that match it.
128
- *
129
- * @param {String|RegExp} evt Name of the event to attach the listener to.
130
- * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
131
- * @return {Object} Current instance of EventEmitter for chaining.
132
- */
133
- proto.addListener = function addListener(evt, listener) {
134
- var listeners = this.getListenersAsObject(evt);
135
- var listenerIsWrapped = typeof listener === 'object';
136
- var key;
137
-
138
- for (key in listeners) {
139
- if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) {
140
- listeners[key].push(listenerIsWrapped ? listener : {
141
- listener: listener,
142
- once: false
143
- });
144
- }
145
- }
146
-
147
- return this;
148
- };
149
-
150
- /**
151
- * Alias of addListener
152
- */
153
- proto.on = alias('addListener');
154
-
155
- /**
156
- * Semi-alias of addListener. It will add a listener that will be
157
- * automatically removed after its first execution.
158
- *
159
- * @param {String|RegExp} evt Name of the event to attach the listener to.
160
- * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
161
- * @return {Object} Current instance of EventEmitter for chaining.
162
- */
163
- proto.addOnceListener = function addOnceListener(evt, listener) {
164
- return this.addListener(evt, {
165
- listener: listener,
166
- once: true
167
- });
168
- };
169
-
170
- /**
171
- * Alias of addOnceListener.
172
- */
173
- proto.once = alias('addOnceListener');
174
-
175
- /**
176
- * 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.
177
- * You need to tell it what event names should be matched by a regex.
178
- *
179
- * @param {String} evt Name of the event to create.
180
- * @return {Object} Current instance of EventEmitter for chaining.
181
- */
182
- proto.defineEvent = function defineEvent(evt) {
183
- this.getListeners(evt);
184
- return this;
185
- };
186
-
187
- /**
188
- * Uses defineEvent to define multiple events.
189
- *
190
- * @param {String[]} evts An array of event names to define.
191
- * @return {Object} Current instance of EventEmitter for chaining.
192
- */
193
- proto.defineEvents = function defineEvents(evts) {
194
- for (var i = 0; i < evts.length; i += 1) {
195
- this.defineEvent(evts[i]);
196
- }
197
- return this;
198
- };
199
-
200
- /**
201
- * Removes a listener function from the specified event.
202
- * When passed a regular expression as the event name, it will remove the listener from all events that match it.
203
- *
204
- * @param {String|RegExp} evt Name of the event to remove the listener from.
205
- * @param {Function} listener Method to remove from the event.
206
- * @return {Object} Current instance of EventEmitter for chaining.
207
- */
208
- proto.removeListener = function removeListener(evt, listener) {
209
- var listeners = this.getListenersAsObject(evt);
210
- var index;
211
- var key;
212
-
213
- for (key in listeners) {
214
- if (listeners.hasOwnProperty(key)) {
215
- index = indexOfListener(listeners[key], listener);
216
-
217
- if (index !== -1) {
218
- listeners[key].splice(index, 1);
219
- }
220
- }
221
- }
222
-
223
- return this;
224
- };
225
-
226
- /**
227
- * Alias of removeListener
228
- */
229
- proto.off = alias('removeListener');
230
-
231
- /**
232
- * Adds listeners in bulk using the manipulateListeners method.
233
- * If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added.
234
- * You can also pass it a regular expression to add the array of listeners to all events that match it.
235
- * Yeah, this function does quite a bit. That's probably a bad thing.
236
- *
237
- * @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.
238
- * @param {Function[]} [listeners] An optional array of listener functions to add.
239
- * @return {Object} Current instance of EventEmitter for chaining.
240
- */
241
- proto.addListeners = function addListeners(evt, listeners) {
242
- // Pass through to manipulateListeners
243
- return this.manipulateListeners(false, evt, listeners);
244
- };
245
-
246
- /**
247
- * Removes listeners in bulk using the manipulateListeners method.
248
- * If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
249
- * You can also pass it an event name and an array of listeners to be removed.
250
- * You can also pass it a regular expression to remove the listeners from all events that match it.
251
- *
252
- * @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.
253
- * @param {Function[]} [listeners] An optional array of listener functions to remove.
254
- * @return {Object} Current instance of EventEmitter for chaining.
255
- */
256
- proto.removeListeners = function removeListeners(evt, listeners) {
257
- // Pass through to manipulateListeners
258
- return this.manipulateListeners(true, evt, listeners);
259
- };
260
-
261
- /**
262
- * 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.
263
- * The first argument will determine if the listeners are removed (true) or added (false).
264
- * 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.
265
- * You can also pass it an event name and an array of listeners to be added/removed.
266
- * You can also pass it a regular expression to manipulate the listeners of all events that match it.
267
- *
268
- * @param {Boolean} remove True if you want to remove listeners, false if you want to add.
269
- * @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.
270
- * @param {Function[]} [listeners] An optional array of listener functions to add/remove.
271
- * @return {Object} Current instance of EventEmitter for chaining.
272
- */
273
- proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) {
274
- var i;
275
- var value;
276
- var single = remove ? this.removeListener : this.addListener;
277
- var multiple = remove ? this.removeListeners : this.addListeners;
278
-
279
- // If evt is an object then pass each of its properties to this method
280
- if (typeof evt === 'object' && !(evt instanceof RegExp)) {
281
- for (i in evt) {
282
- if (evt.hasOwnProperty(i) && (value = evt[i])) {
283
- // Pass the single listener straight through to the singular method
284
- if (typeof value === 'function') {
285
- single.call(this, i, value);
286
- }
287
- else {
288
- // Otherwise pass back to the multiple function
289
- multiple.call(this, i, value);
290
- }
291
- }
292
- }
293
- }
294
- else {
295
- // So evt must be a string
296
- // And listeners must be an array of listeners
297
- // Loop over it and pass each one to the multiple method
298
- i = listeners.length;
299
- while (i--) {
300
- single.call(this, evt, listeners[i]);
301
- }
302
- }
303
-
304
- return this;
305
- };
306
-
307
- /**
308
- * Removes all listeners from a specified event.
309
- * If you do not specify an event then all listeners will be removed.
310
- * That means every event will be emptied.
311
- * You can also pass a regex to remove all events that match it.
312
- *
313
- * @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed.
314
- * @return {Object} Current instance of EventEmitter for chaining.
315
- */
316
- proto.removeEvent = function removeEvent(evt) {
317
- var type = typeof evt;
318
- var events = this._getEvents();
319
- var key;
320
-
321
- // Remove different things depending on the state of evt
322
- if (type === 'string') {
323
- // Remove all listeners for the specified event
324
- delete events[evt];
325
- }
326
- else if (evt instanceof RegExp) {
327
- // Remove all events matching the regex.
328
- for (key in events) {
329
- if (events.hasOwnProperty(key) && evt.test(key)) {
330
- delete events[key];
331
- }
332
- }
333
- }
334
- else {
335
- // Remove all listeners in all events
336
- delete this._events;
337
- }
338
-
339
- return this;
340
- };
341
-
342
- /**
343
- * Alias of removeEvent.
344
- *
345
- * Added to mirror the node API.
346
- */
347
- proto.removeAllListeners = alias('removeEvent');
348
-
349
- /**
350
- * Emits an event of your choice.
351
- * When emitted, every listener attached to that event will be executed.
352
- * If you pass the optional argument array then those arguments will be passed to every listener upon execution.
353
- * Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately.
354
- * So they will not arrive within the array on the other side, they will be separate.
355
- * You can also pass a regular expression to emit to all events that match it.
356
- *
357
- * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
358
- * @param {Array} [args] Optional array of arguments to be passed to each listener.
359
- * @return {Object} Current instance of EventEmitter for chaining.
360
- */
361
- proto.emitEvent = function emitEvent(evt, args) {
362
- var listeners = this.getListenersAsObject(evt);
363
- var listener;
364
- var i;
365
- var key;
366
- var response;
367
-
368
- for (key in listeners) {
369
- if (listeners.hasOwnProperty(key)) {
370
- i = listeners[key].length;
371
-
372
- while (i--) {
373
- // If the listener returns true then it shall be removed from the event
374
- // The function is executed either with a basic call or an apply if there is an args array
375
- listener = listeners[key][i];
376
-
377
- if (listener.once === true) {
378
- this.removeListener(evt, listener.listener);
379
- }
380
-
381
- response = listener.listener.apply(this, args || []);
382
-
383
- if (response === this._getOnceReturnValue()) {
384
- this.removeListener(evt, listener.listener);
385
- }
386
- }
387
- }
388
- }
389
-
390
- return this;
391
- };
392
-
393
- /**
394
- * Alias of emitEvent
395
- */
396
- proto.trigger = alias('emitEvent');
397
-
398
- /**
399
- * 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.
400
- * As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.
401
- *
402
- * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
403
- * @param {...*} Optional additional arguments to be passed to each listener.
404
- * @return {Object} Current instance of EventEmitter for chaining.
405
- */
406
- proto.emit = function emit(evt) {
407
- var args = Array.prototype.slice.call(arguments, 1);
408
- return this.emitEvent(evt, args);
409
- };
410
-
411
- /**
412
- * Sets the current value to check against when executing listeners. If a
413
- * listeners return value matches the one set here then it will be removed
414
- * after execution. This value defaults to true.
415
- *
416
- * @param {*} value The new value to check for when executing listeners.
417
- * @return {Object} Current instance of EventEmitter for chaining.
418
- */
419
- proto.setOnceReturnValue = function setOnceReturnValue(value) {
420
- this._onceReturnValue = value;
421
- return this;
422
- };
423
-
424
- /**
425
- * Fetches the current value to check against when executing listeners. If
426
- * the listeners return value matches this one then it should be removed
427
- * automatically. It will return true by default.
428
- *
429
- * @return {*|Boolean} The current value to check for or the default, true.
430
- * @api private
431
- */
432
- proto._getOnceReturnValue = function _getOnceReturnValue() {
433
- if (this.hasOwnProperty('_onceReturnValue')) {
434
- return this._onceReturnValue;
435
- }
436
- else {
437
- return true;
438
- }
439
- };
440
-
441
- /**
442
- * Fetches the events object and creates one if required.
443
- *
444
- * @return {Object} The events storage object.
445
- * @api private
446
- */
447
- proto._getEvents = function _getEvents() {
448
- return this._events || (this._events = {});
449
- };
450
-
451
- /**
452
- * Reverts the global {@link EventEmitter} to its previous value and returns a reference to this version.
453
- *
454
- * @return {Function} Non conflicting EventEmitter class.
455
- */
456
- EventEmitter.noConflict = function noConflict() {
457
- exports.EventEmitter = originalGlobalValue;
458
- return EventEmitter;
459
- };
460
-
461
- // Expose the class either via AMD, CommonJS or the global object
462
- if (typeof define === 'function' && define.amd) {
463
- define(function () {
464
- return EventEmitter;
465
- });
466
- }
467
- else if (typeof module === 'object' && module.exports){
468
- module.exports = EventEmitter;
469
- }
470
- else {
471
- exports.EventEmitter = EventEmitter;
472
- }
473
- }.call(this));