modularity-rails 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@
8
8
  #
9
9
  # Warning: Caches the responses, so once a request is cached,
10
10
  # any new content on the same URL will not be visible!
11
- class window.modularity.AjaxLoader
11
+ class modularity.AjaxLoader
12
12
 
13
13
  constructor: (params = {}) ->
14
14
 
@@ -55,7 +55,7 @@ class window.modularity.AjaxLoader
55
55
  # Fire 'loading' event if this is the start of a loading operation.
56
56
  @loader_count++
57
57
  if @loader_count == 1
58
- window.modularity.fire_global_event window.modularity.AjaxLoader.events.AJAX_LOADING
58
+ modularity.fire_global_event modularity.AjaxLoader.events.AJAX_LOADING
59
59
 
60
60
  # Perform the request.
61
61
  jQuery.get url, (data) =>
@@ -73,5 +73,5 @@ class window.modularity.AjaxLoader
73
73
  # Fire 'loaded' event.
74
74
  @loader_count--
75
75
  if @loader_count == 0
76
- window.modularity.fire_global_event window.modularity.AjaxLoader.events.AJAX_LOADED
76
+ modularity.fire_global_event modularity.AjaxLoader.events.AJAX_LOADED
77
77
 
@@ -2,9 +2,11 @@
2
2
 
3
3
  # A generic cache.
4
4
  # Stores key-value pairs.
5
- class window.modularity.Cache
5
+ class modularity.Cache
6
6
 
7
7
  constructor: ->
8
+
9
+ # Container for the cached objects.
8
10
  @cache = {}
9
11
 
10
12
 
@@ -4,7 +4,7 @@
4
4
  # by indexing them on a given key column.
5
5
  class modularity.IndexedCache
6
6
 
7
- constructor: (@key) ->
7
+ constructor: (@key = 'id') ->
8
8
  @cache = new modularity.Cache
9
9
 
10
10
 
@@ -21,7 +21,7 @@ class modularity.IndexedCache
21
21
 
22
22
 
23
23
  remove_many: (entries) ->
24
- @cache.remove_many entries
24
+ @cache.remove_many (entry[@key] for entry in entries)
25
25
 
26
26
 
27
27
  get: (key) ->
@@ -8,10 +8,10 @@ class modularity.PersistenceManager
8
8
  constructor: (params) ->
9
9
 
10
10
  # Copy of the data as it is on the server.
11
- @server_data = new modularity.IndexedCache 'id'
11
+ @server_data = new modularity.IndexedCache
12
12
 
13
13
  # Copy of the data as it is on the client.
14
- @client_data = new modularity.IndexedCache 'id'
14
+ @client_data = new modularity.IndexedCache
15
15
 
16
16
  # The base url on the server. Expected to be a fully RESTful API.
17
17
  @base_url = params.url
@@ -43,6 +43,7 @@ class modularity.PersistenceManager
43
43
  callback server_obj
44
44
 
45
45
 
46
+ # Deletes the given object from the server.
46
47
  delete: (obj, callback) ->
47
48
  @client_data.remove obj
48
49
  @server_data.remove obj
@@ -53,9 +54,10 @@ class modularity.PersistenceManager
53
54
  callback() if callback?
54
55
 
55
56
 
57
+ # Deletes the given objects from the server.
56
58
  delete_many: (objects, callback) ->
57
- @client_data.remove_many obj
58
- @server_data.remove_many obj
59
+ @client_data.remove_many objects
60
+ @server_data.remove_many objects
59
61
  jQuery.ajax
60
62
  url: @base_url
61
63
  type: 'DELETE'
@@ -1,21 +1,16 @@
1
1
  # This mixin adds a 'clickable' aspect to modules.
2
2
  # This means clicking anywhere on the module fires the 'clicked' event.
3
- window.modularity.clickable =
3
+ modularity.clickable =
4
4
 
5
5
  constructor: ->
6
6
  @container.click @container_clicked
7
7
 
8
8
 
9
- # Events that are fired by this mixin.
10
- events:
11
- clicked: 'clicked'
12
-
13
-
14
9
  # Programmatically click this clickable element.
15
10
  # For testing and scripting.
16
11
  click: -> @container.click()
17
12
 
18
13
 
19
14
  # Event handler for clicks on this clickable element.
20
- container_clicked: -> @fire_event modularity.clickable.events.clicked
15
+ container_clicked: -> @fire 'clicked'
21
16
 
@@ -1,21 +1,16 @@
1
- window.modularity.closable =
1
+ modularity.closable =
2
2
 
3
3
  constructor: (container) ->
4
4
  close_button = @container.find('.CloseButton')
5
5
  unless close_button?.length > 0
6
- window.alert 'Error: Close button not found'
6
+ alert 'Error: Close button not found'
7
7
  close_button.click => @close_button_clicked()
8
8
 
9
9
 
