From 3a82ff3e6659f3607771a585dc6acb4a70272357 Mon Sep 17 00:00:00 2001 From: Nathan Bishop Date: Wed, 31 Dec 2014 20:38:44 +1000 Subject: [PATCH 1/2] See this issue: https://github.com/mootools/mootools-core/issues/2687 --- Source/Class/Class.js | 1 + Specs/Class/Class.js | 55 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/Source/Class/Class.js b/Source/Class/Class.js index 220e3cd6d..f9d131bf8 100644 --- a/Source/Class/Class.js +++ b/Source/Class/Class.js @@ -23,6 +23,7 @@ var Class = this.Class = new Type('Class', function(params){ reset(this); if (newClass.$prototyping) return this; this.$caller = null; + this.$family = null; var value = (this.initialize) ? this.initialize.apply(this, arguments) : this; this.$caller = this.caller = null; return value; diff --git a/Specs/Class/Class.js b/Specs/Class/Class.js index 962555004..2de36fe48 100644 --- a/Specs/Class/Class.js +++ b/Specs/Class/Class.js @@ -282,4 +282,59 @@ describe('Class toString', function(){ }); +describe('Class.toElement', function () { + + var MyParentElement = new Class({ + initialize: function (el) { + this.element = el; + }, + toElement: function () { + return this.element; + } + }); + + var MyChildElement = new Class({ + Extends: MyParentElement, + initialize: function (el) { + this.parent(el); + } + }); + + MyArrayElement = new Class({ + Extends: Array, + initialize: function (el) { + this.element = el; + }, + toElement: function () { + return this.element; + } + }); + + // -------------------------------------------------------------------------------- + + it('should return an element when a class instance is passed to document.id', function () { + var el = new Element('div', { 'class': 'my-element' }); + var instance = new MyParentElement(el); + + expect(document.id(instance)).toBe(el); + }); + + it('should call the toElement() method in parent class if none is defined in child', function () { + var el = new Element('div', { 'class': 'my-element' }); + var instance = new MyChildElement(el); + + expect(document.id(instance)).toBe(el); + expect(instance instanceof MyParentElement).toEqual(true); + }); + + it('should call toElement() when extending natives (String, Array, Object)', function () { + var el = new Element('div', { 'class': 'my-element' }); + var instance = new MyArrayElement(el); + + expect(document.id(instance)).toBe(el); + expect(instance instanceof Array).toEqual(true); + }); + +}); + })(); From 201627b3b0fd850e3fd8d00dceccd7cc226d4ce8 Mon Sep 17 00:00:00 2001 From: Nathan Bishop Date: Mon, 12 Jan 2015 21:49:50 +1000 Subject: [PATCH 2/2] Updated code to match style guidelines. --- Source/Class/Class.js | 2 +- Specs/Class/Class.js | 114 ++++++++++++++++++++++-------------------- 2 files changed, 62 insertions(+), 54 deletions(-) diff --git a/Source/Class/Class.js b/Source/Class/Class.js index f9d131bf8..05d3ef1b8 100644 --- a/Source/Class/Class.js +++ b/Source/Class/Class.js @@ -23,7 +23,7 @@ var Class = this.Class = new Type('Class', function(params){ reset(this); if (newClass.$prototyping) return this; this.$caller = null; - this.$family = null; + this.$family = null; var value = (this.initialize) ? this.initialize.apply(this, arguments) : this; this.$caller = this.caller = null; return value; diff --git a/Specs/Class/Class.js b/Specs/Class/Class.js index 2de36fe48..c7df035ea 100644 --- a/Specs/Class/Class.js +++ b/Specs/Class/Class.js @@ -282,59 +282,67 @@ describe('Class toString', function(){ }); -describe('Class.toElement', function () { - - var MyParentElement = new Class({ - initialize: function (el) { - this.element = el; - }, - toElement: function () { - return this.element; - } - }); - - var MyChildElement = new Class({ - Extends: MyParentElement, - initialize: function (el) { - this.parent(el); - } - }); - - MyArrayElement = new Class({ - Extends: Array, - initialize: function (el) { - this.element = el; - }, - toElement: function () { - return this.element; - } - }); - - // -------------------------------------------------------------------------------- - - it('should return an element when a class instance is passed to document.id', function () { - var el = new Element('div', { 'class': 'my-element' }); - var instance = new MyParentElement(el); - - expect(document.id(instance)).toBe(el); - }); - - it('should call the toElement() method in parent class if none is defined in child', function () { - var el = new Element('div', { 'class': 'my-element' }); - var instance = new MyChildElement(el); - - expect(document.id(instance)).toBe(el); - expect(instance instanceof MyParentElement).toEqual(true); - }); - - it('should call toElement() when extending natives (String, Array, Object)', function () { - var el = new Element('div', { 'class': 'my-element' }); - var instance = new MyArrayElement(el); - - expect(document.id(instance)).toBe(el); - expect(instance instanceof Array).toEqual(true); - }); - +describe('Class.toElement', function(){ + + var MyParentElement = new Class({ + + initialize: function(element){ + this.element = element; + }, + + toElement: function(){ + return this.element; + } + + }); + + var MyChildElement = new Class({ + + Extends: MyParentElement, + + initialize: function(element){ + this.parent(element); + } + + }); + + var MyArrayElement = new Class({ + + Extends: Array, + + initialize: function(element){ + this.element = element; + }, + + toElement: function(){ + return this.element; + } + + }); + + it('should return an element when a class instance is passed to document.id', function(){ + var element = new Element('div', {'class': 'my-element'}); + var instance = new MyParentElement(element); + + expect(document.id(instance)).toBe(element); + }); + + it('should call the toElement() method in parent class if none is defined in child', function(){ + var element = new Element('div', {'class': 'my-element'}); + var instance = new MyChildElement(element); + + expect(document.id(instance)).toBe(element); + expect(instance instanceof MyParentElement).toEqual(true); + }); + + it('should call toElement() when extending natives (String, Array, Object)', function(){ + var element = new Element('div', {'class': 'my-element'}); + var instance = new MyArrayElement(element); + + expect(document.id(instance)).toBe(element); + expect(instance instanceof Array).toEqual(true); + }); + }); })();