kono_utils 0.15.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +442 -0
  4. data/Rakefile +23 -0
  5. data/app/assets/javascripts/kono_utils/utilities.coffee +456 -0
  6. data/app/assets/stylesheets/kono_utils/utils.css.scss +43 -0
  7. data/app/controllers/kono_utils/change_log_controller.rb +6 -0
  8. data/app/input/bs_aceeditor_input.rb +53 -0
  9. data/app/input/bs_autocomplete_input.rb +60 -0
  10. data/app/input/bs_datepicker_input.rb +16 -0
  11. data/app/input/bs_datetimepicker_input.rb +80 -0
  12. data/app/input/bs_file_download_input.rb +35 -0
  13. data/app/input/bs_image_input.rb +35 -0
  14. data/app/input/bs_label_with_container_input.rb +22 -0
  15. data/app/input/bs_location_picker_input.rb +95 -0
  16. data/app/input/bs_readonly_input.rb +52 -0
  17. data/app/input/bs_timepicker_input.rb +14 -0
  18. data/app/policies/kono_utils/base_editing_policy_concern.rb +27 -0
  19. data/app/views/kono_utils/base_editing/_edit.html.erb +3 -0
  20. data/app/views/kono_utils/base_editing/_edit_page_side_title_header.html.erb +3 -0
  21. data/app/views/kono_utils/base_editing/_edit_page_title_header.html.erb +3 -0
  22. data/app/views/kono_utils/base_editing/_form.html.erb +15 -0
  23. data/app/views/kono_utils/base_editing/_index_buttons.html.erb +2 -0
  24. data/app/views/kono_utils/base_editing/_index_page_side_title_header.html.erb +3 -0
  25. data/app/views/kono_utils/base_editing/_index_page_title_header.html.erb +3 -0
  26. data/app/views/kono_utils/base_editing/_index_tfoot.html.erb +0 -0
  27. data/app/views/kono_utils/base_editing/_new.html.erb +3 -0
  28. data/app/views/kono_utils/base_editing/_new_page_side_title_header.html.erb +3 -0
  29. data/app/views/kono_utils/base_editing/_new_page_title_header.html.erb +3 -0
  30. data/app/views/kono_utils/base_editing/_search_form.html.erb +1 -0
  31. data/app/views/kono_utils/base_editing/application/_edit_page_side_title_header.html.erb +1 -0
  32. data/app/views/kono_utils/base_editing/application/_edit_page_title_header.html.erb +1 -0
  33. data/app/views/kono_utils/base_editing/application/_index_page_side_title_header.html.erb +1 -0
  34. data/app/views/kono_utils/base_editing/application/_index_page_title_header.html.erb +1 -0
  35. data/app/views/kono_utils/base_editing/application/_new_page_side_title_header.html.erb +1 -0
  36. data/app/views/kono_utils/base_editing/application/_new_page_title_header.html.erb +1 -0
  37. data/app/views/kono_utils/base_editing/application/edit.html.erb +1 -0
  38. data/app/views/kono_utils/base_editing/application/new.html.erb +1 -0
  39. data/app/views/kono_utils/base_editing/edit.html.erb +1 -0
  40. data/app/views/kono_utils/base_editing/index.html.erb +36 -0
  41. data/app/views/kono_utils/base_editing/new.html.erb +1 -0
  42. data/app/views/kono_utils/change_log/index.html.erb +3 -0
  43. data/config/initializers/mysql.rb +12 -0
  44. data/config/initializers/time.rb +12 -0
  45. data/config/locales/it.yml +18 -0
  46. data/lib/generators/kono_utils/install/install_generator.rb +24 -0
  47. data/lib/generators/templates/initializer.rb +3 -0
  48. data/lib/kono_utils.rb +41 -0
  49. data/lib/kono_utils/application_helper.rb +625 -0
  50. data/lib/kono_utils/base_editing_helper.rb +194 -0
  51. data/lib/kono_utils/base_search.rb +173 -0
  52. data/lib/kono_utils/concerns.rb +10 -0
  53. data/lib/kono_utils/concerns/active_record_translation.rb +47 -0
  54. data/lib/kono_utils/concerns/base_editing.rb +195 -0
  55. data/lib/kono_utils/concerns/base_modals.rb +97 -0
  56. data/lib/kono_utils/concerns/success_message.rb +25 -0
  57. data/lib/kono_utils/encoder.rb +55 -0
  58. data/lib/kono_utils/engine.rb +13 -0
  59. data/lib/kono_utils/fiscal_code.rb +47 -0
  60. data/lib/kono_utils/params_hash_array.rb +37 -0
  61. data/lib/kono_utils/percentage.rb +60 -0
  62. data/lib/kono_utils/search_attribute.rb +57 -0
  63. data/lib/kono_utils/tmp_file.rb +81 -0
  64. data/lib/kono_utils/version.rb +3 -0
  65. data/lib/kono_utils/virtual_model.rb +22 -0
  66. data/lib/tasks/kono_utils_tasks.rake +4 -0
  67. data/spec/dummy/README.rdoc +28 -0
  68. data/spec/dummy/Rakefile +6 -0
  69. data/spec/dummy/app/assets/images/.keep +0 -0
  70. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  71. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  72. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  73. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  74. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  75. data/spec/dummy/app/mailers/.keep +0 -0
  76. data/spec/dummy/app/models/.keep +0 -0
  77. data/spec/dummy/app/models/concerns/.keep +0 -0
  78. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  79. data/spec/dummy/bin/bundle +3 -0
  80. data/spec/dummy/bin/rails +4 -0
  81. data/spec/dummy/bin/rake +4 -0
  82. data/spec/dummy/bin/setup +29 -0
  83. data/spec/dummy/config.ru +4 -0
  84. data/spec/dummy/config/application.rb +32 -0
  85. data/spec/dummy/config/boot.rb +5 -0
  86. data/spec/dummy/config/database.yml +25 -0
  87. data/spec/dummy/config/environment.rb +5 -0
  88. data/spec/dummy/config/environments/development.rb +41 -0
  89. data/spec/dummy/config/environments/production.rb +79 -0
  90. data/spec/dummy/config/environments/test.rb +42 -0
  91. data/spec/dummy/config/initializers/assets.rb +11 -0
  92. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  93. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  94. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  95. data/spec/dummy/config/initializers/inflections.rb +16 -0
  96. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  97. data/spec/dummy/config/initializers/session_store.rb +3 -0
  98. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  99. data/spec/dummy/config/locales/en.yml +23 -0
  100. data/spec/dummy/config/routes.rb +56 -0
  101. data/spec/dummy/config/secrets.yml +22 -0
  102. data/spec/dummy/lib/assets/.keep +0 -0
  103. data/spec/dummy/log/.keep +0 -0
  104. data/spec/dummy/public/404.html +67 -0
  105. data/spec/dummy/public/422.html +67 -0
  106. data/spec/dummy/public/500.html +66 -0
  107. data/spec/dummy/public/favicon.ico +0 -0
  108. data/spec/lib/kono_utils/fiscal_code_spec.rb +56 -0
  109. data/spec/rails_helper.rb +53 -0
  110. data/spec/spec_helper.rb +92 -0
  111. data/vendor/assets/javascripts/EventEmitter.js +473 -0
  112. metadata +425 -0
