Skip to content

Commit

Permalink
Delegate all params registering stuff from Fieldset to Object.Params
Browse files Browse the repository at this point in the history
Update slider mixin

Add value option

Fix proxies reordering bug when the parent widget doesnt have its own parent

Allow anonymous widget types.
  • Loading branch information
Inviz committed Nov 21, 2011
1 parent 479f36d commit 56fc0a2
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 57 deletions.
5 changes: 3 additions & 2 deletions Source/Layout.js
Expand Up @@ -727,7 +727,7 @@ LSD.Layout.prototype = Object.append({
`soft` parameter tells matcher to skip mutations
and only advance selectors instead.
*/
if (!result || !result.call || (result = result(element))) {
if (!result || !result.call || (result = result(element, parent[0] || parent))) {
if (!result) result = true;
if (result.push) {
(advanced || (advanced = [])).push(result);
Expand Down Expand Up @@ -951,7 +951,8 @@ LSD.Layout.prototype = Object.append({

getType: function(memo, parent) {
var context = this.getContext(memo, parent);
return LSD[LSD.toClassName(context)];
if (typeof context == 'string') return LSD[LSD.toClassName(context)];
return context;
},

getContext: function(memo, parent) {
Expand Down
6 changes: 0 additions & 6 deletions Source/Mixin/Command.js
Expand Up @@ -53,12 +53,6 @@ LSD.Mixin.Command = new Class({
if (arg != null) this.eachLink('quickstart', arg, true, !this.getCommandState());
}
}
},
helpers: {
click: {
click: 'click',
unclick: 'unclick'
}
}
},

Expand Down
25 changes: 9 additions & 16 deletions Source/Mixin/Fieldset.js
Expand Up @@ -49,8 +49,8 @@ LSD.Mixin.Fieldset = new Class({
fieldset: function(options, state) {
if (state) {
this.names = new LSD.Object.Stack;
this.fields = new LSD.Object.Stack;
this.params = new LSD.Object.Stack;
this.params = new LSD.Object.Params;
this.fields = new LSD.Object.Params;
}
this.variables[state ? 'merge' : 'unmerge']({params: this.params, fields: this.fields});
if (!state) {
Expand Down Expand Up @@ -131,13 +131,10 @@ LSD.Mixin.Fieldset = new Class({
var name = widget.attributes.name;
if (!name || !widget.toData) return;
this.names.set(name, widget);
var params = this.params, fields = this.fields;
for (var results = [], regex = Fieldset.rNameParser, match; match = regex.exec(name);)
results.push(match[1] || match[2]);
var index = results.join('.');
fields.set(index, widget);
if ((LSD.Mixin.Command.getCommandType.call(widget) == 'command') || widget.checked) params.set(index, widget.getValue());
var key = index + ':value:callback'
if ((LSD.Mixin.Command.getCommandType.call(widget) == 'command') || widget.checked)
this.params.set(name, widget.getValue())
this.fields.set(name, widget)
var key = widget.lsd + ':value:callback'
var callback = this.retrieve(key);
if (!callback) {
callback = function(value) {
Expand All @@ -163,12 +160,9 @@ LSD.Mixin.Fieldset = new Class({
var name = widget.attributes.name;
if (!name) return;
this.names.unset(name, widget);
var params = this.params, fields = this.fields;
for (var results = [], regex = Fieldset.rNameParser, match; match = regex.exec(name);)
results.push(match[1] || match[2]);
var index = results.join('.');
fields.unset(index, widget);
params.unset(index, widget.getValue());
if ((LSD.Mixin.Command.getCommandType.call(widget) == 'command') || widget.checked)
this.params.unset(name, widget.getValue())
this.fields.unset(name, widget)
var key = widget.lsd + ':value:callback'
var callback = this.retrieve(key);
if (callback) widget.removeEvent('change', callback);
Expand All @@ -193,7 +187,6 @@ LSD.Mixin.Fieldset = new Class({
var Fieldset = Object.append(LSD.Mixin.Fieldset, {
rNameIndexBumper: /(\[)(\d+?)(\])/,
rIdIndexBumper: /(_)(\d+?)(_|$)/,
rNameParser: /(^[^\[]+)|\[([^\]]*)\]/g,
rNameMultiplier: /(?:\[\])?$/,
rPrefixAppender: /^[^\[]+/,
getName: function(model, name) {
Expand Down
25 changes: 13 additions & 12 deletions Source/Mixin/Slider.js
Expand Up @@ -49,26 +49,27 @@ LSD.Trait.Slider = new Class({
if (this.slider) this.slider.update();
},

getSlider: Macro.getter('slider', function (update) {
var slider = new Slider(document.id(this.getTrack()), document.id(this.getTrackThumb()), Object.merge(this.options.slider, {
getSlider: function (update) {
if (this.slider) return this.slider;
this.slider = new Slider(document.id(this.getTrack()), document.id(this.getTrackThumb()), Object.merge(this.options.slider, {
mode: this.options.mode
})).set(parseFloat(this.options.value));
slider.addEvent('change', this.onSet.bind(this));
this.properties.set('slide', slider);
return slider;
}),
this.slider.addEvent('change', this.onSet.bind(this));
this.properties.set('slide', this.slider);
return this.slider;
},

onSet: Macro.defaults(function() {
onSet: function() {
return true;
}),
},

getTrack: Macro.defaults(function() {
getTrack: function() {
return this
}),
},

getTrackThumb: Macro.defaults(function() {
getTrackThumb: function() {
return this.thumb;
}),
},

increment: function() {
this.slider.set((this.slider.step || 0) + 10)
Expand Down
5 changes: 5 additions & 0 deletions Source/Mixin/Value.js
Expand Up @@ -161,6 +161,11 @@ LSD.Mixin.Value = new Class({
}
});

LSD.Options.value = {
add: 'setValue',
remove: 'unsetValue'
};

LSD.Mixin.Value.setValueOnCheck = function(value) {
if (value) this.setValue();
else this.unsetValue();
Expand Down
2 changes: 1 addition & 1 deletion Source/Module/Ambient/Layout.js
Expand Up @@ -34,7 +34,7 @@ LSD.Module.Layout = new Class({
constructors: {
layout: function(options) {
if (!options.document && !this.document)
this.properties.set('document', LSD.document || LSD.getCleanDocument());
this.properties.set('document', LSD.document || new LSD.Document);
this.layouts = {};
}
},
Expand Down
4 changes: 2 additions & 2 deletions Source/Module/Ambient/Proxies.js
Expand Up @@ -27,7 +27,7 @@ LSD.Module.Proxies = new Class({

addProxy: function(name, proxy) {
var selector = proxy.selector || proxy.mutation;
if (selector && selector !== true && selector.match(LSD.Module.Proxies.rOrdered))
if (selector && this.parentNode && selector !== true && selector.match(LSD.Module.Proxies.rOrdered))
var object = this.parentNode;
else
var object = this;
Expand All @@ -37,7 +37,7 @@ LSD.Module.Proxies = new Class({

removeProxy: function(name, proxy) {
var selector = proxy.selector || proxy.mutation;
if (selector && selector !== true && selector.match(LSD.Module.Proxies.rOrdered))
if (selector && this.parentNode && selector !== true && selector.match(LSD.Module.Proxies.rOrdered))
var object = this.parentNode;
else
var object = this;
Expand Down
9 changes: 1 addition & 8 deletions Source/Tools/Helpers.js
Expand Up @@ -96,14 +96,7 @@ Object.append(LSD, {
if (typeof object[identifier] != 'undefined') return object[identifier];
},

identifiers: ['id', '_id', '$id'],

getCleanDocument: function() {
return (LSD.Test.document || (LSD.Test.document = new LSD.Document(false)))
},
getCleanContext: function() {
return new LSD.Type('Clean')
}
identifiers: ['id', '_id', '$id']
});
LSD.Test = {};

Expand Down
29 changes: 19 additions & 10 deletions Source/Type.js
Expand Up @@ -26,16 +26,25 @@ provides:
*/

LSD.Type = function(name, namespace) {
this.name = name;
this.namespace = namespace || 'LSD';
var holder = Object.getFromPath(LSD.global, this.namespace);
if (this.storage = holder[name]) {
for (var key in this) {
this.storage[key] = (this[key].call) ? this[key].bind(this) : this[key];
}
}
else this.storage = (holder[name] = this);
if (typeOf(this.storage) == 'class') this.klass = this.storage;
if (name) {
this.name = name;
this.namespace = namespace || 'LSD';
var holder = Object.getFromPath(LSD.global, this.namespace);
if (typeof holder == 'undefined') throw "LSD.Type cant find namespace " + namespace
var storage = Object.getFromPath(holder, name);
if (storage) {
if (!storage.pool)
for (var key in this)
storage[key] = (this[key].call) ? this[key].bind(this) : this[key];
else storage = null;
} else
storage = (holder[name] = this);
} else {
storage = this;
}
this.storage = storage;
if (typeOf(this.storage) == 'class')
this.klass = this.storage;
this.pool = [this.storage];
this.queries = {};
};
Expand Down

0 comments on commit 56fc0a2

Please sign in to comment.