emerson 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Emerson
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -1,4 +1,4 @@
1
- // Emerson.js 0.0.5
1
+ // Emerson.js 0.0.6
2
2
  //
3
3
  // (c) 2012 Corey Innis
4
4
  // Emerson may be freely distributed under the MIT license.
@@ -21,7 +21,7 @@
21
21
  }
22
22
 
23
23
  // Current version of the library. Keep in sync with `package.json`.
24
- Emerson.VERSION = '0.0.5';
24
+ Emerson.VERSION = '0.0.6';
25
25
 
26
26
  // Reference the base lib (one of jQuery, Zepto or Ender) as $.
27
27
  var $ = Emerson.base = (root.jQuery || root.Zepto || root.ender);
@@ -34,19 +34,44 @@
34
34
  // 1. fire "sink:before" with the sink as the target.
35
35
  // 2. replace the sink with a "prepared" replacement.
36
36
  // 3. fire "sink:after" with the replacement as the target.
37
- $.fn.sink = function() {
37
+ //
38
+ // Note that, while this method will handle multiple sinks, it does so by
39
+ // cloning the source, thereby breaking the chain. It's probably a good idea
40
+ // to have one-to-one matches, but the multiple match option could be good
41
+ // for doing something along the lines of updating an avatar that is rendered
42
+ // many times on the page. The `sink:after` event may be used to manipulate
43
+ // the resultant nodes.
44
+ //
45
+ // Pass an `override` argument to target a specific sink, say:
46
+ //
47
+ // data-sink="modal"
48
+ $.fn.sink = function(override) {
38
49
  _.each(this, function(e) {
39
50
  var elem = $(e);
40
- var key = elem.data('sink');
51
+ var key = override || elem.data('sink');
52
+ var selector, matches;
41
53
 
42
54
  if(key) {
43
- $('[data-sink="' + key + '"]').each(function() {
44
- $(this)
45
- .trigger('sink:before')
46
- .replaceWith(prepare(elem));
47
- });
48
-
49
- $('[data-sink="' + key + '"]').trigger('sink:after');
55
+ selector = '[data-sink="' + key + '"]';
56
+ matches = $(selector);
57
+
58
+ if(matches.length > 1) {
59
+ matches.each(function() {
60
+ var replacement = prepare(elem.clone(true));
61
+
62
+ $(this)
63
+ .trigger('sink:before')
64
+ .replaceWith(replacement);
65
+
66
+ replacement.trigger('sink:after');
67
+ });
68
+ }
69
+ else {
70
+ matches.trigger('sink:before');
71
+ prepare(elem)
72
+ .replaceAll(matches)
73
+ .trigger('sink:after');
74
+ }
50
75
  }
51
76
  });
52
77
 
@@ -60,7 +85,7 @@
60
85
  // ### prepare
61
86
  // Clone the replacement source and, if Emerson.view is defined, apply that.
62
87
  function prepare(source) {
63
- var result = source.clone();
88
+ var result = source;
64
89
 
65
90
  if(Emerson.view) {
66
91
  result.view();
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emerson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: