From 2d41e5655f681f7cb0e2e05fa2ea2ebb75ed706d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20M=2E=20Costa?= Date: Tue, 12 May 2009 23:10:19 -0300 Subject: [PATCH 1/2] Fixes for set/get Property * defaultValue and type added to the camels array; * Specs to test the getProperty('type') of a select-multiple form Element; * Specs to test the setProperty('defaultValue') of a text input; * Changed the Builder script, it is now more clener and flexible. --- Source/Element/Element.js | 8 +-- Specs/Assets/Scripts/Builder.js | 99 ++++++--------------------------- Specs/Element/Element.js | 25 ++++++++- Specs/index.html | 22 ++++++-- 4 files changed, 60 insertions(+), 94 deletions(-) diff --git a/Source/Element/Element.js b/Source/Element/Element.js index 3cc2c4d4f..55e2d9178 100644 --- a/Source/Element/Element.js +++ b/Source/Element/Element.js @@ -262,7 +262,7 @@ var attributes = { 'text': (Browser.Engine.trident || (Browser.Engine.webkit && Browser.Engine.version < 420)) ? 'innerText' : 'textContent' }; var bools = ['compact', 'nowrap', 'ismap', 'declare', 'noshade', 'checked', 'disabled', 'readonly', 'multiple', 'selected', 'noresize', 'defer']; -var camels = ['value', 'accessKey', 'cellPadding', 'cellSpacing', 'colSpan', 'frameBorder', 'maxLength', 'readOnly', 'rowSpan', 'tabIndex', 'useMap']; +var camels = ['value', 'type', 'defaultValue', 'accessKey', 'cellPadding', 'cellSpacing', 'colSpan', 'frameBorder', 'maxLength', 'readOnly', 'rowSpan', 'tabIndex', 'useMap']; bools = bools.associate(bools); @@ -336,7 +336,7 @@ Element.implement({ }, setProperty: function(attribute, value){ - var key = attributes[attribute]; + var key = attributes[attribute.toLowerCase()]; if (value == undefined) return this.removeProperty(attribute); if (key && bools[attribute]) value = !!value; (key) ? this[key] = value : this.setAttribute(attribute, '' + value); @@ -349,7 +349,7 @@ Element.implement({ }, getProperty: function(attribute){ - var key = attributes[attribute]; + var key = attributes[attribute.toLowerCase()]; var value = (key) ? this[key] : this.getAttribute(attribute, 2); return (bools[attribute]) ? !!value : (key) ? value : value || null; }, @@ -360,7 +360,7 @@ Element.implement({ }, removeProperty: function(attribute){ - var key = attributes[attribute]; + var key = attributes[attribute.toLowerCase()]; (key) ? this[key] = (key && bools[attribute]) ? false : '' : this.removeAttribute(attribute); return this; }, diff --git a/Specs/Assets/Scripts/Builder.js b/Specs/Assets/Scripts/Builder.js index 9193f5ca6..4532998da 100644 --- a/Specs/Assets/Scripts/Builder.js +++ b/Specs/Assets/Scripts/Builder.js @@ -11,95 +11,28 @@ Note: var Builder = { - root: '../', - - paths: { - source: 'Source', - specs: 'Specs' - }, - - included: { - source: {}, - specs: {}, - docs: {} - }, - - scripts: { - source: { - 'Core' : ['Core', 'Browser'], - 'Native' : ['Array', 'Function', 'Number', 'String', 'Hash', 'Event'], - 'Class' : ['Class', 'Class.Extras'], - 'Element' : ['Element', 'Element.Event', 'Element.Style', 'Element.Dimensions'], - 'Utilities' : ['Selectors', 'DomReady', 'JSON', 'Cookie', 'Swiff'], - 'Fx' : ['Fx', 'Fx.CSS', 'Fx.Tween', 'Fx.Morph', 'Fx.Transitions'], - 'Request' : ['Request', 'Request.HTML', 'Request.JSON'] - }, - - specs: { - 'Core' : ['Core', 'Browser'], - 'Native' : ['Array', 'String', 'Function', 'Number', 'Hash'], - 'Class' : ['Class', 'Class.Extras'], - 'Element' : ['Element', 'Element.Style', 'Element.Dimensions'], - 'Utilities' : ['Selectors'] - } - }, - - initialize: function(root){ - if (root) this.root = root; - this.includeType('source'); - return this; - }, - - getFolder: function(type, file){ - var scripts = this.scripts[type]; - for (var folder in scripts){ - for (var i = 0; i < scripts[folder].length; i++){ - var script = scripts[folder][i]; - if (script == file) return folder; + includeFiles: function(path, files){ + if( typeof files == 'object' && files.constructor != Array ){ + for(key in files){ + this.includeFiles(path + key + '/', files[key]); } } - return false; - }, - - getRequest: function(){ - var pairs = window.location.search.substring(1).split('&'); - var obj = {}; - for (var i = 0, l = pairs.length; i < l; i++){ - var pair = pairs[i].split('='); - obj[pair[0]] = pair[1]; + else if( typeof files == 'object' && files.constructor == Array ){ + for(var i=0; i< files.length; i++){ + this.includeJs(path + files[i]); + } } - return obj; - }, - - includeFile: function(type, folder, file){ - folder = folder || this.getFolder(type, file); - if (!folder) return false; - this.included[type][folder] = this.included[type][folder] || []; - var files = this.included[type][folder]; - for (var i = 0; i < files.length; i++){ - if (files[i] == file) return false; + else if( typeof files == 'string'){ + this.includeJs(path + files); } - this.included[type][folder].push(file); - return document.writeln(''); }, - - includeFolder: function(type, folder){ - var scripts = this.scripts[type][folder]; - for (var i = 0, l = scripts.length; i < l; i++) this.includeFile(type, folder, scripts[i]); + + includeJs: function(filePath){ + document.writeln(''); }, - - includeType: function(type){ - for (var folder in this.scripts[type]) this.includeFolder(type, folder); - }, - - includeRequest: function(type){ - var req = this.getRequest(); - if (!req.files && !req.folders) return false; - var files = (req.files) ? req.files.split('+') : []; - var folders = (req.folders) ? req.folders.split('+') : []; - for (var j = 0; j < files.length; j++) this.includeFile(type, null, files[j]); - for (var i = 0; i < folders.length; i++) this.includeFolder(type, folders[i]); - return true; + + build: function(root, filesTree){ + this.includeFiles(root, filesTree); } }; \ No newline at end of file diff --git a/Specs/Element/Element.js b/Specs/Element/Element.js index ae9887bcc..10d24528e 100644 --- a/Specs/Element/Element.js +++ b/Specs/Element/Element.js @@ -1183,6 +1183,15 @@ describe('Element.getProperty', { var input2 = new Element('input', {type: 'checkbox'}); value_of(input2.getProperty('type')).should_be('checkbox'); + + var div = new Element('div', {'html': + '' + }); + var input3 = div.getElement('select'); + value_of(input3.getProperty('type')).should_be('select-multiple'); + value_of(input3.getProperty('name')).should_be('test'); }, 'should getPropety checked from an input Element': function(){ @@ -1278,6 +1287,15 @@ describe('Element.setProperty', { var readonly3 = new Element('input', { type: 'text' }).setProperty('readonly', false); value_of(readonly3.getProperty('readonly')).should_be_false(); + }, + + 'should setProperty defaultValue of an input Element': function(){ + var form = new Element('form'); + var defaultValue = new Element('input', {'type': 'text', 'value': '321'}).setProperty('defaultValue', '123'); + form.grab(defaultValue); + value_of(defaultValue.getProperty('value')).should_be('321'); + form.reset(); + value_of(defaultValue.getProperty('value')).should_be('123'); } }); @@ -1305,10 +1323,11 @@ describe('Element.setProperties', { describe('Element.removeProperty', { 'should removeProperty from an Element': function () { - var readonly = new Element('input', { type: 'text', readonly: 'readonly' }); + var readonly = new Element('input', { type: 'text', readonly: 'readonly', maxlenght: 10 }); readonly.removeProperty('readonly'); - var props = readonly.getProperties('type', 'readonly'); - value_of(props).should_be({ type: 'text', readonly: false }); + readonly.removeProperty('maxlength'); + var props = readonly.getProperties('type', 'readonly', 'maxlength'); + value_of(props).should_be({ type: 'text', readonly: false, maxlength: 0}); } }); diff --git a/Specs/index.html b/Specs/index.html index fa66c99ab..d6ff83cbb 100644 --- a/Specs/index.html +++ b/Specs/index.html @@ -12,11 +12,25 @@ - - From 3c17e816fc5ea8d0d5816cf4a8215c9e397797bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20M=2E=20Costa?= Date: Wed, 13 May 2009 22:11:35 -0300 Subject: [PATCH 2/2] Now specs works with Opera, i don't understand this crazy bug that is happening... --- Specs/Assets/Scripts/Builder.js | 25 +++++------ Specs/Element/Element.Dimensions.js | 3 +- Specs/index.html | 64 ++++++++++++++--------------- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/Specs/Assets/Scripts/Builder.js b/Specs/Assets/Scripts/Builder.js index 4532998da..aa9fac6c8 100644 --- a/Specs/Assets/Scripts/Builder.js +++ b/Specs/Assets/Scripts/Builder.js @@ -10,29 +10,30 @@ Note: */ var Builder = { - includeFiles: function(path, files){ - if( typeof files == 'object' && files.constructor != Array ){ - for(key in files){ - this.includeFiles(path + key + '/', files[key]); + switch(typeof files){ + case 'object': + if( files.constructor == Array ){ + for(var i=0; i< files.length; i++){ + this.includeJs(path + files[i]); + } } - } - else if( typeof files == 'object' && files.constructor == Array ){ - for(var i=0; i< files.length; i++){ - this.includeJs(path + files[i]); + else{ + for(key in files){ + this.includeFiles(path + key + '/', files[key]); + } } - } - else if( typeof files == 'string'){ + break; + case 'string': this.includeJs(path + files); } }, includeJs: function(filePath){ - document.writeln(''); + document.writeln(' + + + + - MooTools Specs - - - - - - - - - - - - + + + \ No newline at end of file