elementaljs-rails 0.0.4 → 0.0.5

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.
@@ -1,5 +1,5 @@
1
1
  module Elementaljs
2
2
  module Rails
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -1,43 +1,45 @@
1
- (function(){
1
+ (function(ns) {
2
2
 
3
- var root = this;
4
- var Elemental;
5
- if (typeof exports !== 'undefined') {
6
- Elemental = exports;
7
- } else {
8
- Elemental = root.Elemental = {};
9
- }
3
+ var namespaces = [this];
10
4
 
11
- var namespaces = [root];
5
+ var attachBehavior = function($element, behavior) {
6
+ var fn = namespaces;
12
7
 
13
- Elemental.load = function(element){
14
- var container = $(element);
15
- container.find("*").andSelf().filter("[data-behavior]").each(function(index, element){
16
- var that = $(element);
17
- var behaviors = that.attr('data-behavior');
18
- _.each(behaviors.split(" "), function(behavior){
19
- var namespaced = behavior.split(".");
20
-
21
- var fns = _.map(namespaces, function(namespace){
22
- return _.reduce(namespaced, function(prev, next){
23
- return prev !== undefined ? prev[next] : undefined;
24
- }, namespace);
25
- });
8
+ behavior.replace(/([^.]+)/g, function(object) {
9
+ if(fn === namespaces) {
10
+ for(var nextFn, index = 0; index < fn.length; ++index) {
11
+ nextFn = fn[index][object];
12
+ if(nextFn) {
13
+ fn = nextFn;
14
+ break;
15
+ }
16
+ }
17
+ } else if(typeof fn === 'object') {
18
+ fn = fn[object];
19
+ }
20
+ });
26
21
 
27
- var fn = _.find(fns, function(fn){
28
- return undefined !== fn;
29
- });
22
+ if(typeof fn === 'function') {
23
+ return fn($element);
24
+ } else {
25
+ if (window.console && console.warn) {
26
+ console.warn("elementalJS: Unable to find behavior:", behavior);
27
+ }
28
+ }
29
+ };
30
30
 
31
- if (undefined !== fn) {
32
- fn(that);
33
- }
31
+ ns.load = function(container) {
32
+ $(container).find("*").andSelf().filter("[data-behavior]").each(function(index, element) {
33
+ var $element = $(element);
34
+ var behaviors = $element.data('behavior');
35
+ behaviors.replace(/([^ ]+)/g, function(behavior) {
36
+ attachBehavior($element, behavior);
34
37
  });
35
38
  });
36
39
  };
37
40
 
38
- Elemental.addNamespace = function(namespace){
41
+ ns.addNamespace = function(namespace) {
39
42
  namespaces.push(namespace);
40
43
  };
41
44
 
42
- })();
43
-
45
+ })(window.Elemental = {});
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elementaljs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-18 00:00:00.000000000 Z
12
+ date: 2013-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jquery-rails
@@ -73,7 +73,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
73
  version: '0'
74
74
  segments:
75
75
  - 0
76
- hash: 501618456386788448
76
+ hash: -2270599889799533641
77
77
  required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  none: false
79
79
  requirements:
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  version: '0'
83
83
  segments:
84
84
  - 0
85
- hash: 501618456386788448
85
+ hash: -2270599889799533641
86
86
  requirements: []
87
87
  rubyforge_project:
88
88
  rubygems_version: 1.8.25