lsd_rails 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/Packages/Sheet.js/Source/SheetParser.Value.js +1 -1
  2. data/Packages/lsd/Source/Action/Clone.js +2 -12
  3. data/Packages/lsd/Source/Action/Delete.js +1 -7
  4. data/Packages/lsd/Source/Action/Display.js +7 -7
  5. data/Packages/lsd/Source/Action/Edit.js +2 -2
  6. data/Packages/lsd/Source/Action/Invoke.js +2 -2
  7. data/Packages/lsd/Source/Action/Submit.js +2 -0
  8. data/Packages/lsd/Source/Action/Toggle.js +4 -0
  9. data/Packages/lsd/Source/Action/Update.js +2 -1
  10. data/Packages/lsd/Source/Action.js +4 -5
  11. data/Packages/lsd/Source/Document.js +10 -7
  12. data/Packages/lsd/Source/LSD.js +22 -127
  13. data/Packages/lsd/Source/Layer.js +4 -4
  14. data/Packages/lsd/Source/Layout.js +1077 -259
  15. data/Packages/lsd/Source/Mixin/Animation.js +1 -1
  16. data/Packages/lsd/Source/Mixin/Choice.js +2 -2
  17. data/Packages/lsd/Source/Mixin/Command.js +26 -8
  18. data/Packages/lsd/Source/Mixin/ContentEditable.js +2 -1
  19. data/Packages/lsd/Source/{Trait → Mixin}/Date.js +21 -11
  20. data/Packages/lsd/Source/{Trait/Menu.js → Mixin/Details.js} +6 -1
  21. data/Packages/lsd/Source/Mixin/Draggable.js +1 -1
  22. data/Packages/lsd/Source/Mixin/Fieldset.js +51 -49
  23. data/Packages/lsd/Source/Mixin/Focusable.js +38 -39
  24. data/Packages/lsd/Source/Mixin/Invokable.js +13 -14
  25. data/Packages/lsd/Source/Mixin/List.js +9 -17
  26. data/Packages/lsd/Source/Mixin/Placeholder.js +2 -7
  27. data/Packages/lsd/Source/Mixin/Request.js +5 -3
  28. data/Packages/lsd/Source/Mixin/Resizable.js +3 -3
  29. data/Packages/lsd/Source/Mixin/Resource.js +1 -1
  30. data/Packages/lsd/Source/Mixin/Root.js +17 -1
  31. data/Packages/lsd/Source/Mixin/Scrollable.js +1 -1
  32. data/Packages/lsd/Source/{Trait → Mixin}/Slider.js +0 -0
  33. data/Packages/lsd/Source/Mixin/Sortable.js +2 -2
  34. data/Packages/lsd/Source/Mixin/Submittable.js +2 -1
  35. data/Packages/lsd/Source/Mixin/Target.js +11 -6
  36. data/Packages/lsd/Source/Mixin/Touchable.js +2 -2
  37. data/Packages/lsd/Source/Mixin/Unselectable.js +1 -1
  38. data/Packages/lsd/Source/Mixin/Uploader.js +11 -13
  39. data/Packages/lsd/Source/Mixin/Validity.js +35 -9
  40. data/Packages/lsd/Source/Mixin/Value.js +5 -3
  41. data/Packages/lsd/Source/Module/Accessories/Attributes.js +90 -89
  42. data/Packages/lsd/Source/Module/Accessories/Chain.js +40 -25
  43. data/Packages/lsd/Source/Module/Accessories/Element.js +59 -58
  44. data/Packages/lsd/Source/Module/Accessories/Events.js +25 -10
  45. data/Packages/lsd/Source/Module/Accessories/Options.js +11 -13
  46. data/Packages/lsd/Source/Module/Accessories/States.js +42 -5
  47. data/Packages/lsd/Source/Module/Accessories/Styles.js +1 -1
  48. data/Packages/lsd/Source/Module/Accessories/Tag.js +21 -7
  49. data/Packages/lsd/Source/Module/Ambient/Allocations.js +178 -64
  50. data/Packages/lsd/Source/Module/Ambient/DOM.js +98 -55
  51. data/Packages/lsd/Source/Module/Ambient/Expectations.js +57 -8
  52. data/Packages/lsd/Source/Module/Ambient/Interpolations.js +147 -0
  53. data/Packages/lsd/Source/Module/Ambient/Layout.js +52 -15
  54. data/Packages/lsd/Source/Module/Ambient/Proxies.js +44 -36
  55. data/Packages/lsd/Source/Module/Ambient/Relations.js +3 -1
  56. data/Packages/lsd/Source/Module/Ambient/Selectors.js +3 -3
  57. data/Packages/lsd/Source/Module/Ambient.js +2 -2
  58. data/Packages/lsd/Source/Module/Graphics/Layers.js +1 -1
  59. data/Packages/lsd/Source/Module/Graphics/Render.js +1 -1
  60. data/Packages/lsd/Source/Relation.js +19 -20
  61. data/Packages/lsd/Source/Sheet.js +4 -5
  62. data/Packages/lsd/Source/{Behavior.js → Tools/Behavior.js} +0 -0
  63. data/Packages/lsd/Source/Tools/Command.js +190 -0
  64. data/Packages/lsd/Source/Tools/Helpers.js +109 -0
  65. data/Packages/lsd/Source/Tools/Interpolation.js +351 -0
  66. data/Packages/lsd/Source/Tools/Microdata.js +75 -0
  67. data/Packages/lsd/Source/Tools/Object.js +192 -0
  68. data/Packages/lsd/Source/Tools/Position.js +208 -0
  69. data/Packages/lsd/Source/Tools/Require.js +76 -0
  70. data/Packages/lsd/Source/Type.js +2 -2
  71. data/Packages/lsd/package.yml +11 -7
  72. data/Packages/lsd-mobile/Source/Body/Dialog.js +2 -2
  73. data/Packages/lsd-mobile/Source/Input/Date.js +9 -84
  74. data/Packages/lsd-native/Source/Input/Checkbox.js +4 -4
  75. data/Packages/lsd-native/Source/Input/Date.js +46 -6
  76. data/Packages/lsd-native/Source/Input/Radio.js +1 -4
  77. data/Packages/lsd-native/Source/Input.js +5 -6
  78. data/Packages/lsd-widgets/Source/Body/Dialog.js +9 -6
  79. data/Packages/lsd-widgets/Source/Body/Page.js +1 -1
  80. data/Packages/lsd-widgets/Source/Body.js +1 -1
  81. data/Packages/lsd-widgets/Source/Button.js +1 -1
  82. data/Packages/lsd-widgets/Source/Form.js +1 -1
  83. data/Packages/lsd-widgets/Source/Input/Checkbox.js +2 -2
  84. data/Packages/lsd-widgets/Source/Input/Date.js +45 -16
  85. data/Packages/lsd-widgets/Source/Input/File.js +2 -2
  86. data/Packages/lsd-widgets/Source/Input/HTML.js +2 -2
  87. data/Packages/lsd-widgets/Source/Input/Radio.js +1 -1
  88. data/Packages/lsd-widgets/Source/Input/Range.js +2 -2
  89. data/Packages/lsd-widgets/Source/Input/Submit.js +1 -1
  90. data/Packages/lsd-widgets/Source/Input.js +2 -11
  91. data/Packages/lsd-widgets/Source/Label.js +4 -8
  92. data/Packages/lsd-widgets/Source/Menu/List.js +3 -3
  93. data/Packages/lsd-widgets/Source/Menu.js +2 -2
  94. data/Packages/lsd-widgets/Source/Progress.js +1 -1
  95. data/Packages/lsd-widgets/Source/Select.js +7 -6
  96. data/Packages/lsd-widgets/Source/Table/Calendar.js +41 -15
  97. data/Packages/lsd-widgets/Source/Table.js +7 -2
  98. data/Packages/mootools-ext/Source/Core/Class.Mixin.js +43 -38
  99. data/Packages/mootools-ext/Source/Core/Class.States.js +26 -22
  100. data/Packages/mootools-ext/Source/Element/Element.from.js +1 -1
  101. data/Packages/mootools-ext/Source/Element/Properties/Item.js +1 -2
  102. data/Packages/mootools-ext/Source/Request/Request.Statuses.js +9 -7
  103. data/Packages/mootools-ext/Source/Types/{FastArray.js → Object.Array.js} +8 -14
  104. data/Packages/mootools-ext/package.yml +1 -2
  105. data/lib/lsd.rake +28 -0
  106. metadata +15 -11
  107. data/Packages/lsd/Source/Command.js +0 -135
  108. data/Packages/lsd/Source/Interpolation.js +0 -103
  109. data/Packages/lsd/Source/Module/Ambient/Container.js +0 -56
  110. data/Packages/mootools-ext/Source/Element/Element.onDispose.js +0 -36