10
- # The events that can be fired by closable objects.
11
- events:
12
- closed: 'closed'
13
-
14
-
15
10
  # Called when the button got clicked by the user or programmatically.
16
11
  close_button_clicked: ->
17
12
  if @closable_closing
18
13
  return unless @closable_closing()
19
- @fire_event 'closed'
14
+ @fire 'closed'
20
15
  @container.remove()
21
16
  @closable_closed() if @closable_closed
@@ -8,7 +8,7 @@
8
8
  # and https://github.com/kevgo/modularity-rails for Rails integration.
9
9
 
10
10
 
11
- window.modularity = {
11
+ @modularity = {
12
12
 
13
13
  # Checks whether the given condition is true.
14
14
  # Shows an alert with the given message if not.
@@ -37,11 +37,11 @@ window.modularity = {
37
37
  # Returns the DOM object that is used to fire global events on.
38
38
  global_event_container: -> modularity.global_event_container_cache or= $(window)
39
39
  }
40
- window.modularity.bindGlobalEvent = window.modularity.bind_global_event
41
- window.modularity.fireGlobalEvent = window.modularity.fire_global_event
40
+ @modularity.bindGlobalEvent = @modularity.bind_global_event
41
+ @modularity.fireGlobalEvent = @modularity.fire_global_event
42
42
 
43
43
 
44
- class window.modularity.Module
44
+ class @modularity.Module
45
45
 
46
46
  # The container variable is required. Provide 'testing' in tests.
47
47
  constructor: (container) ->
@@ -81,6 +81,7 @@ class window.modularity.Module
81
81
  return alert "Module.bind_event: parameter 'callback' must be a function, #{callback} (#{typeof callback}) given." unless typeof callback == 'function'
82
82
  @container.bind event_type, callback
83
83
  bindEvent: Module::bind_event
84
+ on: Module::bind_event
84
85
 
85
86
  # Fires the given local event with the given data payload.
86
87
  fire_event: (event_type, data) =>
@@ -88,6 +89,7 @@ class window.modularity.Module
88
89
  return alert("Module.fire_event: Event type must be a string, #{event_type} (#{typeof event_type}) given.") unless typeof event_type == 'string'
89
90
  @container.trigger event_type, data ?= {}
90
91
  fireEvent: Module::fire_event
92
+ fire: Module::fire_event
91
93
 
92
94
 
93
95
  # Hides this module.
@@ -106,25 +108,3 @@ class window.modularity.Module
106
108
  # Shows this module.
107
109
  show: ->
108
110
  @container.show()
109
-
110
-
111
- # jQuery integration for creating Modules.
112
- #
113
- # Call like this: myModule = $('...').module(MyModuleClass)
114
- #
115
- # Parameters:
116
- # * klass: the class of the Module to instantiate
117
- # * any additional parameters are forwarded to the Module constructor.
118
- # Returns the created module instance.
119
- #
120
- # Messages errors in alert boxes.
121
- #
122
- jQuery.fn.module = (klass, args...) ->
123
-
124
- # Check parameters.
125
- if typeof klass != 'function'
126
- return alert "ERROR!\n\nYou must provide the Module class when calling $.module().\n\nExample: $('...').module(MyModuleClass)\n\nYou provided: #{klass} (#{typeof klass})"
127
-
128
- # Instantiate the class and return the instance.
129
- new klass(this, args...)
130
-
@@ -1,5 +1,5 @@
1
1
  # Autogrowing textarea.
2
- class window.modularity.AutogrowTextArea extends modularity.Module
2
+ class modularity.AutogrowTextArea extends modularity.Module
3
3
 
4
4
  constructor: (container) ->
5
5
  super
@@ -3,6 +3,6 @@
3
3
  # A button module.
4
4
  # Responds to clicks on the container element.
5
5
  # The container element is expected to already be populated.
6
- class window.modularity.Button extends window.modularity.Module
7
- @mixin window.modularity.clickable
6
+ class modularity.Button extends modularity.Module
7
+ @mixin modularity.clickable
8
8
 
@@ -1,5 +1,5 @@
1
1
  # Returns a copy of the given array with duplicates removed.
2
- window.modularity.array_unique = (array) ->
2
+ modularity.array_unique = (array) ->
3
3
  output = {}
4
4
  output[array[i]] = array[i] for i in [0...array.length]
5
5
  value for key, value of output
@@ -1,6 +1,5 @@
1
1
  require 'capybara/poltergeist'
2
2
  Konacha.configure do |config|
3
- config.spec_dir = 'spec/javascripts'
4
3
  config.driver = :poltergeist
5
4
  end if defined?(Konacha)
6
5
 
@@ -1,3 +1,3 @@
1
1
  module ModularityRails
2
- VERSION = '0.16.0'
2
+ VERSION = '0.17.0'
3
3
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: modularity-rails
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.16.0
5
+ version: 0.17.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kevin Goslar
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-05 00:00:00.000000000 Z
12
+ date: 2013-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  prerelease: false