@@ -0,0 +1,92 @@
1
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Allows RSpec to persist some state between runs in order to support
54
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
55
+ # you configure your source control system to ignore this file.
56
+ config.example_status_persistence_file_path = "spec/examples.txt"
57
+
58
+ # Limits the available syntax to the non-monkey patched syntax that is
59
+ # recommended. For more details, see:
60
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
61
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
62
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
63
+ config.disable_monkey_patching!
64
+
65
+ # Many RSpec users commonly either run the entire suite or an individual
66
+ # file, and it's useful to allow more verbose output when running an
67
+ # individual spec file.
68
+ if config.files_to_run.one?
69
+ # Use the documentation formatter for detailed output,
70
+ # unless a formatter has already been configured
71
+ # (e.g. via a command-line flag).
72
+ config.default_formatter = 'doc'
73
+ end
74
+
75
+ # Print the 10 slowest examples and example groups at the
76
+ # end of the spec run, to help surface which specs are running
77
+ # particularly slow.
78
+ config.profile_examples = 10
79
+
80
+ # Run specs in random order to surface order dependencies. If you find an
81
+ # order dependency and want to debug it, you can fix the order by providing
82
+ # the seed, which is printed after each run.
83
+ # --seed 1234
84
+ config.order = :random
85
+
86
+ # Seed global randomization in this process using the `--seed` CLI option.
87
+ # Setting this allows you to use `--seed` to deterministically reproduce
88
+ # test failures related to randomization by passing the same `--seed` value
89
+ # as the one that triggered the failure.
90
+ Kernel.srand config.seed
91
+ =end
92
+ end
@@ -0,0 +1,473 @@
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));