Commit 89c41418 authored by Pascal Hartig's avatar Pascal Hartig

Merge pull request #1075 from podefr/master

fix #1071: Olives: Update Olives and Emily to latest 1.x versions
parents b9c3b488 9df98e41
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
"name": "todomvc-olives", "name": "todomvc-olives",
"version": "0.0.0", "version": "0.0.0",
"dependencies": { "dependencies": {
"olives": "~1.4.0", "olives": "~1.6.0",
"emily": "~1.3.5", "emily": "~1.8.1",
"requirejs": "~2.1.5", "requirejs": "~2.1.5",
"todomvc-common": "~0.3.0" "todomvc-common": "~0.3.0"
} }
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
define(["Tools"], function (Tools) { define(["Tools"], function (Tools) {
"use strict";
return { return {
/** /**
* Returns a NodeList including the given dom node, * Returns a NodeList including the given dom node,
......
...@@ -14,121 +14,123 @@ define(["DomUtils"], ...@@ -14,121 +14,123 @@ define(["DomUtils"],
*/ */
function EventPlugin(Utils) { function EventPlugin(Utils) {
/** "use strict";
* The event plugin constructor.
* ex: new EventPlugin({method: function(){} ...}, false); /**
* @param {Object} the object that has the event handling methods * The event plugin constructor.
* @param {Boolean} $isMobile if the event handler has to map with touch events * ex: new EventPlugin({method: function(){} ...}, false);
*/ * @param {Object} the object that has the event handling methods
return function EventPluginConstructor($parent, $isMobile) { * @param {Boolean} $isMobile if the event handler has to map with touch events
*/
/** return function EventPluginConstructor($parent, $isMobile) {
* The parent callback
* @private /**
*/ * The parent callback
var _parent = null, * @private
*/
/** var _parent = null,
* The mapping object.
* @private /**
*/ * The mapping object.
_map = { * @private
"mousedown" : "touchstart", */
"mouseup" : "touchend", _map = {
"mousemove" : "touchmove" "mousedown" : "touchstart",
}, "mouseup" : "touchend",
"mousemove" : "touchmove"
/** },
* Is touch device.
* @private /**
*/ * Is touch device.
_isMobile = !!$isMobile; * @private
*/
/** _isMobile = !!$isMobile;
* Add mapped event listener (for testing purpose).
* @private /**
*/ * Add mapped event listener (for testing purpose).
this.addEventListener = function addEventListener(node, event, callback, useCapture) { * @private
node.addEventListener(this.map(event), callback, !!useCapture); */
}; this.addEventListener = function addEventListener(node, event, callback, useCapture) {
node.addEventListener(this.map(event), callback, !!useCapture);
/** };
* Listen to DOM events.
* @param {Object} node DOM node /**
* @param {String} name event's name * Listen to DOM events.
* @param {String} listener callback's name * @param {Object} node DOM node
* @param {String} useCapture string * @param {String} name event's name
*/ * @param {String} listener callback's name
this.listen = function listen(node, name, listener, useCapture) { * @param {String} useCapture string
this.addEventListener(node, name, function(e){ */
_parent[listener].call(_parent, e, node); this.listen = function listen(node, name, listener, useCapture) {
}, !!useCapture); this.addEventListener(node, name, function(e){
}; _parent[listener].call(_parent, e, node);
}, !!useCapture);
/** };
* Delegate the event handling to a parent DOM element
* @param {Object} node DOM node /**
* @param {String} selector CSS3 selector to the element that listens to the event * Delegate the event handling to a parent DOM element
* @param {String} name event's name * @param {Object} node DOM node
* @param {String} listener callback's name * @param {String} selector CSS3 selector to the element that listens to the event
* @param {String} useCapture string * @param {String} name event's name
*/ * @param {String} listener callback's name
this.delegate = function delegate(node, selector, name, listener, useCapture) { * @param {String} useCapture string
this.addEventListener(node, name, function(event){ */
if (Utils.matches(node, selector, event.target)) { this.delegate = function delegate(node, selector, name, listener, useCapture) {
_parent[listener].call(_parent, event, node); this.addEventListener(node, name, function(event){
} if (Utils.matches(node, selector, event.target)) {
}, !!useCapture); _parent[listener].call(_parent, event, node);
}; }
}, !!useCapture);
/** };
* Get the parent object.
* @return {Object} the parent object /**
*/ * Get the parent object.
this.getParent = function getParent() { * @return {Object} the parent object
return _parent; */
}; this.getParent = function getParent() {
return _parent;
/** };
* Set the parent object.
* The parent object is an object which the functions are called by node listeners. /**
* @param {Object} the parent object * Set the parent object.
* @return true if object has been set * The parent object is an object which the functions are called by node listeners.
*/ * @param {Object} the parent object
this.setParent = function setParent(parent) { * @return true if object has been set
if (parent instanceof Object){ */
_parent = parent; this.setParent = function setParent(parent) {
return true; if (parent instanceof Object){
} _parent = parent;
return false; return true;
}; }
return false;
/** };
* Get event mapping.
* @param {String} event's name /**
* @return the mapped event's name * Get event mapping.
*/ * @param {String} event's name
this.map = function map(name) { * @return the mapped event's name
return _isMobile ? (_map[name] || name) : name; */
}; this.map = function map(name) {
return _isMobile ? (_map[name] || name) : name;
/** };
* Set event mapping.
* @param {String} event's name /**
* @param {String} event's value * Set event mapping.
* @return true if mapped * @param {String} event's name
*/ * @param {String} event's value
this.setMap = function setMap(name, value) { * @return true if mapped
if (typeof name == "string" && */
typeof value == "string") { this.setMap = function setMap(name, value) {
_map[name] = value; if (typeof name == "string" &&
return true; typeof value == "string") {
} _map[name] = value;
return false; return true;
}; }
return false;
//init };
this.setParent($parent);
}; //init
this.setParent($parent);
};
}); });
...@@ -15,6 +15,8 @@ define(["Store", "Tools"], ...@@ -15,6 +15,8 @@ define(["Store", "Tools"],
*/ */
function LocalStore(Store, Tools) { function LocalStore(Store, Tools) {
"use strict";
function LocalStoreConstructor() { function LocalStoreConstructor() {
/** /**
...@@ -96,7 +98,7 @@ function LocalStore(Store, Tools) { ...@@ -96,7 +98,7 @@ function LocalStore(Store, Tools) {
return function LocalStoreFactory(init) { return function LocalStoreFactory(init) {
LocalStoreConstructor.prototype = new Store(init); LocalStoreConstructor.prototype = new Store(init);
return new LocalStoreConstructor; return new LocalStoreConstructor();
}; };
}); });
...@@ -12,77 +12,79 @@ define(["OObject", "Tools"], ...@@ -12,77 +12,79 @@ define(["OObject", "Tools"],
*/ */
function PlacePlugin(OObject, Tools) { function PlacePlugin(OObject, Tools) {
/** "use strict";
* Intilialize a Place.plugin with a list of OObjects
* @param {Object} $uis a list of OObjects such as:
* {
* "header": new OObject(),
* "list": new OObject()
* }
* @Constructor
*/
return function PlacePluginConstructor($uis) {
/** /**
* The list of uis currently set in this place plugin * Intilialize a Place.plugin with a list of OObjects
* @private * @param {Object} $uis a list of OObjects such as:
*/ * {
var _uis = {}; * "header": new OObject(),
* "list": new OObject()
* }
* @Constructor
*/
return function PlacePluginConstructor($uis) {
/** /**
* Attach an OObject to this DOM element * The list of uis currently set in this place plugin
* @param {HTML|SVGElement} node the dom node where to attach the OObject * @private
* @param {String} the name of the OObject to attach */
* @throws {NoSuchOObject} an error if there's no OObject for the given name var _uis = {};
*/
this.place = function place(node, name) {
if (_uis[name] instanceof OObject) {
_uis[name].place(node);
} else {
throw new Error(name + " is not an OObject UI in place:"+name);
}
};
/** /**
* Add an OObject that can be attached to a dom element * Attach an OObject to this DOM element
* @param {String} the name of the OObject to add to the list * @param {HTML|SVGElement} node the dom node where to attach the OObject
* @param {OObject} ui the OObject to add the list * @param {String} the name of the OObject to attach
* @returns {Boolean} true if the OObject was added * @throws {NoSuchOObject} an error if there's no OObject for the given name
*/ */
this.set = function set(name, ui) { this.place = function place(node, name) {
if (typeof name == "string" && ui instanceof OObject) { if (_uis[name] instanceof OObject) {
_uis[name] = ui; _uis[name].place(node);
return true; } else {
} else { throw new Error(name + " is not an OObject UI in place:"+name);
return false; }
} };
};
/** /**
* Add multiple dom elements at once * Add an OObject that can be attached to a dom element
* @param {Object} $uis a list of OObjects such as: * @param {String} the name of the OObject to add to the list
* { * @param {OObject} ui the OObject to add the list
* "header": new OObject(), * @returns {Boolean} true if the OObject was added
* "list": new OObject() */
* } this.set = function set(name, ui) {
*/ if (typeof name == "string" && ui instanceof OObject) {
this.setAll = function setAll(uis) { _uis[name] = ui;
Tools.loop(uis, function (ui, name) { return true;
this.set(name, ui); } else {
}, this); return false;
}; }
};
/** /**
* Returns an OObject from the list given its name * Add multiple dom elements at once
* @param {String} the name of the OObject to get * @param {Object} $uis a list of OObjects such as:
* @returns {OObject} OObject for the given name * {
*/ * "header": new OObject(),
this.get = function get(name) { * "list": new OObject()
return _uis[name]; * }
}; */
this.setAll = function setAll(uis) {
Tools.loop(uis, function (ui, name) {
this.set(name, ui);
}, this);
};
this.setAll($uis); /**
* Returns an OObject from the list given its name
* @param {String} the name of the OObject to get
* @returns {OObject} OObject for the given name
*/
this.get = function get(name) {
return _uis[name];
};
}; this.setAll($uis);
};
}); });
...@@ -17,6 +17,8 @@ define(["Tools", "DomUtils"], ...@@ -17,6 +17,8 @@ define(["Tools", "DomUtils"],
*/ */
function Plugins(Tools, DomUtils) { function Plugins(Tools, DomUtils) {
"use strict";
return function PluginsConstructor($plugins) { return function PluginsConstructor($plugins) {
/** /**
......
...@@ -12,6 +12,8 @@ define(["Observable", "Tools"], ...@@ -12,6 +12,8 @@ define(["Observable", "Tools"],
*/ */
function SocketIOTransport(Observable, Tools) { function SocketIOTransport(Observable, Tools) {
"use strict";
/** /**
* Defines the SocketIOTransport * Defines the SocketIOTransport
* @private * @private
...@@ -47,7 +49,7 @@ function SocketIOTransport(Observable, Tools) { ...@@ -47,7 +49,7 @@ function SocketIOTransport(Observable, Tools) {
*/ */
this.getSocket = function getSocket() { this.getSocket = function getSocket() {
return _socket; return _socket;
}, };
/** /**
* Subscribe to a socket event * Subscribe to a socket event
...@@ -56,7 +58,7 @@ function SocketIOTransport(Observable, Tools) { ...@@ -56,7 +58,7 @@ function SocketIOTransport(Observable, Tools) {
*/ */
this.on = function on(event, func) { this.on = function on(event, func) {
return _socket.on(event, func); return _socket.on(event, func);
}, };
/** /**
* Subscribe to a socket event but disconnect as soon as it fires. * Subscribe to a socket event but disconnect as soon as it fires.
...@@ -95,15 +97,17 @@ function SocketIOTransport(Observable, Tools) { ...@@ -95,15 +97,17 @@ function SocketIOTransport(Observable, Tools) {
* @param {Object} scope the scope in which to execute the callback * @param {Object} scope the scope in which to execute the callback
*/ */
this.request = function request(channel, data, func, scope) { this.request = function request(channel, data, func, scope) {
if (typeof channel == "string" if (typeof channel == "string" &&
&& typeof data != "undefined") { typeof data != "undefined") {
var reqData = { var reqData = {
eventId: Date.now() + Math.floor(Math.random()*1e6), eventId: Date.now() + Math.floor(Math.random()*1e6),
data: data data: data
}, },
boundCallback = function () { boundCallback = function () {
func && func.apply(scope || null, arguments); if (func) {
func.apply(scope || null, arguments);
}
}; };
this.once(reqData.eventId, boundCallback); this.once(reqData.eventId, boundCallback);
...@@ -125,9 +129,9 @@ function SocketIOTransport(Observable, Tools) { ...@@ -125,9 +129,9 @@ function SocketIOTransport(Observable, Tools) {
* @returns * @returns
*/ */
this.listen = function listen(channel, data, func, scope) { this.listen = function listen(channel, data, func, scope) {
if (typeof channel == "string" if (typeof channel == "string" &&
&& typeof data != "undefined" typeof data != "undefined" &&
&& typeof func == "function") { typeof func == "function") {
var reqData = { var reqData = {
eventId: Date.now() + Math.floor(Math.random()*1e6), eventId: Date.now() + Math.floor(Math.random()*1e6),
...@@ -135,7 +139,9 @@ function SocketIOTransport(Observable, Tools) { ...@@ -135,7 +139,9 @@ function SocketIOTransport(Observable, Tools) {
keepAlive: true keepAlive: true
}, },
boundCallback = function () { boundCallback = function () {
func && func.apply(scope || null, arguments); if (func) {
func.apply(scope || null, arguments);
}
}, },
that = this; that = this;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment