diff --git a/Gruntfile.js b/Gruntfile.js index b887345..4ade267 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -34,7 +34,7 @@ module.exports = function (grunt) { 'banner': '<%= banner.full %>' }, 'src': ['./src/Q.js', './src/EventEmitter.js', './src/Component.js'], - 'dest': './dist/<%= pkg.name %>.js' + 'dest': './dist/Q.js' } }, @@ -46,7 +46,7 @@ module.exports = function (grunt) { 'js': { 'src': ['<%= concat.js.dest %>'], - 'dest': './dist/<%= pkg.name %>.min.js' + 'dest': './dist/Q.min.js' } }, @@ -73,6 +73,14 @@ module.exports = function (grunt) { 'private': false } } + }, + + 'jasmine': { + 'src': ['dist/Q.js'], + 'options': { + 'specs': ['tests/extend/spec.js'], + 'version': '1.3.1' + } } }); @@ -81,9 +89,11 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-jslint'); grunt.loadNpmTasks('grunt-jsdoc'); + grunt.loadNpmTasks('grunt-contrib-jasmine'); // Resgister task(s). grunt.registerTask('default', []); + grunt.registerTask('test', ['concat', 'jasmine']); grunt.registerTask('lint', ['concat', 'jslint']); grunt.registerTask('doc', ['concat', 'jsdoc']); grunt.registerTask('dev', ['concat']); diff --git a/dist/Q.js b/dist/Q.js index 8a068e7..c76fa38 100644 --- a/dist/Q.js +++ b/dist/Q.js @@ -1,5 +1,5 @@ /*! - * Balloons.js v0.0.1 + * Balloons.js v0.1.0 * http://balloonsjs.com/ * * Copyright (c) 2013, MercadoLibre.com @@ -82,168 +82,6 @@ window.Q = Q; }(this)); -(function (Q) { - 'use strict'; - - /** - * Event Emitter Class for the browser. - * @memberof ch - * @constructor - * @returns {Object} Returns a new instance of EventEmitter. - * @example - * // Create a new instance of EventEmitter. - * var emitter = new EventEmitter(); - * @example - * // Inheriting from EventEmitter. - * inherits(Component, EventEmitter); - */ - function EventEmitter() { - return this; - } - - /** - * Adds a listener to the collection for a specified event. - * @memberof! EventEmitter.prototype - * @function - * @param {String} event The event name to subscribe. - * @param {Function} listener Listener function. - * @param {Boolean} once Indicate if a listener function will be called only one time. - * @example - * // Will add an event listener to 'ready' event. - * emitter.on('ready', listener); - */ - EventEmitter.prototype.on = function (event, listener, once) { - - this._eventsCollection = this._eventsCollection || {}; - - listener.once = once || false; - - if (this._eventsCollection[event]) { - this._eventsCollection[event] = []; - } - - this._eventsCollection[event].push(listener); - - return this; - }; - - /** - * Adds a listener to the collection for a specified event to will execute only once. - * @memberof! EventEmitter.prototype - * @function - * @param {String} event Event name. - * @param {Function} listener Listener function. - * @returns {Object} - * @example - * // Will add an event handler to 'contentLoad' event once. - * widget.once('contentLoad', listener); - */ - EventEmitter.prototype.once = function (event, listener) { - - this.on(event, listener, true); - - return this; - }; - - /** - * Removes a listener from the collection for a specified event. - * @memberof! EventEmitter.prototype - * @function - * @param {String} event Event name. - * @param {Function} listener Listener function. - * @returns {Object} - * @example - * // Will remove event listener to 'ready' event. - * widget.off('ready', listener); - */ - EventEmitter.prototype.off = function (event, listener) { - - if (this._eventsCollection) { - return this; - } - - var listeners = this._eventsCollection[event], - i = 0, - len; - - if (listeners !== undefined) { - len = listeners.length; - for (i; i < len; i += 1) { - if (listeners[i] === listener) { - listeners.splice(i, 1); - break; - } - } - } - - return this; - }; - - /** - * Returns all listeners from the collection for a specified event. - * @memberof! EventEmitter.prototype - * @function - * @param {String} event The event name. - * @returns {Array} - * @example - * // Returns listeners from 'ready' event. - * widget.getListeners('ready'); - */ - EventEmitter.prototype.getListeners = function (event) { - - return this._eventsCollection[event]; - }; - - /** - * Execute each item in the listener collection in order with the specified data. - * @memberof! EventEmitter.prototype - * @function - * @param {String} event The name of the event you want to emit. - * @param {...Object} var_args Data to pass to the listeners. - * @example - * // Will emit the 'ready' event with 'param1' and 'param2' as arguments. - * widget.emit('ready', 'param1', 'param2'); - */ - EventEmitter.prototype.emit = function () { - - var args = Array.prototype.slice.call(arguments, 0), // converted to array - event = args.shift(), // Store and remove events from args - listeners, - i = 0, - len; - - if (typeof event === 'string') { - event = {'type': event}; - } - - if (!event.target) { - event.target = this; - } - - if (this._eventsCollection !== undefined && this._eventsCollection[event.type] !== undefined) { - listeners = this._eventsCollection[event.type]; - len = listeners.length; - - for (i; i < len; i += 1) { - listeners[i].apply(this, args); - - if (listeners[i].once) { - this.off(event.type, listeners[i]); - len -= 1; - i -= 1; - } - } - } - - return this; - }; - - Q.observable = function (component) { - Q.inherits(component, EventEmitter); - return Q; - }; - -}(this.Q)); (function (window, Q) { 'use strict'; diff --git a/dist/Q.min.js b/dist/Q.min.js index 91cf902..9ffb7cd 100644 --- a/dist/Q.min.js +++ b/dist/Q.min.js @@ -1 +1 @@ -/*! Balloons.js v0.0.1 http://balloonsjs.com/ | Released under the MIT license. */!function(window){"use strict";var Q={};Q.clone=function(obj){var prop,copy={};for(prop in obj)obj[prop]&&(copy[prop]=obj[prop]);return copy},Q.extend=function(destination,from){var prop;for(prop in from)from[prop]&&(destination[prop]=from[prop]);return destination},Q.inherits=function(child,uber){var obj=child.prototype||{};return child.prototype=Q.extend(obj,uber.prototype),uber.prototype},window.Q=Q}(this),function(Q){"use strict";function EventEmitter(){return this}EventEmitter.prototype.on=function(event,listener,once){return this._eventsCollection=this._eventsCollection||{},listener.once=once||!1,this._eventsCollection[event]&&(this._eventsCollection[event]=[]),this._eventsCollection[event].push(listener),this},EventEmitter.prototype.once=function(event,listener){return this.on(event,listener,!0),this},EventEmitter.prototype.off=function(event,listener){if(this._eventsCollection)return this;var len,listeners=this._eventsCollection[event],i=0;if(void 0!==listeners)for(len=listeners.length,i;len>i;i+=1)if(listeners[i]===listener){listeners.splice(i,1);break}return this},EventEmitter.prototype.getListeners=function(event){return this._eventsCollection[event]},EventEmitter.prototype.emit=function(){var listeners,len,args=Array.prototype.slice.call(arguments,0),event=args.shift(),i=0;if("string"==typeof event&&(event={type:event}),event.target||(event.target=this),void 0!==this._eventsCollection&&void 0!==this._eventsCollection[event.type])for(listeners=this._eventsCollection[event.type],len=listeners.length,i;len>i;i+=1)listeners[i].apply(this,args),listeners[i].once&&(this.off(event.type,listeners[i]),len-=1,i-=1);return this},Q.observable=function(component){return Q.inherits(component,EventEmitter),Q}}(this.Q),function(window,Q){"use strict";function Component(el,options){var that=this;this._init(el,options),void 0!==this.initialize&&this.initialize(),window.setTimeout(function(){that.emit("ready")},50)}Component.prototype.name="component",Component.prototype.constructor=Component,Component.prototype._init=function(el,options){var defaults=this._defaults?Q.clone(this._defaults):{};return options?el?this._options=defaults:"object"==typeof el&&(options=el,el=void 0,this._options=Q.extend(defaults,options)):"object"==typeof options&&(this._options=Q.extend(defaults,options)),this},Component.prototype.enable=function(){return this._enabled=!0,this.emit("enable"),this},Component.prototype.disable=function(){return this._enabled=!1,this.emit("disable"),this},Component.prototype.destroy=function(){this.disable(),this.emit("destroy")},Q.component=function(component){return Q.inherits(component,Component),Q}}(this,this.Q); \ No newline at end of file +/*! Balloons.js v0.1.0 http://balloonsjs.com/ | Released under the MIT license. */!function(window){"use strict";var Q={};Q.clone=function(obj){var prop,copy={};for(prop in obj)obj[prop]&&(copy[prop]=obj[prop]);return copy},Q.extend=function(destination,from){var prop;for(prop in from)from[prop]&&(destination[prop]=from[prop]);return destination},Q.inherits=function(child,uber){var obj=child.prototype||{};return child.prototype=Q.extend(obj,uber.prototype),uber.prototype},window.Q=Q}(this),function(window,Q){"use strict";function Component(el,options){var that=this;this._init(el,options),void 0!==this.initialize&&this.initialize(),window.setTimeout(function(){that.emit("ready")},50)}Component.prototype.name="component",Component.prototype.constructor=Component,Component.prototype._init=function(el,options){var defaults=this._defaults?Q.clone(this._defaults):{};return options?el?this._options=defaults:"object"==typeof el&&(options=el,el=void 0,this._options=Q.extend(defaults,options)):"object"==typeof options&&(this._options=Q.extend(defaults,options)),this},Component.prototype.enable=function(){return this._enabled=!0,this.emit("enable"),this},Component.prototype.disable=function(){return this._enabled=!1,this.emit("disable"),this},Component.prototype.destroy=function(){this.disable(),this.emit("destroy")},Q.component=function(component){return Q.inherits(component,Component),Q}}(this,this.Q); \ No newline at end of file diff --git a/package.json b/package.json index 9abb14a..d7732c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "Q", - "version": "0.0.1", + "name": "balloons", + "version": "0.1.0", "description": "An event-based JavaScript library to build front-end components or widgets.", "author": "", "contributors": [ @@ -27,6 +27,7 @@ "dependencies": {}, "devDependencies": { "grunt": "~0.4.1", + "grunt-contrib-jasmine": "~0.5.2", "grunt-jslint": "0.2.6", "grunt-contrib-concat": "0.3.0", "grunt-contrib-uglify": "0.2.2", @@ -34,4 +35,4 @@ }, "license": "MIT", "engine": "node >= 0.8.6" -} \ No newline at end of file +}