Skip to content

Commit

Permalink
Cleaning option values before passing to the constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
anutron committed May 1, 2011
1 parent 10ddc27 commit ae4efa0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 49 deletions.
32 changes: 17 additions & 15 deletions Source/Forms/Behavior.FormValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
description: Adds an instance of Form.Validator.Inline to any form with the class .form-validator.
provides: [Behavior.FormValidator]
requires: [Behavior/Behavior, More/Form.Validator.Inline]
requires: [Behavior/Behavior, More/Form.Validator.Inline, More/Object.Extras]
script: Behavior.FormValidator.js
...
Expand All @@ -28,20 +28,22 @@ Behavior.addGlobalFilter('FormValidator', {
var validator = element.retrieve('validator');
if (!validator) {
validator = new Form.Validator.Inline(element,
api.getAs({
useTitles: Boolean,
scrollToErrorsOnSubmit: Boolean,
scrollToErrorsOnBlur: Boolean,
scrollToErrorsOnChange: Boolean,
ignoreHidden: Boolean,
ignoreDisabled: Boolean,
useTitles: Boolean,
evaluateOnSubmit: Boolean,
evaluateFieldsOnBlur: Boolean,
evaluateFieldsOnChange: Boolean,
serial: Boolean,
stopOnFailure: Boolean
})
Object.cleanValues(
api.getAs({
useTitles: Boolean,
scrollToErrorsOnSubmit: Boolean,
scrollToErrorsOnBlur: Boolean,
scrollToErrorsOnChange: Boolean,
ignoreHidden: Boolean,
ignoreDisabled: Boolean,
useTitles: Boolean,
evaluateOnSubmit: Boolean,
evaluateFieldsOnBlur: Boolean,
evaluateFieldsOnChange: Boolean,
serial: Boolean,
stopOnFailure: Boolean
})
)
);
}
//if the api provides a getScroller method, which should return an instance of
Expand Down
38 changes: 20 additions & 18 deletions Source/Fx/Behavior.FxAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
description: Creates an Fx.Accordion from any element with Accordion in its data-filters property. Uses the .toggle elements within the element as the toggles and the .target elements as the targets.
provides: [Behavior.Accordion, Behavior.FxAccordion]
requires: [Behavior/Behavior, More/Fx.Accordion, Behavior/Element.Data]
requires: [Behavior/Behavior, More/Fx.Accordion, Behavior/Element.Data, More/Object.Extras]
script: Behavior.Accordion.js
...
*/
Expand All @@ -27,23 +27,25 @@ Behavior.addGlobalFilter('Accordion', {
},
setup: function(element, api){
var accordion = new Fx.Accordion(element.getElements(api.get('headers')), element.getElements(api.get('sections')),
$merge(api.getAs({
fixedHeight: Number,
fixedWidth: Number,
display: Number,
show: Number,
height: Boolean,
width: Boolean,
opacity: Boolean,
alwaysHide: Boolean,
trigger: String,
initialDisplayFx: Boolean,
resetHeight: Boolean
}), {
opacity: api.getAs(Boolean, 'fade'),
height: api.get('orientation') == 'vertical',
width: api.get('orientation') == 'horizontal'
})
Object.cleanValues(
Object.merge(api.getAs({
fixedHeight: Number,
fixedWidth: Number,
display: Number,
show: Number,
height: Boolean,
width: Boolean,
opacity: Boolean,
alwaysHide: Boolean,
trigger: String,
initialDisplayFx: Boolean,
resetHeight: Boolean
}), {
opacity: api.getAs(Boolean, 'fade'),
height: api.get('orientation') == 'vertical',
width: api.get('orientation') == 'horizontal'
})
)
);
api.onCleanup(accordion.detach.bind(accordion));
return accordion;
Expand Down
34 changes: 18 additions & 16 deletions Source/Interface/Behavior.HtmlTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
description: Creates instances of HtmlTable for tables with the HtmlTable filter
provides: [Behavior.HtmlTable]
requires: [Behavior/Behavior, More/HtmlTable.Sort, More/HtmlTable.Zebra, More/HtmlTable.Select, More/HtmlTable.Tree, More/HtmlTable.Resize]
requires: [Behavior/Behavior, More/HtmlTable.Sort, More/HtmlTable.Zebra, More/HtmlTable.Select, More/HtmlTable.Tree, More/HtmlTable.Resize, More/Object.Extras]
script: Behavior.HtmlTable.js
...
*/
Expand All @@ -28,7 +28,7 @@ HtmlTable = Class.refactor(HtmlTable, {
//on click, if we haven't parsed, set ready to true and run the parser
if (!this._parsed) {
this._readyToParse = true;
this.detectParsers();
this.setParsers();
}
this.previous(event, el);
},
Expand Down Expand Up @@ -58,20 +58,22 @@ Behavior.addGlobalFilter('HtmlTable', {
});
api.setDefault('firstSort', firstSort);
var multiselectable = api.getAs(Boolean, 'multiselect', element.hasClass('multiselect'));
var table = new HtmlTable(element, {
parsers: api.getAs(Array, 'parsers'),
sortOnStartup: api.getAs(Boolean, 'sortOnStartup'),
sortIndex: api.getAs(Number, 'firstSort'),
sortable: api.getAs(Boolean, 'sortable', /* deprecated default: */ element.hasClass('sortable') && !element.hasClass('treeview')),
classNoSort: api.get('noSort'),
selectable: api.getAs(Boolean, 'selectable', /* deprecated default: */ element.hasClass('selectable') || multiselectable),
allowMultiSelect: multiselectable,
useKeyboard: api.getAs(Boolean, 'useKeybaord', /* deprecated default: */ !element.hasClass('noKeyboard')),
enableTree: api.getAs(Boolean, 'enableTree', /* deprecated default: */ element.hasClass('treeView')),
resizable: api.getAs(Boolean, 'resizable', /* deprecated default: */ element.hasClass('resizable')),
resize: api.getAs(Boolean, 'resize'),
build: api.getAs(Boolean, 'build', /* deprecated default: */ element.hasClass('buildTree'))
});
var table = new HtmlTable(element,
Object.cleanValues({
parsers: api.getAs(Array, 'parsers'),
sortOnStartup: api.getAs(Boolean, 'sortOnStartup'),
sortIndex: api.getAs(Number, 'firstSort'),
sortable: api.getAs(Boolean, 'sortable', /* deprecated default: */ element.hasClass('sortable') && !element.hasClass('treeview')),
classNoSort: api.get('noSort'),
selectable: api.getAs(Boolean, 'selectable', /* deprecated default: */ element.hasClass('selectable') || multiselectable),
allowMultiSelect: multiselectable,
useKeyboard: api.getAs(Boolean, 'useKeybaord', /* deprecated default: */ !element.hasClass('noKeyboard')),
enableTree: api.getAs(Boolean, 'enableTree', /* deprecated default: */ element.hasClass('treeView')),
resizable: api.getAs(Boolean, 'resizable', /* deprecated default: */ element.hasClass('resizable')),
resize: api.getAs(Boolean, 'resize'),
build: api.getAs(Boolean, 'build', /* deprecated default: */ element.hasClass('buildTree'))
})
);
api.onCleanup(function(){
if (table.keyboard) table.keyboard.relinquish();
});
Expand Down

0 comments on commit ae4efa0

Please sign in to comment.