@@ -78,4 +78,4 @@ LSD.Mixin.Resource = new Class({
78
78
  }
79
79
  });
80
80
 
81
- LSD.Behavior.define(':resource, [itemscope]', LSD.Mixin.Resource);
81
+ LSD.Behavior.define(':resource, [itemscope]', 'resource');
@@ -25,17 +25,33 @@ LSD.Mixin.Root = new Class({
25
25
  node.root = this;
26
26
  node.fireEvent('setRoot', this);
27
27
  node.fireEvent('register', ['root', this]);
28
+ node.fireEvent('relate', [this, 'root']);
28
29
  },
29
30
  nodeRemoved: function(node) {
30
31
  if (node.root == this) {
31
32
  node.fireEvent('unsetRoot', this);
32
33
  node.fireEvent('unregister', ['root', this]);
34
+ node.fireEvent('unrelate', [this, 'root']);
33
35
  delete node.root;
34
36
  }
35
37
  }
36
38
  }
37
39
  }
40
+ },
41
+
42
+ onMix: function() {
43
+ this.root = this;
44
+ this.fireEvent('setRoot', this);
45
+ this.fireEvent('relate', [this, 'root']);
46
+ this.fireEvent('register', ['root', this]);
47
+ },
48
+
49
+ onUnmix: function() {
50
+ delete this.root;
51
+ this.fireEvent('unsetRoot', this);
52
+ this.fireEvent('unregister', ['root', this]);
53
+ this.fireEvent('unrelate', [this, 'root']);
38
54
  }
