megatron 0.1.69 → 0.1.70

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: 3748513b1774d6e4731039eadcc60eb777f407e7
4
- data.tar.gz: c37835505c6b5df7b27f23c57d2ac57416b68375
3
+ metadata.gz: 5dfef8663a8a535d9e3c4d99c36412f27d4f42d5
4
+ data.tar.gz: 71df7bdef56a2419c7d7aefec0184141e6a1c43c
5
5
  SHA512:
6
- metadata.gz: dbd0525ee811075578391b42f8a50054253963a865dd78d54e7e064a3df418fa1100bbdee3570053a87831123064a486d22887e1287541187bd100b3ce55792f
7
- data.tar.gz: 2c3d8d0c37aae9ba8b30ddcd9a4df54a7886c049867efc8d2d52bd75adebff05c521c86999b363d4fea508a15c82c3f7b1f3c28333d83042a17f5b5b30bcd1a9
6
+ metadata.gz: d3b0f12ee70e0e6a3373609f2e68fef5152e4b536df14b10613df3daa850e4687df2965ce934f7a362ac41c16a7e367e53d7395f5ecbb13c35480e0e2d0abfee
7
+ data.tar.gz: 5266850c8ddfb41a33297a4b438f0fb4dfc007f509d9fe40a3c685252f585d9d1c5b13ea87915638ddbaf289a20d7be2c7738b71cb7dcd1b7b6cc7bd12bd193f
@@ -10,6 +10,8 @@ var request = require('superagent')
10
10
  var NProgress = require('nprogress')
11
11
  var esvg = require('./esvg')
12
12
 
