turbomorph 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d182a1950ed954881d6b7cebe1ee1e1c8f2ad64c
4
+ data.tar.gz: 48bfe7f73fae95d89532f91ff5333ceda8d92c40
5
+ SHA512:
6
+ metadata.gz: 2c1bb17561c1189153e7164f2a37a543e9ade790bc5868954a56a683be44cd0a27bcf627592671a256c0e561905f0278faba113b62a1fee8dde2634acafb270a
7
+ data.tar.gz: f4e7d4d599de291cdf5de07f2194a1886033365bff850b5461c5de4dc8ecb9ee452461977bd7b2d4453edc967c511f148db7021bae3cf5ee8129a33be6f7db4e
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Matthew Spence
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.morphdom=e()}}(function(){function e(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return!0}function t(e){!u&&document.createRange&&(u=document.createRange(),u.selectNode(document.body));var t;return u&&u.createContextualFragment?t=u.createContextualFragment(e):(t=document.createElement("body"),t.innerHTML=e),t.childNodes[0]}function n(){}function r(e,t){var n,r,o,i,d=t.attributes,a={};for(n=d.length-1;n>=0;n--)r=d[n],r.specified!==!1&&(o=r.name,i=r.value,a[o]=!0,e.getAttribute(o)!==i&&e.setAttribute(o,i));for(d=e.attributes,n=d.length-1;n>=0;n--)r=d[n],r.specified!==!1&&(o=r.name,a.hasOwnProperty(o)||e.removeAttribute(o))}function o(e,t){for(var n=e.firstChild;n;){var r=n.nextSibling;t.appendChild(n),n=r}return t}function i(e){return e.id}function d(d,a,l){function u(e,t){var n=m(e);if(n?p[n]=e:t||g(e),1===e.nodeType)for(var r=e.firstChild;r;)u(r,t||n),r=r.nextSibling}function f(e){if(1===e.nodeType)for(var t=e.firstChild;t;)m(t)||(g(t),f(t)),t=t.nextSibling}function c(e,t,n){N(e)!==!1&&(t.removeChild(e),n?m(e)||(g(e),f(e)):u(e))}function h(e,t,n,o){var i=m(t);if(i&&delete p[i],!o){if(y(e,t)===!1)return;if(r(e,t),b(e,t)===!1)return}if("TEXTAREA"!=e.tagName){var d,a,l,u,f,g=t.firstChild,N=e.firstChild;e:for(;g;){for(l=g.nextSibling,d=m(g);N;){var C=m(N);if(a=N.nextSibling,!n&&C&&(f=v[C]))f.parentNode.replaceChild(N,f),h(N,f,n),N=a;else{var A=N.nodeType;if(A===g.nodeType){var S=!1;if(1===A?(N.tagName===g.tagName&&(C||d?d===C&&(S=!0):S=!0),S&&h(N,g,n)):3===A&&(S=!0,N.nodeValue=g.nodeValue),S){g=l,N=a;continue e}}c(N,e,n),N=a}}d&&((u=p[d])?(h(u,g,!0),g=u):v[d]=g),e.appendChild(g),1===g.nodeType&&(d||g.firstChild)&&T.push(g),g=l,N=a}for(;N;)a=N.nextSibling,c(N,e,n),N=a}var x=s[e.tagName];x&&x(e,t)}l||(l={}),"string"==typeof a&&(a=t(a));var p={},v={},m=l.getNodeKey||i,g=l.onNodeDiscarded||n,y=l.onBeforeMorphEl||n,b=l.onBeforeMorphElChildren||n,N=l.onBeforeNodeDiscarded||n,C=l.childrenOnly===!0,T=[],A=d,S=A.nodeType,x=a.nodeType;if(!C)if(1===S)1===x?d.tagName!==a.tagName&&(g(d),A=o(d,document.createElement(a.tagName))):A=a;else if(3===S){if(3===x)return A.nodeValue=a.nodeValue,A;A=a}if(A===a)g(d);else{h(A,a,!1,C);var E=function(t){for(var n=t.firstChild;n;){var r=n.nextSibling,o=m(n);if(o){var i=p[o];if(i&&n.tagName===i.tagName){if(n.parentNode.replaceChild(i,n),h(i,n,!0),n=r,e(p))return!1;continue}}1===n.nodeType&&E(n),n=r}};if(!e(p))e:for(;T.length;){var w=T;T=[];for(var k=0;k<w.length;k++)if(E(w[k])===!1)break e}for(var O in p)if(p.hasOwnProperty(O)){var P=p[O];g(P),f(P)}}return!C&&A!==d&&d.parentNode&&d.parentNode.replaceChild(A,d),A}var a,l;a={exports:l={}};var u,f,c="undefined"!=typeof document?document.body||document.createElement("div"):{};f=c.hasAttribute?function(e,t){return e.hasAttribute(t)}:function(e,t){return e.getAttributeNode(t)};var s={OPTION:function(e,t){(e.selected=t.selected)?e.setAttribute("selected",""):e.removeAttribute("selected","")},INPUT:function(e,t){e.checked=t.checked,e.value!=t.value&&(e.value=t.value),f(t,"checked")||e.removeAttribute("checked"),f(t,"value")||e.removeAttribute("value")},TEXTAREA:function(e,t){var n=t.value;e.value!=n&&(e.value=n),e.firstChild&&(e.firstChild.nodeValue=n)}};return a.exports=d,a.exports}),function(){var e,t,n;Turbolinks.controller.view.renderSnapshot=function(t,r){var o,i,d,a,l,u,f,c,s,h,p,v;if(o=this.getSnapshot({clone:!1}),!o.hasSameTrackedHeadElementsAsSnapshot(t))return this.delegate.viewInvalidated(),!1;for(h=t.getInlineHeadElementsNotPresentInSnapshot(o),d=0,u=h.length;u>d;d++)i=h[d],document.head.appendChild(i.cloneNode(!0));for(p=o.getTemporaryHeadElements(),a=0,f=p.length;f>a;a++)i=p[a],document.head.removeChild(i);for(v=t.getTemporaryHeadElements(),l=0,c=v.length;c>l;l++)i=v[l],document.head.appendChild(i.cloneNode(!0));return s=t.body.cloneNode(!0),this.delegate.viewWillRender(s),n(s),morphdom(document.body,s),e(),"function"==typeof r&&r(),this.delegate.viewRendered()},n=function(e){var n,r,o,i,d,a;for(d=t(document.body),a=[],n=0,r=d.length;r>n;n++)o=d[n],(i=e.querySelector("[id='"+o.id+"']"))?a.push(i.parentNode.replaceChild(o,i)):a.push(void 0);return a},t=function(e){return e.querySelectorAll("[id][data-turbolinks-permanent]")},e=function(){var e;return null!=(e=document.body.querySelector("[autofocus]"))?e.focus():void 0}}.call(this);
@@ -0,0 +1,3 @@
1
+ module Turbomorph
2
+ VERSION = '0.1.0'
3
+ end
data/lib/turbomorph.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'turbomorph/version'
2
+
3
+ module Turbomorph
4
+
5
+ def self.asset_path
6
+ File.expand_path("../../assets/javascripts", __FILE__)
7
+ end
8
+
9
+ class Engine < ::Rails::Engine
10
+ config.assets.paths += [Turbomorph.asset_path]
11
+ end
12
+
13
+ end
@@ -0,0 +1,45 @@
1
+ #= require morphdom/dist/morphdom-umd
2
+
3
+ Turbolinks.controller.view.renderSnapshot = (newSnapshot, callback) ->
4
+ currentSnapshot = @getSnapshot({ clone: false })
5
+
6
+ unless currentSnapshot.hasSameTrackedHeadElementsAsSnapshot(newSnapshot)
7
+ @delegate.viewInvalidated()
8
+ return false
9
+
10
+ for element in newSnapshot.getInlineHeadElementsNotPresentInSnapshot(currentSnapshot)
11
+ document.head.appendChild(element.cloneNode(true))
12
+
13
+ for element in currentSnapshot.getTemporaryHeadElements()
14
+ document.head.removeChild(element)
15
+
16
+ for element in newSnapshot.getTemporaryHeadElements()
17
+ document.head.appendChild(element.cloneNode(true))
18
+
19
+ newBody = newSnapshot.body.cloneNode(true)
20
+ @delegate.viewWillRender(newBody)
21
+
22
+ importPermanentElementsIntoBody(newBody)
23
+
24
+ morphdom(document.body, newBody)
25
+
26
+ focusFirstAutofocusableElement()
27
+ callback?()
28
+ @delegate.viewRendered()
29
+
30
+ importPermanentElementsIntoBody = (newBody) ->
31
+ for newChild in getPermanentElements(document.body)
32
+ if oldChild = newBody.querySelector("[id='#{newChild.id}']")
33
+ oldChild.parentNode.replaceChild(newChild, oldChild)
34
+
35
+ getPermanentElements = (element) ->
36
+ element.querySelectorAll("[id][data-turbolinks-permanent]")
37
+
38
+
39
+ focusFirstAutofocusableElement = ->
40
+ document.body.querySelector("[autofocus]")?.focus()
41
+ #
42
+ # do ->
43
+ # Turbolinks.controller = controller = new Turbolinks.Controller
44
+ # controller.adapter = new Turbolinks.BrowserAdapter(controller)
45
+ # controller.start()
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: turbomorph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Spence
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: turbolinks
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.0.beta.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.0.beta.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: coffee-script
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sprockets
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: uglifier
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Monkey patches turbolinks to morph your dom between two different pages
70
+ rather than just subbing out the body.
71
+ email: msaspence@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - LICENSE
77
+ - lib/assets/javascripts/turbomorph.js
78
+ - lib/turbomorph.rb
79
+ - lib/turbomorph/version.rb
80
+ - src/turbomorph/index.coffee
81
+ homepage: https://github.com/msaspence/turbomorph#readme
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.4.5.1
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Turbo Morph brings dommorph to turbolinks
105
+ test_files: []