Permalink
Browse files

* Added action enabler/disabler alias support. You can now define a s…

…eparate action that does opposite of whatever the action does by providing enabler or disabler options

* Make editing state has its class without is-

* Fix a few problems with wysiwyg. Make it turn on and off

* Bug fixes
  • Loading branch information...
1 parent 3e2ffbd commit 92e665c2fc2dc0fedb51e152d61675424ed0e753 Yaroslaff Fedin committed Jun 21, 2011
View
19 Source/Action.js
@@ -26,7 +26,19 @@ LSD.Action = function(options, name) {
enable: this.enable.bind(this),
disable: this.disable.bind(this),
detach: this.disable.bind(this)
- };
+ }
+ if (this.options.enabler) LSD.Action[LSD.toClassName(this.options.enabler)] = LSD.Action.build({
+ enable: this.options.enable,
+ disable: this.options.disable,
+ getState: this.options.getState
+ })
+ if (this.options.disabler) LSD.Action[LSD.toClassName(this.options.disabler)] = LSD.Action.build({
+ enable: this.options.disable,
+ disable: this.options.enable,
+ getState: this.options.getState && function() {
+ return !this.options.getState.apply(this, arguments)
+ }.bind(this)
+ })
return this;
};
@@ -51,13 +63,12 @@ LSD.Action.prototype = {
commit: function(target, args, bind) {
if (this.state) this.target[this.state.enabler]();
- var result = this.options.enable.apply(bind || this, [target].concat(args));
- return result;
+ return this.options.enable && this.options.enable.apply(bind || this, [target].concat(args));
},
revert: function(target, args, bind) {
if (this.state) this.target[this.state.disabler]();
- return this.options.disable.apply(bind || this, [target].concat(args));
+ return this.options.disable && this.options.disable.apply(bind || this, [target].concat(args));
},
perform: function(target, args) {
View
4 Source/LSD.js
@@ -71,7 +71,9 @@ var LSD = Object.append(new Events, {
Classes: {
selected: 'selected',
empty: 'empty',
- working: 'working'
+ working: 'working',
+ focused: 'focused',
+ editing: 'editing'
}
},
Options: {},
View
44 Source/Layout.js
@@ -111,9 +111,9 @@ LSD.Layout.prototype = Object.append(new Options, {
var converted = element.uid && Element.retrieve(element, 'widget');
var children = LSD.slice(element.childNodes);
var cloning = (opts && opts.clone) || this.options.clone, group;
-
var ascendant = parent[1] || parent, container = parent[0] || parent.toElement();
+ // Retrieve the stack if the render was not triggered from the root of the layout
if (!stack) {
stack = [];
if ((group = ascendant.mutations['>'])) stack.push(group);
@@ -124,24 +124,32 @@ LSD.Layout.prototype = Object.append(new Options, {
// if ((group = node.mutations['-'])) stack.push(group);
//}
}
+
+ // Match all selectors in the stack and find a right mutation
var index = stack.length;
if (index) {
var mutation, advanced, tagName = LSD.toLowerCase(element.tagName);
for (var i = index, item, result, ary = ['*', tagName]; item = stack[--i];)
for (var j = 0, value = item[1] || item, tag; tag = ary[j++];)
- if ((group = value[tag]))
- for (var k = 0, possibility, sel; possibility = group[k++];)
- if ((result = possibility[1]) && (!mutation || !result.indexOf) && (sel = possibility[0]))
- if ((!sel.id && !sel.classes && !sel.attributes && !sel.pseudos) ? (tagName == sel.tag) :
+ if ((group = value[tag])){
+ for (var k = 0, possibility, sel; possibility = group[k++];) {
+ var result = possibility[1];
+ if ((!mutation || (result && !result.indexOf)) && (sel = possibility[0])) {
+ if ((!sel.id && !sel.classes && !sel.attributes && !sel.pseudos) ? (tagName == sel.tag || j == 0) :
(Slick.matchSelector(element, sel.tag, sel.id, sel.classes, sel.attributes, sel.pseudos)))
- if (!result.call || (result = result(element, !revert)))
- if (!result.push) {
- mutation = result;
+ if (!result || !result.call || (result = result(element, !revert)))
+ if (!result || !result.push) {
+ mutation = result || true;
} else (advanced || (advanced = [])).push(result);
+ }
+ }
+ }
}
+
+
+ // Create, clone or reuse a widget.
if (!converted) {
- var options = Object.append({}, opts);
- options.traverse = false;
+ var options = {traverse: false};
if (!options.context && this.options.context) options.context = this.options.context;
if (mutation) {
Object.append(options, mutation.indexOf ? LSD.Layout.parse(mutation) : mutation);
@@ -152,6 +160,7 @@ LSD.Layout.prototype = Object.append(new Options, {
} else {
var widget = cloning ? converted.cloneNode(false, options) : converted;
}
+ // Append widget into parent widget without moving elements
if (widget) {
var override = function() {
if (widget.toElement().parentNode == container) return;
@@ -165,9 +174,10 @@ LSD.Layout.prototype = Object.append(new Options, {
} else {
if (cloning) var clone = element.cloneNode(false);
if (cloning || (ascendant.origin == element.parentNode)) this.appendChild(container, clone || element);
- }
+ }
var newParent = [clone || (widget && widget.element) || element, widget || ascendant];
- console.log(element, cloning)
+
+ // Put away selectors in the stack that should not be matched again widget children
var group, direct, following;
for (var i = stack.length; group = stack[--i];) {
switch (group[0]) {
@@ -181,10 +191,12 @@ LSD.Layout.prototype = Object.append(new Options, {
(direct || (direct = [])).push(stack.pop());
}
}
+ // Collect the mutations from the converted widget
if (widget) {
if ((group = widget.mutations[' '])) stack.push([' ', group]);
if ((group = widget.mutations['>'])) stack.push(['>', group]);
}
+ // Collect mutations that advanced with this element AND are looking for children
if (advanced) for (var i = 0, group; group = advanced[i]; i++) {
switch (group[0]) {
case ' ': case '>':
@@ -193,6 +205,7 @@ LSD.Layout.prototype = Object.append(new Options, {
break;
}
}
+ // Render children
for (var i = 0, j = children.length - 2, child, previous, result, following; child = children[i]; i++) {
if (previous) {
if ((group = previous.mutations['~'])) stack.push(['~', group]);
@@ -201,12 +214,14 @@ LSD.Layout.prototype = Object.append(new Options, {
previous = this[LSD.Layout.NodeTypes[child.nodeType]](child, newParent, opts, stack, revert, i == j);
if (!previous.lsd) previous = null;
}
+ // Put back advanced selectors into the stack
if (advanced) for (var i = 0; group = advanced[i++];)
if (group[0] != '+' || !last) stack.push(group);
if (!last) {
if (following) for (var i = 0; group = following[i++];) stack.push(group);
if (direct) for (var i = 0; group = direct[i++];) stack.push(group);
}
+
return widget || clone || element;
},
@@ -338,11 +353,6 @@ Object.append(LSD.Layout, {
return options;
},
- mutate: function(element, parent) {
- var mutation = (parent[1] || parent).mutateLayout(element);
- if (mutation) return (mutation === true) || LSD.Layout.parse(mutation, parent);
- },
-
getSource: function(options, tagName) {
if (options && options.localName) {
var source = [LSD.toLowerCase(options.tagName)];
View
36 Source/Mixin/ContentEditable.js
@@ -44,30 +44,28 @@ LSD.Mixin.ContentEditable = new Class({
getEditor: Macro.getter('editor', function() {
use('CKEDITOR', function(CKEDITOR) {
- var value = this.getValueForEditor()
+ var value = this.getValueForEditor();
+ console.error(this.getEditedElement());
var editor = this.editor = new CKEDITOR.editor( this.options.ckeditor, this.getEditedElement(), 1, value);
-
+ console.error('editor', editor, this.editor)
editor.on('focus', function() {
- if (this.editor) this.getEditorContainer().addClass('focus');
+ if (this.editor) this.getEditorContainer().addClass('focused');
}.bind(this));
editor.on('blur', function() {
- if (this.editor) this.getEditorContainer().removeClass('focus');
+ if (this.editor) this.getEditorContainer().removeClass('focused');
}.bind(this));
- editor.on('contentDom', function() {
+ editor.on('uiReady', function() {
this.showEditor();
this.fireEvent('editorReady');
-
- !function() {
-
+ !function() {/*
if (Browser.firefox) {
var body = this.getEditorBody()
body.contentEditable = false;
body.contentEditable = true;
- }
+ }*/
this.editor.focus();
this.editor.forceNextSelectionCheck();
this.editor.focus();
-
}.delay(100, this)
}.bind(this));
}.bind(this))
@@ -84,19 +82,27 @@ LSD.Mixin.ContentEditable = new Class({
},
showEditor: function() {
+ console.log('show', this.element);
this.element.setStyle('display', 'none');
- this.getEditorContainer().setStyle('visibility', 'visible');
+ this.getEditorContainer().setStyles({
+ display: '',
+ visiblity: 'visible'
+ });
},
hideEditor: function() {
this.element.setStyle('display', '');
- this.getEditorContainer().setStyle('visibility', 'hidden');
+ this.getEditorContainer().setStyle('display', 'none');
},
useEditor: function(callback) {
- if (this.editor && this.editor.document) callback.call(this.editor);
- this.addEvent('editorReady:once', callback);
- this.getEditor();
+ if (this.editor && this.editor.document) {
+ if (callback) callback.call(this.editor);
+ this.showEditor();
+ } else {
+ if (callback) this.addEvent('editorReady:once', callback);
+ this.getEditor();
+ }
},
getEditorContainer: function() {
View
1 Source/Mixin/Sortable.js
@@ -45,6 +45,7 @@ LSD.Mixin.Sortable = new Class({
getSortables: Macro.getter('sortables', function() {
var sortables = new Sortables([], this.options.sortables);
this.addEvent('sort', this.bindEvent('onSort'))
+ return sortables
}),
onSort: function(element) {
View
24 Source/Module/Ambient/DOM.js
@@ -92,11 +92,11 @@ LSD.Module.DOM = new Class({
unsetParent: function(widget, index) {
if (!widget) widget = this.parentNode;
- this.fireEvent('unregister', ['parent', widget]);
- this.removed = true;
LSD.Module.DOM.walk(this, function(node) {
widget.dispatchEvent('nodeRemoved', node);
});
+ this.fireEvent('unregister', ['parent', widget]);
+ this.removed = true;
var parent = this.parentNode, siblings = widget.childNodes;
if (index == null) index = siblings.indexOf(this);
var previous = siblings[index - 1], next = siblings[index + 1];
@@ -147,30 +147,34 @@ LSD.Module.DOM = new Class({
if (index) insertion.toElement().inject(this.childNodes[index - 1].toElement(), 'after')
else this.toElement().appendChild(insertion.toElement())
} else this.toElement().insertBefore(insertion.toElement(), child.element);
+ return this;
},
cloneNode: function(children, options) {
var clone = this.context.create(this.element, Object.merge({
source: this.source,
tag: this.tagName,
pseudos: this.pseudos.toObject(),
- document: document,
- clone: true
+ clone: true,
+ traverse: !!children
}, options));
return clone;
},
- setDocument: function(document) {
+ setDocument: function(document, revert) {
LSD.Module.DOM.walk(this, function(child) {
- child.ownerDocument = child.document = document;
- child.fireEvent('register', ['document', document]);
- child.fireEvent('setDocument', document);
+ if (revert) {
+ delete child.ownerDocument;
+ delete child.document;
+ } else child.ownerDocument = child.document = document;
+ child.fireEvent(revert ? 'unregister' : 'register', ['document', document]);
+ child.fireEvent(revert ? 'unsetDocument' : 'setDocument', document);
});
return this;
},
unsetDocument: function(document) {
- delete this.document;
+ return this.setDocument(document, true);
},
inject: function(widget, where, quiet) {
@@ -183,7 +187,7 @@ LSD.Module.DOM = new Class({
if (where === false) widget.appendChild(this, false)
else if (!inserters[where || 'bottom'](widget.lsd ? this : this.toElement(), widget) && !quiet) return false;
}
-
+ if (where == 'after' || where == 'before') widget = this.parentNode;
if (quiet !== true || widget.document) this.setDocument(widget.document || LSD.document);
if (!this.pseudos.root) this.fireEvent('inject', this.parentNode);
return this;
View
2 Source/Module/Ambient/Layout.js
@@ -95,7 +95,7 @@ LSD.Module.Layout.events = {
if (this.getLayout().origin == this && this.options.traverse !== false) {
if (this.origin && !this.options.clone) this.element.replaces(this.origin);
var nodes = LSD.slice((this.origin || this.element).childNodes);
- this.getLayout().result = this.getLayout().render(nodes, [this.element, this], this.options.clone ? 'clone' : null);
+ this.getLayout().result = this.getLayout().render(nodes, [this.element, this], this.options.clone ? {clone: true} : null);
}
if (this.options.layout) this.buildLayout(this.options.layout);
},
View
2 Source/Widget.js
@@ -47,7 +47,7 @@ LSD.Widget = new Class({
LSD.Module.Events.addEvents.call(LSD.Widget.prototype, {
initialize: function() {
- this.addPseudo(this.pseudos.submittable ? 'read-write' : 'read-only');
+ this.addPseudo(this.pseudos.writable ? 'read-write' : 'read-only');
}
});

0 comments on commit 92e665c

Please sign in to comment.