turbolinks-form 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d71f9d88ffc2e745e92ddc03bac798ef0d1e36c2
4
- data.tar.gz: e7ba11e51ec43b66a3737f7a229a559e5c58dc1c
3
+ metadata.gz: 52573b444f45c643fa5c07f5417797187a6ab82e
4
+ data.tar.gz: f96d90ec82e0bc716ae164c214f3c64aac6e59ba
5
5
  SHA512:
6
- metadata.gz: 44686ec2b5e7f2c004128f536e640a9a012e6d1d665949cbfe1f085bfb284d0dd5d99994b66d71783f4b63d111f72bbfec5544a91fd930afedd80a3b21ca17f1
7
- data.tar.gz: f62d2619e59a503fdd3a8d1384b3694e8692077544ee6615b36517cb96a9793e20986fa1d5a0ae30e49086b9a71d94dd06c7afa5bf2bb98b2a02db6911c87b10
6
+ metadata.gz: 429669dc0d8ca92b5d07c9f8c79c1354d8ecd6e7bafdfb2e8941f50f663105a4184336be258d8d10555db8510409a8c6928ac9410a6981052703a169d931a73f
7
+ data.tar.gz: 2ae049a398de0f7a27443e718dff94c8e3f97c9bca31bac6a0dc59b65198e44b0a4778f204e1c7ec861540f5624f55326bab04248216f94d8c16cea83d8e43db
@@ -40,6 +40,20 @@ $(function() {
40
40
  // dispatches turbolinks event
41
41
  Turbolinks.dispatch('turbolinks:before-render', {data: {newBody: newDom.body}});
42
42
 
43
+ // console.log('before-render')
44
+
45
+ // Removes/saves all script tags contents.
46
+ // Most browsers don't run the new <script> tags when we replace the page body,
47
+ // but some do (like PhantomJS). So we clear all script tags to ensure nothing
48
+ // will run on any browser.
49
+ var newBodyScripts = newDom.body.getElementsByTagName('script');
50
+ var newBodyScriptContents = [];
51
+ for (var i=0; i<newBodyScripts.length; i++) {
52
+ var script = newBodyScripts[i];
53
+ newBodyScriptContents.push(script.text);
54
+ script.text = "";
55
+ }
56
+
43
57
  // if there is no target, replaces whole body
44
58
  var target;
45
59
  if (!response.getResponseHeader('turbolinks-form-render-target')) {
@@ -58,14 +72,15 @@ $(function() {
58
72
  // dispatches turbolinks event
59
73
  Turbolinks.dispatch('turbolinks:render');
60
74
 
61
- // get all script tags, and replace them by a new version with the same
62
- // content. This makes them run.
63
- var bodyScriptTags = target.getElementsByTagName('script');
64
- for (var i=0; i<bodyScriptTags.length; i++) {
75
+ // console.log('render')
76
+
77
+ // Add scripts to body, so they are run on any browser
78
+ var bodyScripts = target.getElementsByTagName('script');
79
+ for (var i=0; i<bodyScripts.length; i++) {
80
+ var script = bodyScripts[i];
65
81
  var newScript = document.createElement("script");
66
- var oldScript = bodyScriptTags[i];
67
- newScript.text = oldScript.text;
68
- oldScript.parentNode.replaceChild(newScript, oldScript);
82
+ newScript.text = newBodyScriptContents[i];
83
+ script.parentNode.replaceChild(newScript, script);
69
84
  }
70
85
 
71
86
  Turbolinks.dispatch("turbolinks:load");
@@ -1,5 +1,5 @@
1
1
  module Turbolinks
2
2
  module Form
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbolinks-form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique Gubert