cable_ready 2.0.4 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.lock +30 -32
- data/README.md +26 -28
- data/lib/cable_ready/channel.rb +6 -5
- data/lib/cable_ready/version.rb +1 -1
- data/vendor/assets/javascripts/cable_ready.js +1 -879
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '030087e1ec806372dc4930474097f291137b71ef3ce476d50f1239f33c3069bd'
|
4
|
+
data.tar.gz: c38745299547284356b325ac88ee2c2d98ba1991b730de6f32a4e60a6d6ed2b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f7bf0c672caff6cf06c76b7419248b0818fd38a9e4e526cf9fd76ef15ed66f59c20ec2b5ac85350043bc50ad5f27ad87104207852d2623dd7586ed841538197
|
7
|
+
data.tar.gz: 37f3bd9207d3fc48c23c8bb680f6d44e5594c3214ff51c1ef28d1abe60ae31cdd84297d34d7ea358f79936aa8f4aadb28f3dfaf8e0988ba3cee18a6a4d282842
|
data/Gemfile.lock
CHANGED
@@ -1,44 +1,43 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cable_ready (2.0.
|
4
|
+
cable_ready (2.0.5)
|
5
5
|
activesupport (>= 5.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (5.1
|
10
|
+
activesupport (5.2.1)
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
-
i18n (
|
12
|
+
i18n (>= 0.7, < 2)
|
13
13
|
minitest (~> 5.1)
|
14
14
|
tzinfo (~> 1.1)
|
15
|
-
binding_of_caller (0.
|
15
|
+
binding_of_caller (0.8.0)
|
16
16
|
debug_inspector (>= 0.0.1)
|
17
|
-
byebug (
|
18
|
-
coderay (1.1.
|
17
|
+
byebug (10.0.2)
|
18
|
+
coderay (1.1.2)
|
19
19
|
concurrent-ruby (1.0.5)
|
20
|
-
coveralls (0.8.
|
20
|
+
coveralls (0.8.22)
|
21
21
|
json (>= 1.8, < 3)
|
22
|
-
simplecov (~> 0.
|
22
|
+
simplecov (~> 0.16.1)
|
23
23
|
term-ansicolor (~> 1.3)
|
24
24
|
thor (~> 0.19.4)
|
25
25
|
tins (~> 1.6)
|
26
26
|
debug_inspector (0.0.3)
|
27
|
-
docile (1.1
|
28
|
-
i18n (
|
27
|
+
docile (1.3.1)
|
28
|
+
i18n (1.1.0)
|
29
29
|
concurrent-ruby (~> 1.0)
|
30
30
|
interception (0.5)
|
31
31
|
json (2.1.0)
|
32
|
-
method_source (0.
|
33
|
-
minitest (5.
|
34
|
-
mustermann (1.0.
|
32
|
+
method_source (0.9.0)
|
33
|
+
minitest (5.11.3)
|
34
|
+
mustermann (1.0.3)
|
35
35
|
os (1.0.0)
|
36
|
-
pry (0.
|
36
|
+
pry (0.11.3)
|
37
37
|
coderay (~> 1.1.0)
|
38
|
-
method_source (~> 0.
|
39
|
-
|
40
|
-
|
41
|
-
byebug (~> 9.0)
|
38
|
+
method_source (~> 0.9.0)
|
39
|
+
pry-byebug (3.6.0)
|
40
|
+
byebug (~> 10.0)
|
42
41
|
pry (~> 0.10)
|
43
42
|
pry-rescue (1.4.5)
|
44
43
|
interception (>= 0.5)
|
@@ -46,34 +45,33 @@ GEM
|
|
46
45
|
pry-stack_explorer (0.4.9.2)
|
47
46
|
binding_of_caller (>= 0.7)
|
48
47
|
pry (>= 0.9.11)
|
49
|
-
pry-test (0.6.
|
48
|
+
pry-test (0.6.5)
|
50
49
|
os
|
51
50
|
pry
|
52
51
|
pry-byebug
|
53
52
|
pry-rescue
|
54
53
|
pry-stack_explorer
|
55
|
-
rack (2.0.
|
56
|
-
rack-protection (2.0.
|
54
|
+
rack (2.0.5)
|
55
|
+
rack-protection (2.0.4)
|
57
56
|
rack
|
58
|
-
rake (
|
59
|
-
simplecov (0.
|
60
|
-
docile (~> 1.1
|
57
|
+
rake (12.3.1)
|
58
|
+
simplecov (0.16.1)
|
59
|
+
docile (~> 1.1)
|
61
60
|
json (>= 1.8, < 3)
|
62
61
|
simplecov-html (~> 0.10.0)
|
63
|
-
simplecov-html (0.10.
|
64
|
-
sinatra (2.0.
|
62
|
+
simplecov-html (0.10.2)
|
63
|
+
sinatra (2.0.4)
|
65
64
|
mustermann (~> 1.0)
|
66
65
|
rack (~> 2.0)
|
67
|
-
rack-protection (= 2.0.
|
66
|
+
rack-protection (= 2.0.4)
|
68
67
|
tilt (~> 2.0)
|
69
|
-
slop (3.6.0)
|
70
68
|
term-ansicolor (1.6.0)
|
71
69
|
tins (~> 1.0)
|
72
70
|
thor (0.19.4)
|
73
71
|
thread_safe (0.3.6)
|
74
|
-
tilt (2.0.
|
75
|
-
tins (1.
|
76
|
-
tzinfo (1.2.
|
72
|
+
tilt (2.0.8)
|
73
|
+
tins (1.16.3)
|
74
|
+
tzinfo (1.2.5)
|
77
75
|
thread_safe (~> 0.1)
|
78
76
|
|
79
77
|
PLATFORMS
|
@@ -87,4 +85,4 @@ DEPENDENCIES
|
|
87
85
|
sinatra
|
88
86
|
|
89
87
|
BUNDLED WITH
|
90
|
-
1.16.
|
88
|
+
1.16.4
|
data/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
[![Lines of Code](http://img.shields.io/badge/lines_of_code-
|
2
|
-
[![Code Status](
|
3
|
-
[![Dependency Status](http://img.shields.io/gemnasium/hopsoft/cable_ready.svg?style=flat)](https://gemnasium.com/hopsoft/cable_ready)
|
1
|
+
[![Lines of Code](http://img.shields.io/badge/lines_of_code-204-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
|
2
|
+
[![Code Status](https://img.shields.io/codeclimate/maintainability/hopsoft/cable_ready.svg?style=flat)](https://codeclimate.com/github/hopsoft/cable_ready)
|
4
3
|
|
5
4
|
# CableReady
|
6
5
|
|
@@ -13,11 +12,15 @@ from the server via [ActionCable](http://guides.rubyonrails.org/action_cable_ove
|
|
13
12
|
|
14
13
|
> Please read the official [ActionCable docs](http://guides.rubyonrails.org/action_cable_overview.html) to learn more about ActionCable before proceeding.
|
15
14
|
|
15
|
+
```ruby
|
16
|
+
# Gemfile
|
17
|
+
gem "cable_ready"
|
18
|
+
```
|
19
|
+
|
16
20
|
```javascript
|
17
|
-
// app/assets/javascripts/
|
18
|
-
|
19
|
-
|
20
|
-
*/
|
21
|
+
// app/assets/javascripts/cable.js
|
22
|
+
//= require action_cable
|
23
|
+
//= require cable_ready
|
21
24
|
```
|
22
25
|
|
23
26
|
```javascript
|
@@ -88,9 +91,10 @@ cable_ready["MyChannel"].dispatch_event(
|
|
88
91
|
|
89
92
|
```ruby
|
90
93
|
cable_ready["MyChannel"].morph(
|
91
|
-
selector:
|
92
|
-
|
93
|
-
|
94
|
+
selector: "string", # required - string containing one or more CSS selectors separated by commas
|
95
|
+
html: "string" # [null] - the HTML to assign
|
96
|
+
children_only: true|false # [null] - indicates if only child nodes should be morphed... skipping the parent element
|
97
|
+
focus_selector: "string", # [null] - string containing one or more CSS selectors separated by commas
|
94
98
|
)
|
95
99
|
```
|
96
100
|
|
@@ -100,9 +104,9 @@ Sets the innerHTML of a DOM element.
|
|
100
104
|
|
101
105
|
```ruby
|
102
106
|
cable_ready["MyChannel"].inner_html(
|
103
|
-
selector:
|
104
|
-
|
105
|
-
html:
|
107
|
+
selector: "string", # required - string containing one or more CSS selectors separated by commas
|
108
|
+
focus_selector: "string", # [null] - string containing one or more CSS selectors separated by commas
|
109
|
+
html: "string" # [null] - the HTML to assign
|
106
110
|
)
|
107
111
|
```
|
108
112
|
|
@@ -124,10 +128,10 @@ Supports behavior akin to prepend & append.
|
|
124
128
|
|
125
129
|
```ruby
|
126
130
|
cable_ready["MyChannel"].insert_adjacent_html(
|
127
|
-
selector:
|
128
|
-
|
129
|
-
position:
|
130
|
-
html:
|
131
|
+
selector: "string", # required - string containing one or more CSS selectors separated by commas
|
132
|
+
focus_selector: "string", # [null] - string containing one or more CSS selectors separated by commas
|
133
|
+
position: "string", # [beforeend] - the relative position to the DOM element (beforebegin, afterbegin, beforeend, afterend)
|
134
|
+
html: "string" # [null] - the HTML to insert
|
131
135
|
)
|
132
136
|
```
|
133
137
|
|
@@ -150,8 +154,8 @@ Removes an element from the DOM.
|
|
150
154
|
|
151
155
|
```ruby
|
152
156
|
cable_ready["MyChannel"].remove(
|
153
|
-
selector:
|
154
|
-
|
157
|
+
selector: "string", # required - string containing one or more CSS selectors separated by commas
|
158
|
+
focus_selector: "string" # [null] - string containing one or more CSS selectors separated by commas
|
155
159
|
)
|
156
160
|
```
|
157
161
|
|
@@ -161,9 +165,9 @@ Replaces a DOM element with new HTML.
|
|
161
165
|
|
162
166
|
```ruby
|
163
167
|
cable_ready["MyChannel"].replace(
|
164
|
-
selector:
|
165
|
-
|
166
|
-
html:
|
168
|
+
selector: "string", # required - string containing one or more CSS selectors separated by commas
|
169
|
+
focus_selector: "string", # [null] - string containing one or more CSS selectors separated by commas
|
170
|
+
html: "string" # [null] - the HTML to use as replacement
|
167
171
|
)
|
168
172
|
```
|
169
173
|
|
@@ -251,9 +255,3 @@ The JavaScript source is located in `vendor/assets/javascripts/cable_ready/src`
|
|
251
255
|
cd vendor/assets/javascripts/cable_ready/src
|
252
256
|
webpack
|
253
257
|
```
|
254
|
-
|
255
|
-
---
|
256
|
-
|
257
|
-
<a target='_blank' rel='nofollow' href='https://app.codesponsor.io/link/QMSjMHrtPhvfmCnk5Hbikhhr/hopsoft/cable_ready'>
|
258
|
-
<img alt='Sponsor' width='888' height='68' src='https://app.codesponsor.io/embed/QMSjMHrtPhvfmCnk5Hbikhhr/hopsoft/cable_ready.svg' />
|
259
|
-
</a>
|
data/lib/cable_ready/channel.rb
CHANGED
@@ -17,13 +17,14 @@ module CableReady
|
|
17
17
|
#
|
18
18
|
# morph: [{
|
19
19
|
# selector: "string",
|
20
|
-
# focusSelector: "string",
|
21
20
|
# html: "string"
|
21
|
+
# children_only: true|false,
|
22
|
+
# focus_selector: "string",
|
22
23
|
# }, ...],
|
23
24
|
#
|
24
25
|
# inner_html: [{
|
25
26
|
# selector: "string",
|
26
|
-
#
|
27
|
+
# focus_selector: "string",
|
27
28
|
# html: "string"
|
28
29
|
# }, ...],
|
29
30
|
#
|
@@ -34,7 +35,7 @@ module CableReady
|
|
34
35
|
#
|
35
36
|
# insert_adjacent_html: [{
|
36
37
|
# selector: "string",
|
37
|
-
#
|
38
|
+
# focus_selector: "string",
|
38
39
|
# position: "string",
|
39
40
|
# html: "string"
|
40
41
|
# }, ...],
|
@@ -47,12 +48,12 @@ module CableReady
|
|
47
48
|
#
|
48
49
|
# remove: [{
|
49
50
|
# selector: "string",
|
50
|
-
#
|
51
|
+
# focus_selector: "string,
|
51
52
|
# }, ...],
|
52
53
|
#
|
53
54
|
# replace: [{
|
54
55
|
# selector: "string",
|
55
|
-
#
|
56
|
+
# focus_selector: "string",
|
56
57
|
# html: "string"
|
57
58
|
# }, ...],
|
58
59
|
#
|
data/lib/cable_ready/version.rb
CHANGED
@@ -1,879 +1 @@
|
|
1
|
-
var CableReady
|
2
|
-
/******/ (function(modules) { // webpackBootstrap
|
3
|
-
/******/ // The module cache
|
4
|
-
/******/ var installedModules = {};
|
5
|
-
/******/
|
6
|
-
/******/ // The require function
|
7
|
-
/******/ function __webpack_require__(moduleId) {
|
8
|
-
/******/
|
9
|
-
/******/ // Check if module is in cache
|
10
|
-
/******/ if(installedModules[moduleId]) {
|
11
|
-
/******/ return installedModules[moduleId].exports;
|
12
|
-
/******/ }
|
13
|
-
/******/ // Create a new module (and put it into the cache)
|
14
|
-
/******/ var module = installedModules[moduleId] = {
|
15
|
-
/******/ i: moduleId,
|
16
|
-
/******/ l: false,
|
17
|
-
/******/ exports: {}
|
18
|
-
/******/ };
|
19
|
-
/******/
|
20
|
-
/******/ // Execute the module function
|
21
|
-
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
22
|
-
/******/
|
23
|
-
/******/ // Flag the module as loaded
|
24
|
-
/******/ module.l = true;
|
25
|
-
/******/
|
26
|
-
/******/ // Return the exports of the module
|
27
|
-
/******/ return module.exports;
|
28
|
-
/******/ }
|
29
|
-
/******/
|
30
|
-
/******/
|
31
|
-
/******/ // expose the modules object (__webpack_modules__)
|
32
|
-
/******/ __webpack_require__.m = modules;
|
33
|
-
/******/
|
34
|
-
/******/ // expose the module cache
|
35
|
-
/******/ __webpack_require__.c = installedModules;
|
36
|
-
/******/
|
37
|
-
/******/ // define getter function for harmony exports
|
38
|
-
/******/ __webpack_require__.d = function(exports, name, getter) {
|
39
|
-
/******/ if(!__webpack_require__.o(exports, name)) {
|
40
|
-
/******/ Object.defineProperty(exports, name, {
|
41
|
-
/******/ configurable: false,
|
42
|
-
/******/ enumerable: true,
|
43
|
-
/******/ get: getter
|
44
|
-
/******/ });
|
45
|
-
/******/ }
|
46
|
-
/******/ };
|
47
|
-
/******/
|
48
|
-
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
49
|
-
/******/ __webpack_require__.n = function(module) {
|
50
|
-
/******/ var getter = module && module.__esModule ?
|
51
|
-
/******/ function getDefault() { return module['default']; } :
|
52
|
-
/******/ function getModuleExports() { return module; };
|
53
|
-
/******/ __webpack_require__.d(getter, 'a', getter);
|
54
|
-
/******/ return getter;
|
55
|
-
/******/ };
|
56
|
-
/******/
|
57
|
-
/******/ // Object.prototype.hasOwnProperty.call
|
58
|
-
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
59
|
-
/******/
|
60
|
-
/******/ // __webpack_public_path__
|
61
|
-
/******/ __webpack_require__.p = "";
|
62
|
-
/******/
|
63
|
-
/******/ // Load entry module and return exports
|
64
|
-
/******/ return __webpack_require__(__webpack_require__.s = 0);
|
65
|
-
/******/ })
|
66
|
-
/************************************************************************/
|
67
|
-
/******/ ([
|
68
|
-
/* 0 */
|
69
|
-
/***/ (function(module, exports, __webpack_require__) {
|
70
|
-
|
71
|
-
"use strict";
|
72
|
-
|
73
|
-
|
74
|
-
Object.defineProperty(exports, "__esModule", {
|
75
|
-
value: true
|
76
|
-
});
|
77
|
-
exports.perform = undefined;
|
78
|
-
|
79
|
-
var _morphdom = __webpack_require__(1);
|
80
|
-
|
81
|
-
var _morphdom2 = _interopRequireDefault(_morphdom);
|
82
|
-
|
83
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
84
|
-
|
85
|
-
var DOMOperations = {
|
86
|
-
// DOM Events ..............................................................................................
|
87
|
-
|
88
|
-
dispatchEvent: function dispatchEvent(config) {
|
89
|
-
var target = document.querySelector(config.selector) || window;
|
90
|
-
var event = new Event(config.name);
|
91
|
-
event.detail = config.detail;
|
92
|
-
target.dispatchEvent(event);
|
93
|
-
},
|
94
|
-
|
95
|
-
// Element Mutations .......................................................................................
|
96
|
-
|
97
|
-
morph: function morph(config) {
|
98
|
-
(0, _morphdom2.default)(document.querySelector(config.selector), config.html);
|
99
|
-
if (config.focusSelector) {
|
100
|
-
document.querySelector(config.focusSelector).focus();
|
101
|
-
}
|
102
|
-
},
|
103
|
-
|
104
|
-
innerHtml: function innerHtml(config) {
|
105
|
-
document.querySelector(config.selector).innerHTML = config.html;
|
106
|
-
if (config.focusSelector) {
|
107
|
-
document.querySelector(config.focusSelector).focus();
|
108
|
-
}
|
109
|
-
},
|
110
|
-
|
111
|
-
textContent: function textContent(config) {
|
112
|
-
document.querySelector(config.selector).textContent = config.text;
|
113
|
-
},
|
114
|
-
|
115
|
-
insertAdjacentHtml: function insertAdjacentHtml(config) {
|
116
|
-
document.querySelector(config.selector).insertAdjacentHTML(config.position || "beforeend", config.html);
|
117
|
-
if (config.focusSelector) {
|
118
|
-
document.querySelector(config.focusSelector).focus();
|
119
|
-
}
|
120
|
-
},
|
121
|
-
|
122
|
-
insertAdjacentText: function insertAdjacentText(config) {
|
123
|
-
document.querySelector(config.querySelector).insertAdjacentText(config.position || "beforeend", config.text);
|
124
|
-
},
|
125
|
-
|
126
|
-
remove: function remove(config) {
|
127
|
-
document.querySelector(config.selector).remove();
|
128
|
-
if (config.focusSelector) {
|
129
|
-
document.querySelector(config.focusSelector).focus();
|
130
|
-
}
|
131
|
-
},
|
132
|
-
|
133
|
-
replace: function replace(config) {
|
134
|
-
var element = document.querySelector(config.selector);
|
135
|
-
var div = document.createElement("div");
|
136
|
-
div.innerHTML = config.html;
|
137
|
-
if (config.focusSelector) {
|
138
|
-
document.querySelector(config.focusSelector).focus();
|
139
|
-
}
|
140
|
-
},
|
141
|
-
|
142
|
-
setValue: function setValue(config) {
|
143
|
-
document.querySelector(config.selector).value = config.value;
|
144
|
-
},
|
145
|
-
|
146
|
-
// Attribute Mutations .....................................................................................
|
147
|
-
|
148
|
-
setAttribute: function setAttribute(config) {
|
149
|
-
document.querySelector(config.selector).setAttribute(config.name, config.value);
|
150
|
-
},
|
151
|
-
|
152
|
-
removeAttribute: function removeAttribute(config) {
|
153
|
-
document.querySelector(config.selector).removeAttribute(config.name);
|
154
|
-
},
|
155
|
-
|
156
|
-
// CSS Class Mutations .....................................................................................
|
157
|
-
|
158
|
-
addCssClass: function addCssClass(config) {
|
159
|
-
document.querySelector(config.selector).classList.add(config.name);
|
160
|
-
},
|
161
|
-
|
162
|
-
removeCssClass: function removeCssClass(config) {
|
163
|
-
document.querySelector(config.selector).classList.remove(config.name);
|
164
|
-
},
|
165
|
-
|
166
|
-
// Dataset Mutations .......................................................................................
|
167
|
-
|
168
|
-
setDatasetProperty: function setDatasetProperty(config) {
|
169
|
-
document.querySelector(config.selector).dataset[config.name] = config.value;
|
170
|
-
}
|
171
|
-
};
|
172
|
-
|
173
|
-
var perform = exports.perform = function perform(operations) {
|
174
|
-
for (var name in operations) {
|
175
|
-
if (operations.hasOwnProperty(name)) {
|
176
|
-
var entries = operations[name];
|
177
|
-
for (var i = 0; i < entries.length; i++) {
|
178
|
-
try {
|
179
|
-
var config = entries[i];
|
180
|
-
DOMOperations[name](config);
|
181
|
-
} catch (e) {
|
182
|
-
console.log("CableReady detected an error in " + name + "! " + e.message);
|
183
|
-
}
|
184
|
-
}
|
185
|
-
}
|
186
|
-
}
|
187
|
-
};
|
188
|
-
|
189
|
-
/***/ }),
|
190
|
-
/* 1 */
|
191
|
-
/***/ (function(module, exports, __webpack_require__) {
|
192
|
-
|
193
|
-
"use strict";
|
194
|
-
|
195
|
-
|
196
|
-
var range; // Create a range object for efficently rendering strings to elements.
|
197
|
-
var NS_XHTML = 'http://www.w3.org/1999/xhtml';
|
198
|
-
|
199
|
-
var doc = typeof document === 'undefined' ? undefined : document;
|
200
|
-
|
201
|
-
var testEl = doc ?
|
202
|
-
doc.body || doc.createElement('div') :
|
203
|
-
{};
|
204
|
-
|
205
|
-
// Fixes <https://github.com/patrick-steele-idem/morphdom/issues/32>
|
206
|
-
// (IE7+ support) <=IE7 does not support el.hasAttribute(name)
|
207
|
-
var actualHasAttributeNS;
|
208
|
-
|
209
|
-
if (testEl.hasAttributeNS) {
|
210
|
-
actualHasAttributeNS = function(el, namespaceURI, name) {
|
211
|
-
return el.hasAttributeNS(namespaceURI, name);
|
212
|
-
};
|
213
|
-
} else if (testEl.hasAttribute) {
|
214
|
-
actualHasAttributeNS = function(el, namespaceURI, name) {
|
215
|
-
return el.hasAttribute(name);
|
216
|
-
};
|
217
|
-
} else {
|
218
|
-
actualHasAttributeNS = function(el, namespaceURI, name) {
|
219
|
-
return el.getAttributeNode(namespaceURI, name) != null;
|
220
|
-
};
|
221
|
-
}
|
222
|
-
|
223
|
-
var hasAttributeNS = actualHasAttributeNS;
|
224
|
-
|
225
|
-
|
226
|
-
function toElement(str) {
|
227
|
-
if (!range && doc.createRange) {
|
228
|
-
range = doc.createRange();
|
229
|
-
range.selectNode(doc.body);
|
230
|
-
}
|
231
|
-
|
232
|
-
var fragment;
|
233
|
-
if (range && range.createContextualFragment) {
|
234
|
-
fragment = range.createContextualFragment(str);
|
235
|
-
} else {
|
236
|
-
fragment = doc.createElement('body');
|
237
|
-
fragment.innerHTML = str;
|
238
|
-
}
|
239
|
-
return fragment.childNodes[0];
|
240
|
-
}
|
241
|
-
|
242
|
-
/**
|
243
|
-
* Returns true if two node's names are the same.
|
244
|
-
*
|
245
|
-
* NOTE: We don't bother checking `namespaceURI` because you will never find two HTML elements with the same
|
246
|
-
* nodeName and different namespace URIs.
|
247
|
-
*
|
248
|
-
* @param {Element} a
|
249
|
-
* @param {Element} b The target element
|
250
|
-
* @return {boolean}
|
251
|
-
*/
|
252
|
-
function compareNodeNames(fromEl, toEl) {
|
253
|
-
var fromNodeName = fromEl.nodeName;
|
254
|
-
var toNodeName = toEl.nodeName;
|
255
|
-
|
256
|
-
if (fromNodeName === toNodeName) {
|
257
|
-
return true;
|
258
|
-
}
|
259
|
-
|
260
|
-
if (toEl.actualize &&
|
261
|
-
fromNodeName.charCodeAt(0) < 91 && /* from tag name is upper case */
|
262
|
-
toNodeName.charCodeAt(0) > 90 /* target tag name is lower case */) {
|
263
|
-
// If the target element is a virtual DOM node then we may need to normalize the tag name
|
264
|
-
// before comparing. Normal HTML elements that are in the "http://www.w3.org/1999/xhtml"
|
265
|
-
// are converted to upper case
|
266
|
-
return fromNodeName === toNodeName.toUpperCase();
|
267
|
-
} else {
|
268
|
-
return false;
|
269
|
-
}
|
270
|
-
}
|
271
|
-
|
272
|
-
/**
|
273
|
-
* Create an element, optionally with a known namespace URI.
|
274
|
-
*
|
275
|
-
* @param {string} name the element name, e.g. 'div' or 'svg'
|
276
|
-
* @param {string} [namespaceURI] the element's namespace URI, i.e. the value of
|
277
|
-
* its `xmlns` attribute or its inferred namespace.
|
278
|
-
*
|
279
|
-
* @return {Element}
|
280
|
-
*/
|
281
|
-
function createElementNS(name, namespaceURI) {
|
282
|
-
return !namespaceURI || namespaceURI === NS_XHTML ?
|
283
|
-
doc.createElement(name) :
|
284
|
-
doc.createElementNS(namespaceURI, name);
|
285
|
-
}
|
286
|
-
|
287
|
-
/**
|
288
|
-
* Copies the children of one DOM element to another DOM element
|
289
|
-
*/
|
290
|
-
function moveChildren(fromEl, toEl) {
|
291
|
-
var curChild = fromEl.firstChild;
|
292
|
-
while (curChild) {
|
293
|
-
var nextChild = curChild.nextSibling;
|
294
|
-
toEl.appendChild(curChild);
|
295
|
-
curChild = nextChild;
|
296
|
-
}
|
297
|
-
return toEl;
|
298
|
-
}
|
299
|
-
|
300
|
-
function morphAttrs(fromNode, toNode) {
|
301
|
-
var attrs = toNode.attributes;
|
302
|
-
var i;
|
303
|
-
var attr;
|
304
|
-
var attrName;
|
305
|
-
var attrNamespaceURI;
|
306
|
-
var attrValue;
|
307
|
-
var fromValue;
|
308
|
-
|
309
|
-
for (i = attrs.length - 1; i >= 0; --i) {
|
310
|
-
attr = attrs[i];
|
311
|
-
attrName = attr.name;
|
312
|
-
attrNamespaceURI = attr.namespaceURI;
|
313
|
-
attrValue = attr.value;
|
314
|
-
|
315
|
-
if (attrNamespaceURI) {
|
316
|
-
attrName = attr.localName || attrName;
|
317
|
-
fromValue = fromNode.getAttributeNS(attrNamespaceURI, attrName);
|
318
|
-
|
319
|
-
if (fromValue !== attrValue) {
|
320
|
-
fromNode.setAttributeNS(attrNamespaceURI, attrName, attrValue);
|
321
|
-
}
|
322
|
-
} else {
|
323
|
-
fromValue = fromNode.getAttribute(attrName);
|
324
|
-
|
325
|
-
if (fromValue !== attrValue) {
|
326
|
-
fromNode.setAttribute(attrName, attrValue);
|
327
|
-
}
|
328
|
-
}
|
329
|
-
}
|
330
|
-
|
331
|
-
// Remove any extra attributes found on the original DOM element that
|
332
|
-
// weren't found on the target element.
|
333
|
-
attrs = fromNode.attributes;
|
334
|
-
|
335
|
-
for (i = attrs.length - 1; i >= 0; --i) {
|
336
|
-
attr = attrs[i];
|
337
|
-
if (attr.specified !== false) {
|
338
|
-
attrName = attr.name;
|
339
|
-
attrNamespaceURI = attr.namespaceURI;
|
340
|
-
|
341
|
-
if (attrNamespaceURI) {
|
342
|
-
attrName = attr.localName || attrName;
|
343
|
-
|
344
|
-
if (!hasAttributeNS(toNode, attrNamespaceURI, attrName)) {
|
345
|
-
fromNode.removeAttributeNS(attrNamespaceURI, attrName);
|
346
|
-
}
|
347
|
-
} else {
|
348
|
-
if (!hasAttributeNS(toNode, null, attrName)) {
|
349
|
-
fromNode.removeAttribute(attrName);
|
350
|
-
}
|
351
|
-
}
|
352
|
-
}
|
353
|
-
}
|
354
|
-
}
|
355
|
-
|
356
|
-
function syncBooleanAttrProp(fromEl, toEl, name) {
|
357
|
-
if (fromEl[name] !== toEl[name]) {
|
358
|
-
fromEl[name] = toEl[name];
|
359
|
-
if (fromEl[name]) {
|
360
|
-
fromEl.setAttribute(name, '');
|
361
|
-
} else {
|
362
|
-
fromEl.removeAttribute(name, '');
|
363
|
-
}
|
364
|
-
}
|
365
|
-
}
|
366
|
-
|
367
|
-
var specialElHandlers = {
|
368
|
-
/**
|
369
|
-
* Needed for IE. Apparently IE doesn't think that "selected" is an
|
370
|
-
* attribute when reading over the attributes using selectEl.attributes
|
371
|
-
*/
|
372
|
-
OPTION: function(fromEl, toEl) {
|
373
|
-
syncBooleanAttrProp(fromEl, toEl, 'selected');
|
374
|
-
},
|
375
|
-
/**
|
376
|
-
* The "value" attribute is special for the <input> element since it sets
|
377
|
-
* the initial value. Changing the "value" attribute without changing the
|
378
|
-
* "value" property will have no effect since it is only used to the set the
|
379
|
-
* initial value. Similar for the "checked" attribute, and "disabled".
|
380
|
-
*/
|
381
|
-
INPUT: function(fromEl, toEl) {
|
382
|
-
syncBooleanAttrProp(fromEl, toEl, 'checked');
|
383
|
-
syncBooleanAttrProp(fromEl, toEl, 'disabled');
|
384
|
-
|
385
|
-
if (fromEl.value !== toEl.value) {
|
386
|
-
fromEl.value = toEl.value;
|
387
|
-
}
|
388
|
-
|
389
|
-
if (!hasAttributeNS(toEl, null, 'value')) {
|
390
|
-
fromEl.removeAttribute('value');
|
391
|
-
}
|
392
|
-
},
|
393
|
-
|
394
|
-
TEXTAREA: function(fromEl, toEl) {
|
395
|
-
var newValue = toEl.value;
|
396
|
-
if (fromEl.value !== newValue) {
|
397
|
-
fromEl.value = newValue;
|
398
|
-
}
|
399
|
-
|
400
|
-
var firstChild = fromEl.firstChild;
|
401
|
-
if (firstChild) {
|
402
|
-
// Needed for IE. Apparently IE sets the placeholder as the
|
403
|
-
// node value and vise versa. This ignores an empty update.
|
404
|
-
var oldValue = firstChild.nodeValue;
|
405
|
-
|
406
|
-
if (oldValue == newValue || (!newValue && oldValue == fromEl.placeholder)) {
|
407
|
-
return;
|
408
|
-
}
|
409
|
-
|
410
|
-
firstChild.nodeValue = newValue;
|
411
|
-
}
|
412
|
-
},
|
413
|
-
SELECT: function(fromEl, toEl) {
|
414
|
-
if (!hasAttributeNS(toEl, null, 'multiple')) {
|
415
|
-
var selectedIndex = -1;
|
416
|
-
var i = 0;
|
417
|
-
var curChild = toEl.firstChild;
|
418
|
-
while(curChild) {
|
419
|
-
var nodeName = curChild.nodeName;
|
420
|
-
if (nodeName && nodeName.toUpperCase() === 'OPTION') {
|
421
|
-
if (hasAttributeNS(curChild, null, 'selected')) {
|
422
|
-
selectedIndex = i;
|
423
|
-
break;
|
424
|
-
}
|
425
|
-
i++;
|
426
|
-
}
|
427
|
-
curChild = curChild.nextSibling;
|
428
|
-
}
|
429
|
-
|
430
|
-
fromEl.selectedIndex = i;
|
431
|
-
}
|
432
|
-
}
|
433
|
-
};
|
434
|
-
|
435
|
-
var ELEMENT_NODE = 1;
|
436
|
-
var TEXT_NODE = 3;
|
437
|
-
var COMMENT_NODE = 8;
|
438
|
-
|
439
|
-
function noop() {}
|
440
|
-
|
441
|
-
function defaultGetNodeKey(node) {
|
442
|
-
return node.id;
|
443
|
-
}
|
444
|
-
|
445
|
-
function morphdomFactory(morphAttrs) {
|
446
|
-
|
447
|
-
return function morphdom(fromNode, toNode, options) {
|
448
|
-
if (!options) {
|
449
|
-
options = {};
|
450
|
-
}
|
451
|
-
|
452
|
-
if (typeof toNode === 'string') {
|
453
|
-
if (fromNode.nodeName === '#document' || fromNode.nodeName === 'HTML') {
|
454
|
-
var toNodeHtml = toNode;
|
455
|
-
toNode = doc.createElement('html');
|
456
|
-
toNode.innerHTML = toNodeHtml;
|
457
|
-
} else {
|
458
|
-
toNode = toElement(toNode);
|
459
|
-
}
|
460
|
-
}
|
461
|
-
|
462
|
-
var getNodeKey = options.getNodeKey || defaultGetNodeKey;
|
463
|
-
var onBeforeNodeAdded = options.onBeforeNodeAdded || noop;
|
464
|
-
var onNodeAdded = options.onNodeAdded || noop;
|
465
|
-
var onBeforeElUpdated = options.onBeforeElUpdated || noop;
|
466
|
-
var onElUpdated = options.onElUpdated || noop;
|
467
|
-
var onBeforeNodeDiscarded = options.onBeforeNodeDiscarded || noop;
|
468
|
-
var onNodeDiscarded = options.onNodeDiscarded || noop;
|
469
|
-
var onBeforeElChildrenUpdated = options.onBeforeElChildrenUpdated || noop;
|
470
|
-
var childrenOnly = options.childrenOnly === true;
|
471
|
-
|
472
|
-
// This object is used as a lookup to quickly find all keyed elements in the original DOM tree.
|
473
|
-
var fromNodesLookup = {};
|
474
|
-
var keyedRemovalList;
|
475
|
-
|
476
|
-
function addKeyedRemoval(key) {
|
477
|
-
if (keyedRemovalList) {
|
478
|
-
keyedRemovalList.push(key);
|
479
|
-
} else {
|
480
|
-
keyedRemovalList = [key];
|
481
|
-
}
|
482
|
-
}
|
483
|
-
|
484
|
-
function walkDiscardedChildNodes(node, skipKeyedNodes) {
|
485
|
-
if (node.nodeType === ELEMENT_NODE) {
|
486
|
-
var curChild = node.firstChild;
|
487
|
-
while (curChild) {
|
488
|
-
|
489
|
-
var key = undefined;
|
490
|
-
|
491
|
-
if (skipKeyedNodes && (key = getNodeKey(curChild))) {
|
492
|
-
// If we are skipping keyed nodes then we add the key
|
493
|
-
// to a list so that it can be handled at the very end.
|
494
|
-
addKeyedRemoval(key);
|
495
|
-
} else {
|
496
|
-
// Only report the node as discarded if it is not keyed. We do this because
|
497
|
-
// at the end we loop through all keyed elements that were unmatched
|
498
|
-
// and then discard them in one final pass.
|
499
|
-
onNodeDiscarded(curChild);
|
500
|
-
if (curChild.firstChild) {
|
501
|
-
walkDiscardedChildNodes(curChild, skipKeyedNodes);
|
502
|
-
}
|
503
|
-
}
|
504
|
-
|
505
|
-
curChild = curChild.nextSibling;
|
506
|
-
}
|
507
|
-
}
|
508
|
-
}
|
509
|
-
|
510
|
-
/**
|
511
|
-
* Removes a DOM node out of the original DOM
|
512
|
-
*
|
513
|
-
* @param {Node} node The node to remove
|
514
|
-
* @param {Node} parentNode The nodes parent
|
515
|
-
* @param {Boolean} skipKeyedNodes If true then elements with keys will be skipped and not discarded.
|
516
|
-
* @return {undefined}
|
517
|
-
*/
|
518
|
-
function removeNode(node, parentNode, skipKeyedNodes) {
|
519
|
-
if (onBeforeNodeDiscarded(node) === false) {
|
520
|
-
return;
|
521
|
-
}
|
522
|
-
|
523
|
-
if (parentNode) {
|
524
|
-
parentNode.removeChild(node);
|
525
|
-
}
|
526
|
-
|
527
|
-
onNodeDiscarded(node);
|
528
|
-
walkDiscardedChildNodes(node, skipKeyedNodes);
|
529
|
-
}
|
530
|
-
|
531
|
-
// // TreeWalker implementation is no faster, but keeping this around in case this changes in the future
|
532
|
-
// function indexTree(root) {
|
533
|
-
// var treeWalker = document.createTreeWalker(
|
534
|
-
// root,
|
535
|
-
// NodeFilter.SHOW_ELEMENT);
|
536
|
-
//
|
537
|
-
// var el;
|
538
|
-
// while((el = treeWalker.nextNode())) {
|
539
|
-
// var key = getNodeKey(el);
|
540
|
-
// if (key) {
|
541
|
-
// fromNodesLookup[key] = el;
|
542
|
-
// }
|
543
|
-
// }
|
544
|
-
// }
|
545
|
-
|
546
|
-
// // NodeIterator implementation is no faster, but keeping this around in case this changes in the future
|
547
|
-
//
|
548
|
-
// function indexTree(node) {
|
549
|
-
// var nodeIterator = document.createNodeIterator(node, NodeFilter.SHOW_ELEMENT);
|
550
|
-
// var el;
|
551
|
-
// while((el = nodeIterator.nextNode())) {
|
552
|
-
// var key = getNodeKey(el);
|
553
|
-
// if (key) {
|
554
|
-
// fromNodesLookup[key] = el;
|
555
|
-
// }
|
556
|
-
// }
|
557
|
-
// }
|
558
|
-
|
559
|
-
function indexTree(node) {
|
560
|
-
if (node.nodeType === ELEMENT_NODE) {
|
561
|
-
var curChild = node.firstChild;
|
562
|
-
while (curChild) {
|
563
|
-
var key = getNodeKey(curChild);
|
564
|
-
if (key) {
|
565
|
-
fromNodesLookup[key] = curChild;
|
566
|
-
}
|
567
|
-
|
568
|
-
// Walk recursively
|
569
|
-
indexTree(curChild);
|
570
|
-
|
571
|
-
curChild = curChild.nextSibling;
|
572
|
-
}
|
573
|
-
}
|
574
|
-
}
|
575
|
-
|
576
|
-
indexTree(fromNode);
|
577
|
-
|
578
|
-
function handleNodeAdded(el) {
|
579
|
-
onNodeAdded(el);
|
580
|
-
|
581
|
-
var curChild = el.firstChild;
|
582
|
-
while (curChild) {
|
583
|
-
var nextSibling = curChild.nextSibling;
|
584
|
-
|
585
|
-
var key = getNodeKey(curChild);
|
586
|
-
if (key) {
|
587
|
-
var unmatchedFromEl = fromNodesLookup[key];
|
588
|
-
if (unmatchedFromEl && compareNodeNames(curChild, unmatchedFromEl)) {
|
589
|
-
curChild.parentNode.replaceChild(unmatchedFromEl, curChild);
|
590
|
-
morphEl(unmatchedFromEl, curChild);
|
591
|
-
}
|
592
|
-
}
|
593
|
-
|
594
|
-
handleNodeAdded(curChild);
|
595
|
-
curChild = nextSibling;
|
596
|
-
}
|
597
|
-
}
|
598
|
-
|
599
|
-
function morphEl(fromEl, toEl, childrenOnly) {
|
600
|
-
var toElKey = getNodeKey(toEl);
|
601
|
-
var curFromNodeKey;
|
602
|
-
|
603
|
-
if (toElKey) {
|
604
|
-
// If an element with an ID is being morphed then it is will be in the final
|
605
|
-
// DOM so clear it out of the saved elements collection
|
606
|
-
delete fromNodesLookup[toElKey];
|
607
|
-
}
|
608
|
-
|
609
|
-
if (toNode.isSameNode && toNode.isSameNode(fromNode)) {
|
610
|
-
return;
|
611
|
-
}
|
612
|
-
|
613
|
-
if (!childrenOnly) {
|
614
|
-
if (onBeforeElUpdated(fromEl, toEl) === false) {
|
615
|
-
return;
|
616
|
-
}
|
617
|
-
|
618
|
-
morphAttrs(fromEl, toEl);
|
619
|
-
onElUpdated(fromEl);
|
620
|
-
|
621
|
-
if (onBeforeElChildrenUpdated(fromEl, toEl) === false) {
|
622
|
-
return;
|
623
|
-
}
|
624
|
-
}
|
625
|
-
|
626
|
-
if (fromEl.nodeName !== 'TEXTAREA') {
|
627
|
-
var curToNodeChild = toEl.firstChild;
|
628
|
-
var curFromNodeChild = fromEl.firstChild;
|
629
|
-
var curToNodeKey;
|
630
|
-
|
631
|
-
var fromNextSibling;
|
632
|
-
var toNextSibling;
|
633
|
-
var matchingFromEl;
|
634
|
-
|
635
|
-
outer: while (curToNodeChild) {
|
636
|
-
toNextSibling = curToNodeChild.nextSibling;
|
637
|
-
curToNodeKey = getNodeKey(curToNodeChild);
|
638
|
-
|
639
|
-
while (curFromNodeChild) {
|
640
|
-
fromNextSibling = curFromNodeChild.nextSibling;
|
641
|
-
|
642
|
-
if (curToNodeChild.isSameNode && curToNodeChild.isSameNode(curFromNodeChild)) {
|
643
|
-
curToNodeChild = toNextSibling;
|
644
|
-
curFromNodeChild = fromNextSibling;
|
645
|
-
continue outer;
|
646
|
-
}
|
647
|
-
|
648
|
-
curFromNodeKey = getNodeKey(curFromNodeChild);
|
649
|
-
|
650
|
-
var curFromNodeType = curFromNodeChild.nodeType;
|
651
|
-
|
652
|
-
var isCompatible = undefined;
|
653
|
-
|
654
|
-
if (curFromNodeType === curToNodeChild.nodeType) {
|
655
|
-
if (curFromNodeType === ELEMENT_NODE) {
|
656
|
-
// Both nodes being compared are Element nodes
|
657
|
-
|
658
|
-
if (curToNodeKey) {
|
659
|
-
// The target node has a key so we want to match it up with the correct element
|
660
|
-
// in the original DOM tree
|
661
|
-
if (curToNodeKey !== curFromNodeKey) {
|
662
|
-
// The current element in the original DOM tree does not have a matching key so
|
663
|
-
// let's check our lookup to see if there is a matching element in the original
|
664
|
-
// DOM tree
|
665
|
-
if ((matchingFromEl = fromNodesLookup[curToNodeKey])) {
|
666
|
-
if (curFromNodeChild.nextSibling === matchingFromEl) {
|
667
|
-
// Special case for single element removals. To avoid removing the original
|
668
|
-
// DOM node out of the tree (since that can break CSS transitions, etc.),
|
669
|
-
// we will instead discard the current node and wait until the next
|
670
|
-
// iteration to properly match up the keyed target element with its matching
|
671
|
-
// element in the original tree
|
672
|
-
isCompatible = false;
|
673
|
-
} else {
|
674
|
-
// We found a matching keyed element somewhere in the original DOM tree.
|
675
|
-
// Let's moving the original DOM node into the current position and morph
|
676
|
-
// it.
|
677
|
-
|
678
|
-
// NOTE: We use insertBefore instead of replaceChild because we want to go through
|
679
|
-
// the `removeNode()` function for the node that is being discarded so that
|
680
|
-
// all lifecycle hooks are correctly invoked
|
681
|
-
fromEl.insertBefore(matchingFromEl, curFromNodeChild);
|
682
|
-
|
683
|
-
fromNextSibling = curFromNodeChild.nextSibling;
|
684
|
-
|
685
|
-
if (curFromNodeKey) {
|
686
|
-
// Since the node is keyed it might be matched up later so we defer
|
687
|
-
// the actual removal to later
|
688
|
-
addKeyedRemoval(curFromNodeKey);
|
689
|
-
} else {
|
690
|
-
// NOTE: we skip nested keyed nodes from being removed since there is
|
691
|
-
// still a chance they will be matched up later
|
692
|
-
removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);
|
693
|
-
}
|
694
|
-
|
695
|
-
curFromNodeChild = matchingFromEl;
|
696
|
-
}
|
697
|
-
} else {
|
698
|
-
// The nodes are not compatible since the "to" node has a key and there
|
699
|
-
// is no matching keyed node in the source tree
|
700
|
-
isCompatible = false;
|
701
|
-
}
|
702
|
-
}
|
703
|
-
} else if (curFromNodeKey) {
|
704
|
-
// The original has a key
|
705
|
-
isCompatible = false;
|
706
|
-
}
|
707
|
-
|
708
|
-
isCompatible = isCompatible !== false && compareNodeNames(curFromNodeChild, curToNodeChild);
|
709
|
-
if (isCompatible) {
|
710
|
-
// We found compatible DOM elements so transform
|
711
|
-
// the current "from" node to match the current
|
712
|
-
// target DOM node.
|
713
|
-
morphEl(curFromNodeChild, curToNodeChild);
|
714
|
-
}
|
715
|
-
|
716
|
-
} else if (curFromNodeType === TEXT_NODE || curFromNodeType == COMMENT_NODE) {
|
717
|
-
// Both nodes being compared are Text or Comment nodes
|
718
|
-
isCompatible = true;
|
719
|
-
// Simply update nodeValue on the original node to
|
720
|
-
// change the text value
|
721
|
-
if (curFromNodeChild.nodeValue !== curToNodeChild.nodeValue) {
|
722
|
-
curFromNodeChild.nodeValue = curToNodeChild.nodeValue;
|
723
|
-
}
|
724
|
-
|
725
|
-
}
|
726
|
-
}
|
727
|
-
|
728
|
-
if (isCompatible) {
|
729
|
-
// Advance both the "to" child and the "from" child since we found a match
|
730
|
-
curToNodeChild = toNextSibling;
|
731
|
-
curFromNodeChild = fromNextSibling;
|
732
|
-
continue outer;
|
733
|
-
}
|
734
|
-
|
735
|
-
// No compatible match so remove the old node from the DOM and continue trying to find a
|
736
|
-
// match in the original DOM. However, we only do this if the from node is not keyed
|
737
|
-
// since it is possible that a keyed node might match up with a node somewhere else in the
|
738
|
-
// target tree and we don't want to discard it just yet since it still might find a
|
739
|
-
// home in the final DOM tree. After everything is done we will remove any keyed nodes
|
740
|
-
// that didn't find a home
|
741
|
-
if (curFromNodeKey) {
|
742
|
-
// Since the node is keyed it might be matched up later so we defer
|
743
|
-
// the actual removal to later
|
744
|
-
addKeyedRemoval(curFromNodeKey);
|
745
|
-
} else {
|
746
|
-
// NOTE: we skip nested keyed nodes from being removed since there is
|
747
|
-
// still a chance they will be matched up later
|
748
|
-
removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);
|
749
|
-
}
|
750
|
-
|
751
|
-
curFromNodeChild = fromNextSibling;
|
752
|
-
}
|
753
|
-
|
754
|
-
// If we got this far then we did not find a candidate match for
|
755
|
-
// our "to node" and we exhausted all of the children "from"
|
756
|
-
// nodes. Therefore, we will just append the current "to" node
|
757
|
-
// to the end
|
758
|
-
if (curToNodeKey && (matchingFromEl = fromNodesLookup[curToNodeKey]) && compareNodeNames(matchingFromEl, curToNodeChild)) {
|
759
|
-
fromEl.appendChild(matchingFromEl);
|
760
|
-
morphEl(matchingFromEl, curToNodeChild);
|
761
|
-
} else {
|
762
|
-
var onBeforeNodeAddedResult = onBeforeNodeAdded(curToNodeChild);
|
763
|
-
if (onBeforeNodeAddedResult !== false) {
|
764
|
-
if (onBeforeNodeAddedResult) {
|
765
|
-
curToNodeChild = onBeforeNodeAddedResult;
|
766
|
-
}
|
767
|
-
|
768
|
-
if (curToNodeChild.actualize) {
|
769
|
-
curToNodeChild = curToNodeChild.actualize(fromEl.ownerDocument || doc);
|
770
|
-
}
|
771
|
-
fromEl.appendChild(curToNodeChild);
|
772
|
-
handleNodeAdded(curToNodeChild);
|
773
|
-
}
|
774
|
-
}
|
775
|
-
|
776
|
-
curToNodeChild = toNextSibling;
|
777
|
-
curFromNodeChild = fromNextSibling;
|
778
|
-
}
|
779
|
-
|
780
|
-
// We have processed all of the "to nodes". If curFromNodeChild is
|
781
|
-
// non-null then we still have some from nodes left over that need
|
782
|
-
// to be removed
|
783
|
-
while (curFromNodeChild) {
|
784
|
-
fromNextSibling = curFromNodeChild.nextSibling;
|
785
|
-
if ((curFromNodeKey = getNodeKey(curFromNodeChild))) {
|
786
|
-
// Since the node is keyed it might be matched up later so we defer
|
787
|
-
// the actual removal to later
|
788
|
-
addKeyedRemoval(curFromNodeKey);
|
789
|
-
} else {
|
790
|
-
// NOTE: we skip nested keyed nodes from being removed since there is
|
791
|
-
// still a chance they will be matched up later
|
792
|
-
removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);
|
793
|
-
}
|
794
|
-
curFromNodeChild = fromNextSibling;
|
795
|
-
}
|
796
|
-
}
|
797
|
-
|
798
|
-
var specialElHandler = specialElHandlers[fromEl.nodeName];
|
799
|
-
if (specialElHandler) {
|
800
|
-
specialElHandler(fromEl, toEl);
|
801
|
-
}
|
802
|
-
} // END: morphEl(...)
|
803
|
-
|
804
|
-
var morphedNode = fromNode;
|
805
|
-
var morphedNodeType = morphedNode.nodeType;
|
806
|
-
var toNodeType = toNode.nodeType;
|
807
|
-
|
808
|
-
if (!childrenOnly) {
|
809
|
-
// Handle the case where we are given two DOM nodes that are not
|
810
|
-
// compatible (e.g. <div> --> <span> or <div> --> TEXT)
|
811
|
-
if (morphedNodeType === ELEMENT_NODE) {
|
812
|
-
if (toNodeType === ELEMENT_NODE) {
|
813
|
-
if (!compareNodeNames(fromNode, toNode)) {
|
814
|
-
onNodeDiscarded(fromNode);
|
815
|
-
morphedNode = moveChildren(fromNode, createElementNS(toNode.nodeName, toNode.namespaceURI));
|
816
|
-
}
|
817
|
-
} else {
|
818
|
-
// Going from an element node to a text node
|
819
|
-
morphedNode = toNode;
|
820
|
-
}
|
821
|
-
} else if (morphedNodeType === TEXT_NODE || morphedNodeType === COMMENT_NODE) { // Text or comment node
|
822
|
-
if (toNodeType === morphedNodeType) {
|
823
|
-
if (morphedNode.nodeValue !== toNode.nodeValue) {
|
824
|
-
morphedNode.nodeValue = toNode.nodeValue;
|
825
|
-
}
|
826
|
-
|
827
|
-
return morphedNode;
|
828
|
-
} else {
|
829
|
-
// Text node to something else
|
830
|
-
morphedNode = toNode;
|
831
|
-
}
|
832
|
-
}
|
833
|
-
}
|
834
|
-
|
835
|
-
if (morphedNode === toNode) {
|
836
|
-
// The "to node" was not compatible with the "from node" so we had to
|
837
|
-
// toss out the "from node" and use the "to node"
|
838
|
-
onNodeDiscarded(fromNode);
|
839
|
-
} else {
|
840
|
-
morphEl(morphedNode, toNode, childrenOnly);
|
841
|
-
|
842
|
-
// We now need to loop over any keyed nodes that might need to be
|
843
|
-
// removed. We only do the removal if we know that the keyed node
|
844
|
-
// never found a match. When a keyed node is matched up we remove
|
845
|
-
// it out of fromNodesLookup and we use fromNodesLookup to determine
|
846
|
-
// if a keyed node has been matched up or not
|
847
|
-
if (keyedRemovalList) {
|
848
|
-
for (var i=0, len=keyedRemovalList.length; i<len; i++) {
|
849
|
-
var elToRemove = fromNodesLookup[keyedRemovalList[i]];
|
850
|
-
if (elToRemove) {
|
851
|
-
removeNode(elToRemove, elToRemove.parentNode, false);
|
852
|
-
}
|
853
|
-
}
|
854
|
-
}
|
855
|
-
}
|
856
|
-
|
857
|
-
if (!childrenOnly && morphedNode !== fromNode && fromNode.parentNode) {
|
858
|
-
if (morphedNode.actualize) {
|
859
|
-
morphedNode = morphedNode.actualize(fromNode.ownerDocument || doc);
|
860
|
-
}
|
861
|
-
// If we had to swap out the from node with a new node because the old
|
862
|
-
// node was not compatible with the target node then we need to
|
863
|
-
// replace the old DOM node in the original DOM tree. This is only
|
864
|
-
// possible if the original DOM node was part of a DOM tree which
|
865
|
-
// we know is the case if it has a parent node.
|
866
|
-
fromNode.parentNode.replaceChild(morphedNode, fromNode);
|
867
|
-
}
|
868
|
-
|
869
|
-
return morphedNode;
|
870
|
-
};
|
871
|
-
}
|
872
|
-
|
873
|
-
var morphdom = morphdomFactory(morphAttrs);
|
874
|
-
|
875
|
-
module.exports = morphdom;
|
876
|
-
|
877
|
-
|
878
|
-
/***/ })
|
879
|
-
/******/ ]);
|
1
|
+
window.CableReady=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t,n){"use strict";var r,o="http://www.w3.org/1999/xhtml",u="undefined"==typeof document?void 0:document,i=u?u.body||u.createElement("div"):{},c=i.hasAttributeNS?function(e,t,n){return e.hasAttributeNS(t,n)}:i.hasAttribute?function(e,t,n){return e.hasAttribute(n)}:function(e,t,n){return null!=e.getAttributeNode(t,n)};function l(e,t){var n=e.nodeName,r=t.nodeName;return n===r||!!(t.actualize&&n.charCodeAt(0)<91&&r.charCodeAt(0)>90)&&n===r.toUpperCase()}function a(e,t,n){e[n]!==t[n]&&(e[n]=t[n],e[n]?e.setAttribute(n,""):e.removeAttribute(n,""))}var d={OPTION:function(e,t){a(e,t,"selected")},INPUT:function(e,t){a(e,t,"checked"),a(e,t,"disabled"),e.value!==t.value&&(e.value=t.value),c(t,null,"value")||e.removeAttribute("value")},TEXTAREA:function(e,t){var n=t.value;e.value!==n&&(e.value=n);var r=e.firstChild;if(r){var o=r.nodeValue;if(o==n||!n&&o==e.placeholder)return;r.nodeValue=n}},SELECT:function(e,t){if(!c(t,null,"multiple")){for(var n=0,r=t.firstChild;r;){var o=r.nodeName;if(o&&"OPTION"===o.toUpperCase()){if(c(r,null,"selected")){n;break}n++}r=r.nextSibling}e.selectedIndex=n}}},f=1,s=3,m=8;function v(){}function p(e){return e.id}var S=function(e){return function(t,n,i){if(i||(i={}),"string"==typeof n)if("#document"===t.nodeName||"HTML"===t.nodeName){var c=n;(n=u.createElement("html")).innerHTML=c}else n=function(e){var t;return!r&&u.createRange&&(r=u.createRange()).selectNode(u.body),r&&r.createContextualFragment?t=r.createContextualFragment(e):(t=u.createElement("body")).innerHTML=e,t.childNodes[0]}(n);var a,S=i.getNodeKey||p,b=i.onBeforeNodeAdded||v,y=i.onNodeAdded||v,h=i.onBeforeElUpdated||v,N=i.onElUpdated||v,g=i.onBeforeNodeDiscarded||v,C=i.onNodeDiscarded||v,A=i.onBeforeElChildrenUpdated||v,x=!0===i.childrenOnly,T={};function q(e){a?a.push(e):a=[e]}function E(e,t,n){!1!==g(e)&&(t&&t.removeChild(e),C(e),function e(t,n){if(t.nodeType===f)for(var r=t.firstChild;r;){var o=void 0;n&&(o=S(r))?q(o):(C(r),r.firstChild&&e(r,n)),r=r.nextSibling}}(e,n))}function O(e){y(e);for(var t=e.firstChild;t;){var n=t.nextSibling,r=S(t);if(r){var o=T[r];o&&l(t,o)&&(t.parentNode.replaceChild(o,t),w(o,t))}O(t),t=n}}function w(r,o,i){var c,a=S(o);if(a&&delete T[a],!n.isSameNode||!n.isSameNode(t)){if(!i){if(!1===h(r,o))return;if(e(r,o),N(r),!1===A(r,o))return}if("TEXTAREA"!==r.nodeName){var v,p,y,g,C=o.firstChild,x=r.firstChild;e:for(;C;){for(y=C.nextSibling,v=S(C);x;){if(p=x.nextSibling,C.isSameNode&&C.isSameNode(x)){C=y,x=p;continue e}c=S(x);var j=x.nodeType,M=void 0;if(j===C.nodeType&&(j===f?(v?v!==c&&((g=T[v])?x.nextSibling===g?M=!1:(r.insertBefore(g,x),p=x.nextSibling,c?q(c):E(x,r,!0),x=g):M=!1):c&&(M=!1),(M=!1!==M&&l(x,C))&&w(x,C)):j!==s&&j!=m||(M=!0,x.nodeValue!==C.nodeValue&&(x.nodeValue=C.nodeValue))),M){C=y,x=p;continue e}c?q(c):E(x,r,!0),x=p}if(v&&(g=T[v])&&l(g,C))r.appendChild(g),w(g,C);else{var V=b(C);!1!==V&&(V&&(C=V),C.actualize&&(C=C.actualize(r.ownerDocument||u)),r.appendChild(C),O(C))}C=y,x=p}for(;x;)p=x.nextSibling,(c=S(x))?q(c):E(x,r,!0),x=p}var L=d[r.nodeName];L&&L(r,o)}}!function e(t){if(t.nodeType===f)for(var n=t.firstChild;n;){var r=S(n);r&&(T[r]=n),e(n),n=n.nextSibling}}(t);var j=t,M=j.nodeType,V=n.nodeType;if(!x)if(M===f)V===f?l(t,n)||(C(t),j=function(e,t){for(var n=e.firstChild;n;){var r=n.nextSibling;t.appendChild(n),n=r}return t}(t,function(e,t){return t&&t!==o?u.createElementNS(t,e):u.createElement(e)}(n.nodeName,n.namespaceURI))):j=n;else if(M===s||M===m){if(V===M)return j.nodeValue!==n.nodeValue&&(j.nodeValue=n.nodeValue),j;j=n}if(j===n)C(t);else if(w(j,n,x),a)for(var L=0,P=a.length;L<P;L++){var H=T[a[L]];H&&E(H,H.parentNode,!1)}return!x&&j!==t&&t.parentNode&&(j.actualize&&(j=j.actualize(t.ownerDocument||u)),t.parentNode.replaceChild(j,t)),j}}(function(e,t){var n,r,o,u,i,l=t.attributes;for(n=l.length-1;n>=0;--n)o=(r=l[n]).name,u=r.namespaceURI,i=r.value,u?(o=r.localName||o,e.getAttributeNS(u,o)!==i&&e.setAttributeNS(u,o,i)):e.getAttribute(o)!==i&&e.setAttribute(o,i);for(n=(l=e.attributes).length-1;n>=0;--n)!1!==(r=l[n]).specified&&(o=r.name,(u=r.namespaceURI)?(o=r.localName||o,c(t,u,o)||e.removeAttributeNS(u,o)):c(t,null,o)||e.removeAttribute(o))});e.exports=S},function(e,t,n){"use strict";n.r(t),n.d(t,"perform",function(){return i});var r=n(0),o=n.n(r),u={dispatchEvent:function(e){var t=document.querySelector(e.selector)||window,n=new Event(e.name);n.detail=e.detail,t.dispatchEvent(n)},morph:function(e){var t=String(e.html).trim(),n=document.createElement("template");n.innerHTML=t,o()(document.querySelector(e.selector),n.content,{childrenOnly:!!e.childrenOnly}),e.focusSelector&&document.querySelector(e.focusSelector).focus()},innerHtml:function(e){document.querySelector(e.selector).innerHTML=e.html,e.focusSelector&&document.querySelector(e.focusSelector).focus()},textContent:function(e){document.querySelector(e.selector).textContent=e.text},insertAdjacentHtml:function(e){document.querySelector(e.selector).insertAdjacentHTML(e.position||"beforeend",e.html),e.focusSelector&&document.querySelector(e.focusSelector).focus()},insertAdjacentText:function(e){document.querySelector(e.querySelector).insertAdjacentText(e.position||"beforeend",e.text)},remove:function(e){document.querySelector(e.selector).remove(),e.focusSelector&&document.querySelector(e.focusSelector).focus()},replace:function(e){document.querySelector(e.selector);document.createElement("div").innerHTML=e.html,e.focusSelector&&document.querySelector(e.focusSelector).focus()},setValue:function(e){document.querySelector(e.selector).value=e.value},setAttribute:function(e){document.querySelector(e.selector).setAttribute(e.name,e.value)},removeAttribute:function(e){document.querySelector(e.selector).removeAttribute(e.name)},addCssClass:function(e){document.querySelector(e.selector).classList.add(e.name)},removeCssClass:function(e){document.querySelector(e.selector).classList.remove(e.name)},setDatasetProperty:function(e){document.querySelector(e.selector).dataset[e.name]=e.value}},i=function(e){for(var t in e)if(e.hasOwnProperty(t))for(var n=e[t],r=0;r<n.length;r++)try{var o=n[r];u[t](o)}catch(e){console.log("CableReady detected an error in ".concat(t,"! ").concat(e.message))}}}]);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cable_ready
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Hopkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
requirements: []
|
122
122
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.6
|
123
|
+
rubygems_version: 2.7.6
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: put something here
|