39
55
  });
40
56
 
41
- LSD.Behavior.define(':root', LSD.Mixin.Root);
57
+ LSD.Behavior.define(':root', 'root');
@@ -66,4 +66,4 @@ LSD.Mixin.Scrollable = new Class({
66
66
  })
67
67
  });
68
68
 
69
- LSD.Behavior.define('[scrollable]', LSD.Mixin.Scrollable);
69
+ LSD.Behavior.define('[scrollable]', 'scrollable');
File without changes
@@ -27,7 +27,7 @@ LSD.Mixin.Sortable = new Class({
27
27
  constrain: true,
28
28
  revert: true
29
29
  },
30
- pseudos: Array.fast('activatable'),
30
+ pseudos: Array.object('activatable'),
31
31
  events: {
32
32
  self: {
33
33
  mousedown: 'onBeforeSortStart'
@@ -131,4 +131,4 @@ LSD.Mixin.Sortable = new Class({
131
131
 
132
132
  });
133
133
 
134
- LSD.Behavior.define(':sortable', LSD.Mixin.Sortable);
134
+ LSD.Behavior.define(':sortable', 'sortable');
@@ -41,6 +41,7 @@ LSD.Mixin.Submittable = new Class({
41
41
  },
42
42
 
43
43
  submit: function(event) {
44
+ this.fireEvent('beforeSubmit', arguments);
44
45
  if (event && event.type == 'submit' && event.target == this.element)
45
46
  event.preventDefault();
46
47
  var submission = this.captureEvent('submit', arguments);
@@ -61,4 +62,4 @@ LSD.Mixin.Submittable = new Class({
61
62
  }
62
63
  });
63
64
 
64
- LSD.Behavior.define(':submittable', LSD.Mixin.Submittable);
65
+ LSD.Behavior.define(':submittable', 'submittable');
@@ -26,12 +26,17 @@ provides:
26
26
  target: function() {
27
27
  if (!this.attributes.target) return;
28
28
  return this.parseTargetSelector(this.attributes.target).map(function(chain) {
29
- if (!chain.action) chain.action = this.getTargetAction();
30
- if (!chain.action) return;
29
+ chain = Object.append({}, chain);
30
+ if (!chain.action && !(chain.action = this.getTargetAction())) return;
31
31
  if (chain.selector) {
32
- chain.target = function() {
33
- return this.getElements(chain.selector);
34
- }.bind(this);
32
+ chain.target = function(callback, state, revert) {
33
+ if (chain.selector.expressions[0][0].combinator.charAt(0) != '$') {
34
+ this[(state == true && revert) ? 'unwatch' : 'watch'](chain.selector, callback);
35
+ return true;
36
+ } else {
37
+ return this.getElements(chain.selector);
38
+ }
39
+ }.bind(this)
35
40
  };
36
41
  switch (chain.keyword) {
37
42
  case "before":
@@ -96,7 +101,7 @@ provides:
96
101
  }
97
102
  };
98
103
 
99
- var Keywords = Parser.Keywords = Array.fast('if', 'then', 'else', 'or', 'and', 'before');
104
+ var Keywords = Parser.Keywords = Array.object('if', 'then', 'else', 'or', 'and', 'before', 'do');
100
105
  }();
101
106
 
102
107
  LSD.Behavior.define('[target]', LSD.Mixin.Target);
@@ -34,8 +34,8 @@ LSD.Mixin.Touchable = new Class({
34
34
  }
35
35
  }
36
36
  },
37
- states: Array.fast('active')
37
+ states: Array.object('active')
38
38
  }
39
39
  });
40
40
 
41
- LSD.Behavior.define(':touchable', LSD.Mixin.Touchable);
41
+ LSD.Behavior.define(':touchable', 'touchable');
@@ -32,4 +32,4 @@ LSD.Mixin.Unselectable = new Class({
32
32
  }
33
33
  });