13
+ require('./shims/classlist')
14
+
13
15
  window.Megatron = module.exports = {
14
16
  Dialog: Dialog,
15
17
  notify: notify,
@@ -71,14 +73,14 @@ function handleDialogTrigger(event){
71
73
 
72
74
  function toggleNavigationMode(event) {
73
75
  event.target.blur()
74
- utils.Classie.toggle(document.querySelector('body'), 'active-nav')
76
+ document.querySelector('body').classList.toggle('active-nav')
75
77
  }
76
78
 
77
79
  function disableWith(event){
78
80
  var buttons = event.currentTarget.querySelectorAll('[data-disable-with]')
79
81
  Array.prototype.forEach.call(buttons, function(button){
80
82
  button.disabled = true
81
- utils.Classie.add(button, 'disabled')
83
+ button.classList.add('disabled')
82
84
 
83
85
  var buttonText = button.dataset.disableWith
84
86
  if (!buttonText || buttonText == '') { buttonText = button.innerHTML }
@@ -97,8 +99,10 @@ if (!window.$ || !$.rails) {
97
99
  }
98
100
 
99
101
  function handleRemoteFormSubmit(event){
100
- if (_.find(boundForms, function(el){return el == event.currentTarget}))
102
+ // Prevent doubling up on form event hanlding.
103
+ if(boundForms.filter(function(el){return el == event.currentTarget})[0])
101
104
  return
105
+ // Trigger a form submission event.
102
106
  new Form({el: event.currentTarget}).submit(event)
103
107
  boundForms.push(event.currentTarget)
104
108
  }
@@ -0,0 +1,238 @@
1
+ /*
2
+ * classList.js: Cross-browser full element.classList implementation.
3
+ * 2014-07-23
4
+ *
5
+ * By Eli Grey, http://eligrey.com
6
+ * Public Domain.
7
+ * NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
8
+ */
9
+
10
+ /*global self, document, DOMException */
11
+
12
+ /*! @source http://purl.eligrey.com/github/classList.js/blob/master/classList.js*/
13
+
14
+ if ("document" in self) {
15
+
16
+ // Full polyfill for browsers with no classList support
17
+ if (!("classList" in document.createElement("_"))) {
18
+
19
+ (function (view) {
20
+
21
+ "use strict";
22
+
23
+ if (!('Element' in view)) return;
24
+
25
+ var
26
+ classListProp = "classList"
27
+ , protoProp = "prototype"
28
+ , elemCtrProto = view.Element[protoProp]
29
+ , objCtr = Object
30
+ , strTrim = String[protoProp].trim || function () {
31
+ return this.replace(/^\s+|\s+$/g, "");
32
+ }
33
+ , arrIndexOf = Array[protoProp].indexOf || function (item) {
34
+ var
35
+ i = 0
36
+ , len = this.length
37
+ ;
38
+ for (; i < len; i++) {
39
+ if (i in this && this[i] === item) {
40
+ return i;
41
+ }
42
+ }
43
+ return -1;
44
+ }
45
+ // Vendors: please allow content code to instantiate DOMExceptions
46
+ , DOMEx = function (type, message) {
47
+ this.name = type;
48
+ this.code = DOMException[type];
49
+ this.message = message;
50
+ }
51
+ , checkTokenAndGetIndex = function (classList, token) {
52
+ if (token === "") {
53
+ throw new DOMEx(
54
+ "SYNTAX_ERR"
55
+ , "An invalid or illegal string was specified"
56
+ );
57
+ }
58
+ if (/\s/.test(token)) {
59
+ throw new DOMEx(
60
+ "INVALID_CHARACTER_ERR"
61
+ , "String contains an invalid character"
62
+ );
63
+ }
64
+ return arrIndexOf.call(classList, token);
65
+ }
66
+ , ClassList = function (elem) {
67
+ var
68
+ trimmedClasses = strTrim.call(elem.getAttribute("class") || "")
69
+ , classes = trimmedClasses ? trimmedClasses.split(/\s+/) : []
70
+ , i = 0
71
+ , len = classes.length
72
+ ;
73
+ for (; i < len; i++) {
74
+ this.push(classes[i]);
75
+ }
76
+ this._updateClassName = function () {
77
+ elem.setAttribute("class", this.toString());
78
+ };
79
+ }
80
+ , classListProto = ClassList[protoProp] = []
81
+ , classListGetter = function () {
82
+ return new ClassList(this);
83
+ }
84
+ ;
85
+ // Most DOMException implementations don't allow calling DOMException's toString()
86
+ // on non-DOMExceptions. Error's toString() is sufficient here.
87
+ DOMEx[protoProp] = Error[protoProp];
88
+ classListProto.item = function (i) {
89
+ return this[i] || null;
90
+ };
91
+ classListProto.contains = function (token) {
92
+ token += "";
93
+ return checkTokenAndGetIndex(this, token) !== -1;
94
+ };
95
+ classListProto.add = function () {
96
+ var
97
+ tokens = arguments
98
+ , i = 0
99
+ , l = tokens.length
100
+ , token
101
+ , updated = false
102
+ ;
103
+ do {
104
+ token = tokens[i] + "";
105
+ if (checkTokenAndGetIndex(this, token) === -1) {
106
+ this.push(token);
107
+ updated = true;
108
+ }
109
+ }
110
+ while (++i < l);
111
+
112
+ if (updated) {
113
+ this._updateClassName();
114
+ }
115
+ };
116
+ classListProto.remove = function () {
117
+ var
118
+ tokens = arguments
119
+ , i = 0
120
+ , l = tokens.length
121
+ , token
122
+ , updated = false
123
+ , index
124
+ ;
125
+ do {
126
+ token = tokens[i] + "";
127
+ index = checkTokenAndGetIndex(this, token);
128
+ while (index !== -1) {
129
+ this.splice(index, 1);
130
+ updated = true;
131
+ index = checkTokenAndGetIndex(this, token);
132
+ }
133
+ }
134
+ while (++i < l);
135
+
136
+ if (updated) {
137
+ this._updateClassName();
138
+ }
139
+ };
140
+ classListProto.toggle = function (token, force) {
141
+ token += "";
142
+
143
+ var
144
+ result = this.contains(token)
145
+ , method = result ?
146
+ force !== true && "remove"
147
+ :
148
+ force !== false && "add"
149
+ ;
150
+
151
+ if (method) {
152
+ this[method](token);
153
+ }
154
+
155
+ if (force === true || force === false) {
156
+ return force;
157
+ } else {
158
+ return !result;
159
+ }
160
+ };
161
+ classListProto.toString = function () {
162
+ return this.join(" ");
163
+ };
164
+
165
+ if (objCtr.defineProperty) {
166
+ var classListPropDesc = {
167
+ get: classListGetter
168
+ , enumerable: true
169
+ , configurable: true
170
+ };
171
+ try {
172
+ objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);
173
+ } catch (ex) { // IE 8 doesn't support enumerable:true
174
+ if (ex.number === -0x7FF5EC54) {
175
+ classListPropDesc.enumerable = false;
176
+ objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);
177
+ }
178
+ }
179
+ } else if (objCtr[protoProp].__defineGetter__) {
180
+ elemCtrProto.__defineGetter__(classListProp, classListGetter);
181
+ }
182
+
183
+ }(self));
184
+
185
+ } else {
186
+ // There is full or partial native classList support, so just check if we need
187
+ // to normalize the add/remove and toggle APIs.
188
+
189
+ (function () {
190
+ "use strict";
191
+
192
+ var testElement = document.createElement("_");
193
+
194
+ testElement.classList.add("c1", "c2");
195
+
196
+ // Polyfill for IE 10/11 and Firefox <26, where classList.add and
197
+ // classList.remove exist but support only one argument at a time.
198
+ if (!testElement.classList.contains("c2")) {
199
+ var createMethod = function(method) {
200
+ var original = DOMTokenList.prototype[method];
201
+
202
+ DOMTokenList.prototype[method] = function(token) {
203
+ var i, len = arguments.length;
204
+
205
+ for (i = 0; i < len; i++) {
206
+ token = arguments[i];
207
+ original.call(this, token);
208
+ }
209
+ };
210
+ };
211
+ createMethod('add');
212
+ createMethod('remove');
213
+ }
214
+
215
+ testElement.classList.toggle("c3", false);
216
+
217
+ // Polyfill for IE 10 and Firefox <24, where classList.toggle does not
218
+ // support the second argument.
219
+ if (testElement.classList.contains("c3")) {
220
+ var _toggle = DOMTokenList.prototype.toggle;
221
+
222
+ DOMTokenList.prototype.toggle = function(token, force) {
223
+ if (1 in arguments && !this.contains(token) === !force) {
224
+ return force;
225
+ } else {
226
+ return _toggle.call(this, token);
227
+ }
228
+ };
229
+
230
+ }
231
+
232
+ testElement = null;
233
+ }());
234
+
235
+ }
236
+
237
+ }
238
+
@@ -1,5 +1,4 @@
1
1
  var bean = require('bean')
2
- var classie = require('classie')
3
2
 
4
3
  require('compose-tap-event')
5
4
 
@@ -1,6 +1,5 @@
1
1
  var bean = require('bean')
2
2
  var CodeMirror = require('codemirror')
3
- var classie = require('classie')
4
3
  var Toggler = require('./toggler')
5
4
  var Messages = require('./messages')
6
5
  var AutoNavigate = require('./auto-navigate')
@@ -22,7 +21,6 @@ module.exports = {
22
21
  Timeago: Timeago,
23
22
  TimeSwitch: TimeSwitch,
24
23
  CodeMirror: CodeMirror,
25
- Classie: classie,
26
24
  Toggler: Toggler,
27
25
  Messages: Messages,
28
26
  AutoNavigate: AutoNavigate,
@@ -53,9 +51,9 @@ module.exports = {
53
51
  var lang = element.className.match(/lang.*?-(\S+)/)[1]
54
52
 
55
53
  // Standardize classes: lang-[language]
56
- if (classie.has(element, 'language-'+lang)) {
57
- classie.remove(element, 'language-'+lang)
58
- classie.add(element, 'lang-'+lang)
54
+ if (element.classList.contains('language-'+lang)) {
55
+ element.classList.remove('language-'+lang)
56
+ element.classList.add('lang-'+lang)
59
57
  }
60
58
  var code = element.textContent.trim()
61
59
 
@@ -66,7 +64,7 @@ module.exports = {
66
64
 
67
65
  CodeMirror.runMode(code, aliasLang(lang), element, options)
68
66
  element.innerHTML = "<code class='highlighted-code static-code cm-s-default'>" + element.innerHTML + "</code>"
69
- classie.add(element, 'highlighted')
67
+ element.classList.add('highlighted')
70
68
  }
71
69
  },
72
70
 
@@ -100,7 +98,7 @@ module.exports = {
100
98
  var type = flash.dataset.type || 'error'
101
99
  if (type == 'info') type = 'action'
102
100
  notify[type](flash.textContent.trim())
103
- classie.add(flash, 'hidden')
101
+ flash.classList.add('hidden')
104
102
  }
105
103
  },
106
104
 
@@ -1,7 +1,6 @@
1
1
  var bean = require('bean')
2
2
 
3
3
  require('compose-tap-event')
4
- require('compose-dataset-shim')
5
4
 
6
5
  var RangeInputHelper = {
7
6
  listen: function(){
@@ -1,10 +1,7 @@
1
1
  var timeago = require('./timeago')
2
2
  var dateToHtml = require('./date-to-html')
3
- var classie = require('classie')
4
3
  var bean = require('bean')
5
4
 
6
- require('compose-dataset-shim')
7
-
8
5
  var TimeSwitch = {
9
6
 
10
7
  // Attach listeners, setup HTML templates
@@ -19,7 +16,7 @@ var TimeSwitch = {
19
16
  var timeagoPosition = el.dataset.timeago
20
17
  var timeagoStyle = el.dataset.timeagoStyle
21
18
  el.innerHTML = TimeSwitch.template(datetime, timeagoPosition, timeagoStyle)
22
- classie.add(el, 'time-switch')
19
+ el.classList.add('time-switch')
23
20
  el.setAttribute('title', 'toggle timezones')
24
21
  })
25
22
  },
@@ -35,7 +32,7 @@ var TimeSwitch = {
35
32
  var timeEls = document.querySelectorAll('.time-switch')
36
33
 
37
34
  Array.prototype.forEach.call(timeEls, function(el) {
38
- classie.toggle(el, 'alt-zone')
35
+ el.classList.toggle('alt-zone')
39
36
  })
40
37
  },
41
38
 
@@ -1,9 +1,6 @@
1
1
  var bean = require('bean')
2
- var classie = require('classie')
3
- var _ = require('lodash')
4
2
 
5
3
  require('compose-tap-event')
6
- require('compose-dataset-shim')
7
4
 
8
5
  var Toggler = {
9
6
  checkboxSelector: "[type=checkbox][data-toggle], [type=checkbox][data-show], [type=checkbox][data-hide]",
@@ -68,7 +65,7 @@ var Toggler = {
68
65
 
69
66
  setClass: function (selectors, action, el){
70
67
  if (typeof(action) == 'boolean') {
71
- action = (action ? 'addClass' : 'removeClass')
68
+ action = (action ? 'add' : 'remove')
72
69
  }
73
70
 
74
71
  // Get selector and classnames, format: "classname classname; selector,selector"
@@ -85,8 +82,9 @@ var Toggler = {
85
82
  }
86
83
 
87
84
  Array.prototype.forEach.call(matches, function(match){
85
+ action = action.replace(/Class/,'')
88
86
  Array.prototype.forEach.call(classnames.split(' '), function(classname) {
89
- classie[action](match, classname)
87
+ match.classList[action](classname)
90
88
  })
91
89
  })
92
90
  },
@@ -113,8 +111,8 @@ var Toggler = {
113
111
  },
114
112
 
115
113
  show: function togglerShow(el) {
116
- classie.remove(el, 'hidden')
117
- classie.add(el, 'visible')
114
+ el.classList.remove('hidden')
115
+ el.classList.add('visible')
118
116
 
119
117
  // Focus on key element if an element expects focus
120
118
  var focusEl = el.querySelector('[data-focus]')
@@ -131,8 +129,8 @@ var Toggler = {
131
129
  },
132
130
 
133
131
  hide: function togglerHide(el) {
134
- classie.remove(el, 'visible')
135
- classie.add(el, 'hidden')
132
+ el.classList.remove('visible')
133
+ el.classList.add('hidden')
136
134
  },
137
135
 
138
136
  toggleRadios: function togglerToggleRadio(radios) {
@@ -171,7 +169,7 @@ var Toggler = {
171
169
  if (checkbox.dataset.removeClass)
172
170
  Toggler.setClass(checkbox.dataset.removeClass, !checkbox.checked, checkbox)
173
171
  if (checkbox.dataset.toggleClass)
174
- Toggler.setClass(checkbox.dataset.toggleClass, 'toggleClass', checkbox)
172
+ Toggler.setClass(checkbox.dataset.toggleClass, 'toggle', checkbox)
175
173
  if (checkbox.dataset.addClass)
176
174
  Toggler.setClass(checkbox.dataset.addClass, checkbox.checked, checkbox)
177
175
  },
@@ -200,14 +198,14 @@ var Toggler = {
200
198
  if (!option.dataset.hide) {
201
199
 
202
200
  var select = Toggler.getSelectFromOption(option)
203
- classie.add(select, 'select-toggler')
201
+ select.classList.add('select-toggler')
204
202
  var options = select.querySelectorAll('option')
205
203
  var selectors = Toggler.showAttributes(options)
206
204
 
207
205
  Array.prototype.forEach.call(options, function(o) {
208
- option.dataset.hide = _.compact(selectors.filter(function(selector){
206
+ option.dataset.hide = selectors.filter(function(selector){
209
207
  return option.dataset.show != selector && selector != ""
210
- })).join(',')
208
+ }).join(',')
211
209
  })
212
210
 
213
211
  // Ensure that currently selected option is toggled properly