├── .gitignore ├── package.js ├── .versions ├── README.md ├── lib.js └── versions.json /.gitignore: -------------------------------------------------------------------------------- 1 | .build* 2 | -------------------------------------------------------------------------------- /package.js: -------------------------------------------------------------------------------- 1 | Package.describe({ 2 | name: "gwendall:body-events", 3 | summary: "Get Template.body.events() working", 4 | version: "0.1.7", 5 | git: "https://github.com/gwendall/meteor-body-events" 6 | }); 7 | 8 | Package.on_use(function(api, where) { 9 | api.use(["templating@1.0.7", "jquery@1.0.0"], "client"); 10 | api.add_files(["lib.js"], "client"); 11 | }); 12 | -------------------------------------------------------------------------------- /.versions: -------------------------------------------------------------------------------- 1 | base64@1.0.2 2 | blaze@2.0.4 3 | blaze-tools@1.0.2 4 | deps@1.0.6 5 | ejson@1.0.5 6 | geojson-utils@1.0.2 7 | gwendall:body-events@0.1.5 8 | html-tools@1.0.3 9 | htmljs@1.0.3 10 | id-map@1.0.2 11 | jquery@1.11.3 12 | json@1.0.2 13 | meteor@1.1.4 14 | minifiers@1.1.3 15 | minimongo@1.0.6 16 | observe-sequence@1.0.4 17 | ordered-dict@1.0.2 18 | random@1.0.2 19 | reactive-var@1.0.4 20 | spacebars-compiler@1.0.4 21 | templating@1.0.11 22 | tracker@1.0.5 23 | underscore@1.0.2 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ```diff 2 | - NOTE: This package is not maintained anymore. 3 | - If you want to help, please reach out to gwendall.esnault@gmail.com 4 | ``` 5 | 6 | Meteor Body Events 7 | =================== 8 | 9 | Template.body.events working 10 | 11 | Installation 12 | ------------ 13 | 14 | ``` sh 15 | meteor add gwendall:body-events 16 | ``` 17 | 18 | Methods 19 | ------- 20 | 21 | 22 | ``` javascript 23 | Template.body.events({ 24 | "click .btn": function(e, data, tpl) { 25 | // e -> jquery event 26 | // data -> Blaze data context of the DOM element triggering the event handler 27 | // tpl -> the parent template instance for the target element 28 | } 29 | }) 30 | ``` 31 | -------------------------------------------------------------------------------- /lib.js: -------------------------------------------------------------------------------- 1 | Template.body.events = function(events) { 2 | for (var eventMap in events) { 3 | (function(events, eventMap) { 4 | var handler = events[eventMap]; 5 | var maps = eventMap.split(","); 6 | maps.forEach(function(map) { 7 | map = $.trim(map); 8 | var split = map.split(" "); 9 | var event = split[0]; 10 | if (split.length === 1) { 11 | $(document).on(event, function(e) { 12 | var data = {}; 13 | handler.apply(this, [e, data]); 14 | }); 15 | } else { 16 | var selector = split.slice(1).join(" "); 17 | $(document).delegate(selector, event, function(e) { 18 | var el = $(e.currentTarget).get(0); 19 | var data = Blaze.getData(el); 20 | var tpl = (Blaze.getView(el) 21 | && _findThisTemplate(Blaze.getView(el), "_templateInstance")) 22 | || {}; 23 | handler.apply(this, [e, data, tpl]); 24 | }); 25 | } 26 | }); 27 | })(events, eventMap); 28 | } 29 | } 30 | 31 | function _findThisTemplate(view) { 32 | let currentView = view; 33 | 34 | // If this view is a template instance return it 35 | do { 36 | if(currentView._templateInstance) return currentView._templateInstance; 37 | 38 | // if not walk up the parents as long as: 39 | // - current view does not start new lexical scope 40 | // - and parent view's child does not start new lexical scope 41 | } while(! (currentView.__startsNewLexicalScope && 42 | ! (currentView.parentView && 43 | currentView.parentView.__childDoesntStartNewLexicalScope)) 44 | && (currentView = currentView.parentView)); 45 | 46 | return undefined; 47 | } 48 | -------------------------------------------------------------------------------- /versions.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": [ 3 | [ 4 | "application-configuration", 5 | "1.0.3" 6 | ], 7 | [ 8 | "base64", 9 | "1.0.1" 10 | ], 11 | [ 12 | "binary-heap", 13 | "1.0.1" 14 | ], 15 | [ 16 | "blaze", 17 | "2.0.3" 18 | ], 19 | [ 20 | "blaze-tools", 21 | "1.0.1" 22 | ], 23 | [ 24 | "boilerplate-generator", 25 | "1.0.1" 26 | ], 27 | [ 28 | "callback-hook", 29 | "1.0.1" 30 | ], 31 | [ 32 | "check", 33 | "1.0.2" 34 | ], 35 | [ 36 | "ddp", 37 | "1.0.12" 38 | ], 39 | [ 40 | "deps", 41 | "1.0.5" 42 | ], 43 | [ 44 | "ejson", 45 | "1.0.4" 46 | ], 47 | [ 48 | "follower-livedata", 49 | "1.0.2" 50 | ], 51 | [ 52 | "geojson-utils", 53 | "1.0.1" 54 | ], 55 | [ 56 | "html-tools", 57 | "1.0.2" 58 | ], 59 | [ 60 | "htmljs", 61 | "1.0.2" 62 | ], 63 | [ 64 | "id-map", 65 | "1.0.1" 66 | ], 67 | [ 68 | "jquery", 69 | "1.0.1" 70 | ], 71 | [ 72 | "json", 73 | "1.0.1" 74 | ], 75 | [ 76 | "logging", 77 | "1.0.5" 78 | ], 79 | [ 80 | "meteor", 81 | "1.1.3" 82 | ], 83 | [ 84 | "minifiers", 85 | "1.1.2" 86 | ], 87 | [ 88 | "minimongo", 89 | "1.0.5" 90 | ], 91 | [ 92 | "mongo", 93 | "1.0.9" 94 | ], 95 | [ 96 | "mrt:underscore-string-latest", 97 | "2.3.3" 98 | ], 99 | [ 100 | "observe-sequence", 101 | "1.0.3" 102 | ], 103 | [ 104 | "ordered-dict", 105 | "1.0.1" 106 | ], 107 | [ 108 | "random", 109 | "1.0.1" 110 | ], 111 | [ 112 | "reactive-var", 113 | "1.0.3" 114 | ], 115 | [ 116 | "retry", 117 | "1.0.1" 118 | ], 119 | [ 120 | "routepolicy", 121 | "1.0.2" 122 | ], 123 | [ 124 | "spacebars", 125 | "1.0.3" 126 | ], 127 | [ 128 | "spacebars-compiler", 129 | "1.0.3" 130 | ], 131 | [ 132 | "templating", 133 | "1.0.9" 134 | ], 135 | [ 136 | "tracker", 137 | "1.0.3" 138 | ], 139 | [ 140 | "ui", 141 | "1.0.4" 142 | ], 143 | [ 144 | "underscore", 145 | "1.0.1" 146 | ], 147 | [ 148 | "webapp", 149 | "1.1.4" 150 | ], 151 | [ 152 | "webapp-hashing", 153 | "1.0.1" 154 | ] 155 | ], 156 | "pluginDependencies": [], 157 | "toolVersion": "meteor-tool@1.0.36", 158 | "format": "1.0" 159 | } --------------------------------------------------------------------------------