34
34
 
35
- LSD.Behavior.define(':unselectable', LSD.Mixin.Unselectable);
35
+ LSD.Behavior.define(':unselectable', 'unselectable');
@@ -61,7 +61,7 @@ LSD.Mixin.Uploader = new Class({
61
61
  }
62
62
  }
63
63
  },
64
- states: Array.fast('empty'),
64
+ states: Array.object('empty'),
65
65
  filelist: false,
66
66
  uploader: {
67
67
  instantStart: true,
@@ -71,10 +71,8 @@ LSD.Mixin.Uploader = new Class({
71
71
  }
72
72
  },
73
73
 
74
- constructors: {
75
- uploader: function() {
76
- this.blobs = {};
77
- }
74
+ onMix: function() {
75
+ this.blobs = {};
78
76
  },
79
77
 
80
78
  getUploader: function() {
@@ -176,7 +174,7 @@ LSD.Mixin.Uploader = new Class({
176
174
  addFile: function(blob) {
177
175
  var widget = new (this.getUploaderFileClass());
178
176
  widget.widget = this;
179
- widget.setState('complete');
177
+ widget.states.add('complete');
180
178
  widget.build();
181
179
  widget.setBase(this.getUploader());
182
180
  widget.setFile(blob);
@@ -206,15 +204,15 @@ LSD.Mixin.Upload = new Class({
206
204
  if (this.progress) this.progress.set(progress.percentLoaded);
207
205
  },
208
206
  start: function() {
209
- this.setState('started');
207
+ this.states.add('started');
210
208
  },
211
209
  complete: function() {
212
210
  if (this.progress) this.progress.set(100);
213
- this.unsetState('started');
214
- this.setState('complete');
211
+ this.states.remove('started');
212
+ this.states.add('complete');
215
213
  },
216
214
  stop: function() {
217
- this.unsetState('started');
215
+ this.states.remove('started');
218
216
  },
219
217
  remove: 'dispose'
220
218
  }
@@ -253,7 +251,7 @@ LSD.Widget.Filelist.File = new Class({
253
251
  '::canceller': 'Cancel',
254
252
  '::progress': true
255
253
  },
256
- pseudos: Array.fast('upload'),
254
+ pseudos: Array.object('upload'),
257
255
  events: {
258
256
  setFile: function() {
259
257
  this.write(this.name);
@@ -273,5 +271,5 @@ LSD.Widget.Filelist.File = new Class({
273
271
  }
274
272
  });
275
273
 
276
- LSD.Behavior.define(':uploader', LSD.Mixin.Uploader);
277
- LSD.Behavior.define(':upload', LSD.Mixin.Upload);
274
+ LSD.Behavior.define(':uploader', 'uploader');
275
+ LSD.Behavior.define(':upload', 'upload');
@@ -35,15 +35,19 @@ provides:
35
35
  !function() {
36
36
 
37
37
  LSD.Mixin.Validity = new Class({
38
- initialize: function() {
39
- this.parent.apply(this, arguments);
40
- this.addClass(this.attributes.required ? 'required' : 'optional');
38
+ onMix: function() {
39
+ this.states.add(this.attributes.required ? 'required' : 'optional');
40
+ this.addEvents(LSD.Mixin.Validity.events);
41
+ },
42
+
43
+ onUnmix: function() {
44
+ this.removeEvents(LSD.Mixin.Validity.events)
41
45
  },
42
46
 
43
47
  checkValidity: function() {
44
48
  var validity = this.validity = {};
45
49
  var value = this.getValue();
46
- for (attribute in Attributes) {
50
+ for (var attribute in Attributes) {
47
51
  var constraint = this.attributes[attribute]
48
52
  if (!constraint) continue;
49
53
  var result = Attributes[attribute].call(this, value, constraint)
@@ -56,23 +60,45 @@ LSD.Mixin.Validity = new Class({
56
60
 
57
61
  validate: function(value) {
58
62
  if (value !== true && !this.checkValidity()) return false;
59
- this.setStateTo('valid', true);
60
- this.setStateTo('invalid', false);
63
+ if (this.invalid) this.setStateTo('invalid', false, arguments);
64
+ if (!this.valid) this.setStateTo('valid', true, arguments);
61
65
  return true;
62
66
  },
63
67
 
64
68
  invalidate: function(value) {
65
- this.setStateTo('invalid', true);
66
- this.setStateTo('valid', false);
69
+ if (this.valid) this.setStateTo('valid', false, arguments);
70
+ if (!this.invalid) this.setStateTo('invalid', true, arguments);
67
71
  return true;
68
72
  },
69
73
 
74
+ unvalidate: function() {
75
+ if (this.valid) this.setStateTo('valid', false);
76
+ if (this.invalid) this.setStateTo('invalid', false);
77
+ },
78
+
70
79
  setCustomValidity: function(validity) {
71
80
  this.validationMessage = validity;
72
81
  this.validity.customError = true;
73
82
  }
74
83
  });
75
84
 
85
+ LSD.Mixin.Validity.events = {
86
+ invalidate: function(message) {
87
+ this.allocate('message', message, 'error', LSD.Mixin.Validity.message)
88
+ },
89
+
90
+ unvalidate: function() {
91
+ this.release('message');
92
+ }
93
+ };
94
+
95
+ LSD.Mixin.Validity.message = {
96
+ position: ['top', 'left'],
97
+ parent: function() {
98
+ return document.body
99
+ }
100
+ };
101
+
76
102
  var Attributes = LSD.Mixin.Validity.Attributes = {
77
103
  required: function(value) {
78
104
  if (!value) return "valueMissing"
@@ -97,6 +123,6 @@ var Attributes = LSD.Mixin.Validity.Attributes = {
97
123
  }
98
124
  }
99
125
 
100
- LSD.Behavior.define('[name], :value', LSD.Mixin.Validity);
126
+ LSD.Behavior.define('[name], :value', 'validity');
101
127
 
102
128
  }();
@@ -37,13 +37,14 @@ LSD.Mixin.Value = new Class({
37
37
 
38
38
  setValue: function(value, unset) {
39
39
  if (value == null || (value.event && value.type)) value = this.getDefaultValue();
40
+
40
41
  else if (value.getValue) value = this.processValue(value.getValue());
41
42
  var result = false;
42
43
  if (this.isValueDifferent(value) ^ unset) {
43
44
  result = this.writeValue(value, unset);
44
45
  var previous = this.getPreviousValue();
45
46
  this.fireEvent('change', [value, previous]);
46
- if (!this.click) this.callChain(value, previous);
47
+ if (!this.click && previous != null) this.callChain(value, previous);
47
48
  }
48
49
  return result
49
50
  },
@@ -105,7 +106,8 @@ LSD.Mixin.Value = new Class({
105
106
  },
106
107
 
107
108
  getDefaultValue: function() {
108
- return this.processValue(this.getRawValue());
109
+ var value = this.getRawValue();
110
+ if (value != null) return this.processValue(value);
109
111
  },
110
112
 
111
113
  getRawValue: function() {
@@ -157,4 +159,4 @@ LSD.Mixin.Value = new Class({
157
159
  }
158
160
  });
159
161
 
160
- LSD.Behavior.define(':value', LSD.Mixin.Value);
162
+ LSD.Behavior.define(':value', 'value');
@@ -11,6 +11,7 @@ authors: Yaroslaff Fedin
11
11
 
12
12
  requires:
13
13
  - LSD.Module
14
+ - LSD.Object
14
15
  - Core/Slick.Parser
15
16
 
16
17
  provides:
@@ -22,10 +23,31 @@ provides:
22
23
  LSD.Module.Attributes = new Class({
23
24
  constructors: {
24
25
  attributes: function() {
25
- this.classes = new FastArray;
26
- this.pseudos = new FastArray;
27
- this.dataset = {};
28
- this.attributes = {};
26
+ var self = this;
27
+ this.pseudos = (new LSD.Object.Stack).addEvent('change', function(name, value, state, old, memo) {
28
+ if (!memo && LSD.States[name]) self.states[state ? 'add' : 'remove'](name, 'pseudos');
29
+ self.fireEvent('selectorChange', ['pseudos', name, state]);
30
+ })
31
+ this.classes = (new LSD.Object.Stack).addEvent('change', function(name, value, state, old, memo) {
32
+ if (!memo && LSD.States[name]) self.states[state ? 'add' : 'remove'](name, 'classes');
33
+ if (self.element) self.element[state ? 'addClass' : 'removeClass'](name);
34
+ self.fireEvent('selectorChange', ['classes', name, state]);
35
+ });
36
+ this.attributes = (new LSD.Object.Stack).addEvent('change', function(name, value, state, old, memo) {
37
+ if (!memo && LSD.States[name]) self.states[state ? 'add' : 'remove'](name, 'attributes');
38
+ value = LSD.Module.Attributes.resolve(name, value, self);
39
+ if (self.element && (name != 'type' || LSD.toLowerCase(self.element.tagName) != 'input')) {
40
+ if (state) self.element.setAttribute(name, LSD.Attributes[name] == 'boolean' ? name : value);
41
+ else self.element.removeAttribute(name);
42
+ if (LSD.Attributes[name] == 'boolean') self.element[name] = state;
43
+ }
44
+ self.fireEvent('selectorChange', ['attributes', name, state]);
45
+ return value;
46
+ }).addEvent('beforechange', function(name, value, state) {
47
+ self.fireEvent('selectorChange', ['attributes', name, state]);
48
+ });
49
+ this.storage = new LSD.Object;
50
+ this.dataset = new LSD.Object;
29
51
  }
30
52
  },
31
53
 
@@ -36,80 +58,40 @@ LSD.Module.Attributes = new Class({
36
58
  default: return this.attributes[attribute];
37
59
  }
38
60
  },
39
-
40
- removeAttribute: function(name) {
41
- if (name.substring(0, 5) == 'data') {
42
- delete this.dataset[name.substring(5, name.length - 5)];
43
- } else if (this.attributes[name] != null) {
44
- this.fireEvent('selectorChange', ['attributes', name, false]);
45
- delete this.attributes[name];
46
- if (this.element) this.element.removeAttribute(name);
47
- if (LSD.States.Attributes[name])
48
- if (this[name]) this.setStateTo(name, false);
49
- }
50
- return this;
51
- },
52
61
 
53
62
  setAttribute: function(name, value) {
54
- if (LSD.Attributes.Numeric[name]) value = value.toInt();
55
- else {
56
- var logic = LSD.Attributes.Setter[name];
57
- if (logic) logic.call(this, value)
58
- }
59
- if (name.substring(0, 5) == 'data-') {
60
- this.dataset[name.substring(5, name.length - 5)] = value;
63
+ if (name.substr(0, 5) == 'data-') {
64
+ this.dataset.set(name.substring(5), value);
61
65
  } else {
62
- if (this.options && this.options.interpolate)
63
- value = LSD.Interpolation.attempt(value, this.options.interpolate) || value;
64
- if (this.attributes[name] != value) {
65
- if (LSD.States.Attributes[name]) {
66
- var mode = (value == true || value == name);
67
- if (this[name] != mode) this.setStateTo(name, mode);
68
- }
69
- this.fireEvent('selectorChange', ['attributes', name, false]);
70
- this.attributes[name] = value;
71
- this.fireEvent('selectorChange', ['attributes', name, true]);
72
- if (this.element && this.element[name] != value) this.element.setAttribute(name, value);
73
- }
66
+ this.attributes.set(name, value);
74
67
  }
75
68
  return this;
76
69
  },
77
-
70
+
71
+ removeAttribute: function(name) {
72
+ if (name.substr(0, 5) == 'data-') {
73
+ delete this.dataset.unset(name.substring(5));
74
+ } else this.attributes.unset(name, this.attributes[name]);
75
+ return this;
76
+ },
77
+
78
78
  addPseudo: function(name){
79
- if (!this.pseudos[name]) {
80
- if (this.$states[name]) this.setStateTo(name, true);
81
- this.pseudos[name] = true;
82
- this.fireEvent('selectorChange', ['pseudos', name, true]);
83
- }
79
+ this.pseudos.set(name, true);
84
80
  return this;
85
81
  },
86
82
 
87
83
  removePseudo: function(name) {
88
- if (this.pseudos[name]) {
89
- if (this.$states[name]) this.setStateTo(name, false);
90
- this.fireEvent('selectorChange', ['pseudos', name, false]);
91
- delete this.pseudos[name];
92
- }
84
+ this.pseudos.unset(name, true);
93
85
  return this;
94
86
  },
95
87
 
96
88
  addClass: function(name) {
97
- if (LSD.States.Classes[name] && !this[name]) this.setStateTo(name, true);
98
- if (!this.classes[name]) {
99
- this.classes[name] = true;
100
- this.fireEvent('selectorChange', ['classes', name, true]);
101
- if (this.element) this.element.addClass(name);
102
- }
89
+ this.classes.set(name, true);
103
90
  return this;
104
91
  },
105
92
 
106
93
  removeClass: function(name){
107
- if (LSD.States.Classes[name] && this[name]) return this.setStateTo(name, false);
108
- if (this.classes[name]) {
109
- this.fireEvent('selectorChange', ['classes', name, false]);
110
- delete this.classes[name];
111
- if (this.element) this.element.removeClass(name);
112
- }
94
+ this.classes.unset(name, true);
113
95
  return this;
114
96
  },
115
97
 
@@ -117,51 +99,52 @@ LSD.Module.Attributes = new Class({
117
99
  return this.classes[name]
118
100
  },
119
101
 
120
- setState: function(name) {
121
- var attribute = LSD.States.Attributes[name];
122
- if (attribute) this.setAttribute(attribute, attribute)
123
- else this.addClass(LSD.States.Classes[name] || 'is-' + name);
124
- this.addPseudo(name);
125
- return this;
126
- },
127
-
128
- unsetState: function(name) {
129
- var attribute = LSD.States.Attributes[name];
130
- if (attribute) this.removeAttribute(attribute);
131
- else this.removeClass(LSD.States.Classes[name] || 'is-' + name);
132
- this.removePseudo(name);
133
- return this;
134
- },
135
-
136
- getSelector: function(){
102
+ getSelector: function() {
137
103
  var parent = this.parentNode;
138
104
  var selector = (parent && parent.getSelector) ? parent.getSelector() + ' ' : '';
139
105
  selector += this.tagName;
140
106
  if (this.attributes.id) selector += '#' + this.attributes.id;
141
- for (var klass in this.classes) if (this.classes.hasOwnProperty(klass)) selector += '.' + klass;
142
- for (var pseudo in this.pseudos) if (this.pseudos.hasOwnProperty(pseudo)) selector += ':' + pseudo;
143
- for (var name in this.attributes) if (name != 'id') selector += '[' + name + '=' + this.attributes[name] + ']';
107
+ for (var klass in this.classes) if (this.classes.has(klass)) selector += '.' + klass;
108
+ for (var pseudo in this.pseudos) if (this.pseudos.has(pseudo)) selector += ':' + pseudo;
109
+ for (var name in this.attributes) if (this.attributes.has(name))
110
+ if (name != 'id') {
111
+ selector += '[' + name;
112
+ if (LSD.Attributes[name] != 'boolean') selector += '=' + this.attributes[name]
113
+ selector += ']';
114
+ }
144
115
  return selector;
145
116
  },
146
117
 
147
- onStateChange: function(state, value, args) {
148
- var args = Array.prototype.slice.call(arguments, 0);
149
- args.slice(1, 2); //state + args
150
- this[value ? 'setState' : 'unsetState'][args && ("length" in args) ? 'apply' : 'call'](this, args);
151
- this.fireEvent('stateChange', [state, args]);
152
- return true;
118
+ store: function(name, value) {
119
+ return this.storage.set(name, value);
120
+ },
121
+
122
+ retrieve: function(name, placeholder) {
123
+ var value = this.storage[name];
124
+ if (value == null) return placeholder
125
+ return value;
126
+ },
127
+
128
+ eliminate: function(name, value) {
129
+ return this.storage.unset(name, value)
153
130
  }
154
131
  });
155
132
 
156
-
157
- LSD.Attributes.Setter = {
158
- 'id': function(id) {
133
+ LSD.Module.Attributes.List = {
134
+ tabindex: 'number',
135
+ width: 'number',
136
+ height: 'number',
137
+ readonly: 'boolean',
138
+ disabled: 'boolean',
139
+ hidden: 'boolean',
140
+ checked: 'boolean',
141
+ id: function(id) {
159
142
  this.id = id;
160
143
  },
161
144
  'class': function(value) {
162
145
  value.split(' ').each(this.addClass.bind(this));
163
146
  },
164
- 'style': function(value) {
147
+ style: function(value) {
165
148
  value.split(/\s*;\s*/).each(function(definition) {
166
149
  var bits = definition.split(/\s*:\s*/)
167
150
  if (!bits[1]) return;
@@ -173,6 +156,24 @@ LSD.Attributes.Setter = {
173
156
  }
174
157
  };
175
158
 
159
+ Object.each(LSD.Module.Attributes.List, function(value, name) {
160
+ if (!LSD.Attributes[name]) LSD.Attributes[name] = value;
161
+ });
162
+
163
+ LSD.Module.Attributes.resolve = function(name, value, bind) {
164
+ var attribute = LSD.Attributes[name];
165
+ switch (attribute) {
166
+ case "boolean":
167
+ return (name == value || value === true);
168
+ case "number":
169
+ return parseFloat(name);
170
+ default:
171
+ if (attribute && attribute.call)
172
+ return attribute.call(bind || this, value)
173
+ }
174
+ return value;
175
+ };
176
+
176
177
  Object.append(LSD.Options, {
177
178
  attributes: {
178
179
  add: 'setAttribute',