Permalink
Browse files

Simple tests for all modules in the console

Next is testing in the browser
  • Loading branch information...
1 parent 1993719 commit c3680386d3583eea94403235bf62654eb469027f @chubas chubas committed Jan 12, 2014
@@ -1,32 +0,0 @@
-BubblingSupport = Module('BubblingSupport')({
- dispatch : function (type, data) {
- data = data || {};
- var event = CustomEventSupport.prototype.dispatch.call(this, type, data);
- if (event.isPropagationStopped === false) {
- if (this.parent && this.parent.dispatch) {
- data.target = event.target;
- data.currentTarget = this.parent;
- this.parent.dispatch(event.type, data);
- }
- }
- return event;
- },
-
- prototype : {
- dispatch : function (type, data) {
- data = data || {};
-
- var event = CustomEventSupport.prototype.dispatch.call(this, type, data);
-
- if (event.isPropagationStopped === false && event.bubbles === true) {
- if (this.parent && this.parent.dispatch) {
- data.target = event.target;
- data.currentTarget = this.parent;
- this.parent.dispatch(event.type, data);
- }
- }
-
- return event;
- }
- }
-});
View
@@ -1,37 +0,0 @@
-Class('CustomEvent')({
- prototype : {
- bubbles : true,
- cancelable : true,
- currentTarget : null,
- timeStamp : 0,
- target : null,
- type : '',
- isPropagationStopped : false,
- isDefaultPrevented : false,
- isImmediatePropagationStopped : false,
- areImmediateHandlersPrevented : false,
- init : function init(type, data) {
- this.type = type;
- if (typeof data !== 'undefined') {
- for(var property in data){
- if (data.hasOwnProperty(property)) {
- this[property] = data[property];
- }
- }
- }
- },
- stopPropagation : function stopPropagation() {
- this.isPropagationStopped = true;
- },
- preventDefault : function preventDefault() {
- this.isDefaultPrevented = true;
- },
- stopImmediatePropagation : function stopImmediatePropagation() {
- this.preventImmediateHandlers();
- this.stopPropagation();
- },
- preventImmediateHandlers : function preventImmediateHandlers() {
- this.areImmediateHandlersPrevented = true;
- }
- }
-});
@@ -1,171 +0,0 @@
-CustomEventSupport = Module('CustomEventSupport')({
- eventListeners : null,
- bind : function(type, eventHandler){
- var found, i, listeners;
-
- if(!this.eventListeners){
- this.eventListeners = {};
- }
-
- if(!this.eventListeners[type]){
- this.eventListeners[type] = [];
- }
-
- found = false;
-
- listeners = this.eventListeners[type];
- for (i = 0; i < listeners.length; i++){
- if (listeners[i] === eventHandler) {
- found = true;
- break;
- }
- }
-
- if(!found){
- this.eventListeners[type].push(eventHandler);
- }
-
- return this;
- },
- unbind : function(type, eventHandler){
- var i, found, listeners;
-
- found = false;
-
- if(!this.eventListeners){
- this.eventListeners = {};
- }
-
- if(typeof eventHandler == 'undefined'){
- this.eventListeners[type] = [];
- }
-
- listeners = this.eventListeners[type];
- for (i = 0; i < listeners.length; i++) {
- if(listeners[i] === eventHandler){
- found = true;
- break;
- }
- }
-
- if(found){
- this.eventListeners[type].splice(i, 1);
- }
-
- return this;
- },
- dispatch : function(type, data){
- var event, listeners, instance, i;
-
- if (this.eventListeners === null) {
- this.eventListeners = {};
- }
-
- if (typeof data === 'undefined') {
- data = {};
- }
-
- if (data.hasOwnProperty('target') === false) {
- data.target = this;
- }
-
- event = new CustomEvent(type, data);
- listeners = this.eventListeners[type] || [];
- instance = this;
-
- for (i = 0; i < listeners.length; i = i + 1) {
- listeners[i].call(instance, event);
- if (event.areImmediateHandlersPrevented === true) {
- break;
- }
- }
-
- return event;
- },
- prototype : {
- eventListeners : null,
- bind : function(type, eventHandler){
- var found, i, listeners;
-
- if(!this.eventListeners){
- this.eventListeners = {};
- }
-
- if(!this.eventListeners[type]){
- this.eventListeners[type] = [];
- }
-
- found = false;
-
- listeners = this.eventListeners[type];
- for (i = 0; i < listeners.length; i++) {
- if(listeners[i] === eventHandler){
- found = true;
- break;
- }
- }
-
- if(!found){
- this.eventListeners[type].push(eventHandler);
- }
-
- return this;
- },
- unbind : function(type, eventHandler){
- var i, found, listeners;
-
- found = false;
- i = 0;
-
- if(!this.eventListeners){
- this.eventListeners = {};
- }
-
- if(typeof eventHandler == 'undefined'){
- this.eventListeners[type] = [];
- }
-
- listeners = this.eventListeners[type];
- for (i = 0; i < listeners.length; i++) {
- if(listeners[i] == eventHandler){
- found = true;
- break;
- }
- }
-
- if(found){
- this.eventListeners[type].splice(i, 1);
- }
-
- return this;
- },
- dispatch : function(type, data){
- var event, listeners, instance, i;
-
- if (this.eventListeners === null) {
- this.eventListeners = {};
- }
-
- if (typeof data === 'undefined') {
- data = {};
- }
-
- if (data.hasOwnProperty('target') === false) {
- data.target = this;
- }
-
- event = new CustomEvent(type, data);
- listeners = this.eventListeners[type] || [];
- instance = this;
-
- for (i = 0; i < listeners.length; i = i + 1) {
- listeners[i].call(instance, event);
- if (event.areImmediateHandlersPrevented === true) {
- break;
- }
- }
-
- return event;
- }
- }
-});
View
@@ -1,127 +0,0 @@
-(function(global) {
-
-NodeSupport = Module('NodeSupport')({
- prototype : {
- parent : null,
-
- children : [],
-
- appendChild : function(child){
- if(child.parent){
- child.parent.removeChild(child);
- }
-
- if(!this.hasOwnProperty('children')){
- this.children = [];
- }
-
- this.children.push(child);
- this[child.name] = child;
- child.setParent(this);
- return child;
- },
-
- insertBefore : function (child, beforeChild) {
- var position;
-
- if (child.parent) {
- child.parent.removeChild(child);
- }
-
- if (!this.hasOwnProperty('children')) {
- this.children = [];
- }
-
- if (typeof beforeChild === 'undefined') {
- this.appendChild(child);
- } else {
- position = this.children.indexOf(beforeChild);
- this.children.splice(position, 0, child);
-
- this[child.name] = child;
- child.setParent(this);
- }
-
- return child;
-
- },
-
- insertChild : function(child, position){
- console.warn('NodeSupport insertChild method is deprecated, try insertBefore');
-
- if (child.parent) {
- child.parent.removeChild(child);
- }
-
- if (!this.hasOwnProperty('children')) {
- this.children = [];
- }
-
- if (typeof position == 'undefined') {
- this.children.push(child);
- this[child.name] = child;
- child.setParent(this);
- return child;
- }
-
- this.children.splice(position, 0, child);
- this[child.name] = child;
- child.setParent(this);
- return child;
- },
-
- removeChild : function (child) {
- var position = this.children.indexOf(child);
-
- if (position !== -1) {
- this.children.splice(position, 1);
- delete this[child.name];
- child.parent = null;
- }
-
- return child;
- },
-
- setParent : function (parent) {
- this.parent = parent;
- return this;
- },
-
- getDescendants : function () {
- var nodes = [];
- this.children.forEach(function (node) {
- nodes.push(node);
- });
- this.children.forEach(function (node) {
- nodes = nodes.concat(node.getDescendants());
- });
- return nodes;
- },
-
- getPreviousSibling : function () {
- if (typeof this.parent === 'undefined') {
- return;
- }
-
- if (this.parent.children[0] === this) {
- return;
- }
-
- return this.parent.children[ this.parent.children.indexOf(this) - 1 ];
- },
-
- getNextSibling : function () {
- if (typeof this.parent === 'undefined') {
- return;
- }
-
- if (this.parent.children[ this.parent.children.length - 1 ] === this) {
- return;
- }
-
- return this.parent.children[ this.parent.children.indexOf(this) + 1 ];
- }
- }
-});
-
-}(typeof window !== 'undefined' ? window : (typeof exports !== 'undefined' ? exports : null)));
Oops, something went wrong.

0 comments on commit c368038

Please sign in to comment.