twine-rails 1.0.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/assets/javascripts/twine.coffee +47 -19
- data/lib/twine-rails/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75172b52a36ebd2de8b177f65b1733c0433eb5e2
|
4
|
+
data.tar.gz: 41c83aac3cb17eed504cb352eab82db8f4babbb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65b2216340071a68ea54fa4bb2e5d5c7e716de7c56655c19428aa2e21e822b0ed56d73558bfb89aa28777c071a453aabe8cd948caba16e8948f2e4a0b7676e2f
|
7
|
+
data.tar.gz: da8b5083d1f4120862638df28199853f2ee4a92b8c8713766c001d98abbb894a3c89ff004921919f41ec767b1548296ab938b9669eeb2e3223770fe1f7cc2540
|
data/README.md
CHANGED
@@ -171,6 +171,7 @@ Where context expects a node and `$0` is shorthand for the current node in the d
|
|
171
171
|
## Releasing
|
172
172
|
|
173
173
|
1. Update version number in `package.json`, `bower.json`, and `lib/twine-rails/version.rb`
|
174
|
-
2. Run `
|
175
|
-
3. Run make .all && make .uglify to update JS
|
174
|
+
2. Run `dev up` to update `Gemfile.lock`
|
175
|
+
3. Run `make .all && make .uglify` to update JS
|
176
176
|
4. Push the new tag to GitHub and the new version to rubygems with `bundle exec rake release`
|
177
|
+
5. Publish the new version to NPM with `npm publish`.
|
@@ -24,6 +24,7 @@
|
|
24
24
|
|
25
25
|
keypathRegex = /^[a-z]\w*(\.[a-z]\w*|\[\d+\])*$/i # Tests if a string is a pure keypath.
|
26
26
|
refreshQueued = false
|
27
|
+
refreshCallbacks = []
|
27
28
|
rootNode = null
|
28
29
|
|
29
30
|
currentBindingCallbacks = null
|
@@ -80,17 +81,14 @@
|
|
80
81
|
|
81
82
|
bindingConstructors ?= []
|
82
83
|
definition = attribute.value
|
83
|
-
|
84
|
-
bindingConstructors.unshift([constructor, definition])
|
85
|
-
else
|
86
|
-
bindingConstructors.push([constructor, definition])
|
84
|
+
bindingConstructors.push([type, constructor, definition])
|
87
85
|
|
88
86
|
if bindingConstructors
|
89
87
|
element ?= findOrCreateElementForNode(node)
|
90
88
|
element.bindings ?= []
|
91
89
|
element.indexes ?= indexes
|
92
90
|
|
93
|
-
for [constructor, definition] in bindingConstructors
|
91
|
+
for [_, constructor, definition] in bindingConstructors.sort(bindingOrder)
|
94
92
|
binding = constructor(node, context, definition, element)
|
95
93
|
element.bindings.push(binding) if binding
|
96
94
|
|
@@ -127,7 +125,9 @@
|
|
127
125
|
elements[node.bindingId] ?= {}
|
128
126
|
|
129
127
|
# Queues a refresh of the DOM, batching up calls for the current synchronous block.
|
130
|
-
|
128
|
+
# The callback will be called once when the refresh has completed.
|
129
|
+
Twine.refresh = (callback) ->
|
130
|
+
refreshCallbacks.push(callback) if callback
|
131
131
|
return if refreshQueued
|
132
132
|
refreshQueued = true
|
133
133
|
setTimeout(Twine.refreshImmediately, 0)
|
@@ -139,6 +139,10 @@
|
|
139
139
|
Twine.refreshImmediately = ->
|
140
140
|
refreshQueued = false
|
141
141
|
refreshElement(element) for key, element of elements
|
142
|
+
|
143
|
+
callbacks = refreshCallbacks
|
144
|
+
refreshCallbacks = []
|
145
|
+
cb() for cb in callbacks
|
142
146
|
return
|
143
147
|
|
144
148
|
Twine.register = (name, component) ->
|
@@ -294,6 +298,17 @@
|
|
294
298
|
event.initCustomEvent('bindings:change', true, false, {})
|
295
299
|
node.dispatchEvent(event)
|
296
300
|
|
301
|
+
bindingOrder = ([firstType], [secondType]) ->
|
302
|
+
ORDERED_BINDINGS = {
|
303
|
+
define: 1,
|
304
|
+
bind: 2,
|
305
|
+
eval: 3
|
306
|
+
}
|
307
|
+
return 1 unless ORDERED_BINDINGS[firstType]
|
308
|
+
return -1 unless ORDERED_BINDINGS[secondType]
|
309
|
+
|
310
|
+
ORDERED_BINDINGS[firstType] - ORDERED_BINDINGS[secondType]
|
311
|
+
|
297
312
|
Twine.bindingTypes =
|
298
313
|
bind: (node, context, definition) ->
|
299
314
|
valueProp = valuePropertyForNode(node)
|
@@ -339,9 +354,9 @@
|
|
339
354
|
return if getValue(context, keypath) == this[valueProp]
|
340
355
|
refreshContext()
|
341
356
|
Twine.refreshImmediately()
|
342
|
-
|
357
|
+
jQuery(node).on 'input keyup change', changeHandler
|
343
358
|
teardown = ->
|
344
|
-
|
359
|
+
jQuery(node).off 'input keyup change', changeHandler
|
345
360
|
|
346
361
|
{refresh, teardown}
|
347
362
|
|
@@ -351,16 +366,29 @@
|
|
351
366
|
return refresh: ->
|
352
367
|
newValue = !fn.call(node, context, rootContext, arrayPointersForNode(node, context))
|
353
368
|
return if newValue == lastValue
|
354
|
-
|
369
|
+
jQuery(node).toggleClass('hide', lastValue = newValue)
|
355
370
|
|
356
371
|
'bind-class': (node, context, definition) ->
|
357
372
|
fn = wrapFunctionString(definition, '$context,$root,$arrayPointers', node)
|
358
|
-
|
373
|
+
lastValues = {}
|
374
|
+
$node = jQuery(node)
|
359
375
|
return refresh: ->
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
376
|
+
newValues = fn.call(node, context, rootContext, arrayPointersForNode(node, context))
|
377
|
+
additions = []
|
378
|
+
removals = []
|
379
|
+
|
380
|
+
for key, value of newValues
|
381
|
+
newValue = newValues[key] = !!newValues[key]
|
382
|
+
currValue = lastValues[key] ? $node.hasClass(key)
|
383
|
+
if currValue != newValue
|
384
|
+
if newValue
|
385
|
+
additions.push(key)
|
386
|
+
else
|
387
|
+
removals.push(key)
|
388
|
+
|
389
|
+
$node.removeClass(removals.join(' ')) if removals.length
|
390
|
+
$node.addClass(additions.join(' ')) if additions.length
|
391
|
+
lastValues = newValues
|
364
392
|
|
365
393
|
'bind-attribute': (node, context, definition) ->
|
366
394
|
fn = wrapFunctionString(definition, '$context,$root,$arrayPointers', node)
|
@@ -368,7 +396,7 @@
|
|
368
396
|
return refresh: ->
|
369
397
|
newValue = fn.call(node, context, rootContext, arrayPointersForNode(node, context))
|
370
398
|
for key, value of newValue when lastValue[key] != value
|
371
|
-
|
399
|
+
jQuery(node).attr(key, value || null)
|
372
400
|
lastValue = newValue
|
373
401
|
|
374
402
|
define: (node, context, definition) ->
|
@@ -398,7 +426,7 @@
|
|
398
426
|
indexes
|
399
427
|
|
400
428
|
setupPropertyBinding = (attributeName, bindingName) ->
|
401
|
-
booleanProp = attributeName in ['checked', 'indeterminate', 'disabled', 'readOnly']
|
429
|
+
booleanProp = attributeName in ['checked', 'indeterminate', 'disabled', 'readOnly', 'draggable']
|
402
430
|
|
403
431
|
Twine.bindingTypes["bind-#{bindingName.toLowerCase()}"] = (node, context, definition) ->
|
404
432
|
fn = wrapFunctionString(definition, '$context,$root,$arrayPointers', node)
|
@@ -411,7 +439,7 @@
|
|
411
439
|
|
412
440
|
fireCustomChangeEvent(node) if attributeName == 'checked'
|
413
441
|
|
414
|
-
for attribute in ['placeholder', 'checked', 'indeterminate', 'disabled', 'href', 'title', 'readOnly', 'src']
|
442
|
+
for attribute in ['placeholder', 'checked', 'indeterminate', 'disabled', 'href', 'title', 'readOnly', 'src', 'draggable']
|
415
443
|
setupPropertyBinding(attribute, attribute)
|
416
444
|
|
417
445
|
setupPropertyBinding('innerHTML', 'unsafe-html')
|
@@ -431,10 +459,10 @@
|
|
431
459
|
|
432
460
|
wrapFunctionString(definition, '$context,$root,$arrayPointers,event,data', node).call(node, context, rootContext, arrayPointersForNode(node, context), event, data)
|
433
461
|
Twine.refreshImmediately()
|
434
|
-
|
462
|
+
jQuery(node).on eventName, onEventHandler
|
435
463
|
|
436
464
|
return teardown: ->
|
437
|
-
|
465
|
+
jQuery(node).off eventName, onEventHandler
|
438
466
|
|
439
467
|
for eventName in ['click', 'dblclick', 'mouseenter', 'mouseleave', 'mouseover', 'mouseout', 'mousedown', 'mouseup',
|
440
468
|
'submit', 'dragenter', 'dragleave', 'dragover', 'drop', 'drag', 'change', 'keypress', 'keydown', 'keyup', 'input',
|
data/lib/twine-rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twine-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Li
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2017-02-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: coffee-rails
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
version: '0'
|
101
101
|
requirements: []
|
102
102
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.
|
103
|
+
rubygems_version: 2.5.1
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
106
|
summary: Minimalistic two-way bindings
|