Skip to content

Commit

Permalink
adds a handler for model and value attributes
Browse files Browse the repository at this point in the history
Close #257
  • Loading branch information
marclaval committed Sep 12, 2014
1 parent 1e61b34 commit d84f8b4
Show file tree
Hide file tree
Showing 31 changed files with 556 additions and 383 deletions.
2 changes: 1 addition & 1 deletion docs/samples/gestures/gestures.hsp
@@ -1,4 +1,4 @@
require('hsp/gestures/index');
require('hsp/gestures/index').register();

{template gestures(msgList)}
<div class="touchboard" style="height:200px; background: #27AAFC;text-align:center;"
Expand Down
2 changes: 1 addition & 1 deletion gruntfile.js
Expand Up @@ -265,7 +265,7 @@ module.exports = function (grunt) {
}
},
gestures: {
files: [{dest: 'dist/hashspace-browserify-gestures.js', src: ['hsp/rt.js']}],
files: [{dest: 'dist/hashspace-browserify-gestures.js', src: ['hsp/gestures/index.js']}],
options: {
aliasMappings: [
{
Expand Down
19 changes: 18 additions & 1 deletion hsp/gestures/doubleTap.js
@@ -1,3 +1,18 @@
/*
* Copyright 2014 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var hsp = require("../rt");
var klass = require("../klass");
var touchEvent = require("./touchEvent");
Expand Down Expand Up @@ -159,4 +174,6 @@ var DoubleTap = klass({

});

hsp.registerCustomAttributes(["ondoubletap", "ondoubletapstart", "ondoubletapcancel"], DoubleTap);
module.exports.register = function() {
hsp.registerCustomAttributes(["ondoubletap", "ondoubletapstart", "ondoubletapcancel"], DoubleTap);
};
19 changes: 18 additions & 1 deletion hsp/gestures/drag.js
@@ -1,3 +1,18 @@
/*
* Copyright 2014 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var hsp = require("../rt");
var klass = require("../klass");
var touchEvent = require("./touchEvent");
Expand Down Expand Up @@ -113,4 +128,6 @@ var Drag = klass({

});

hsp.registerCustomAttributes(["ondrag", "ondragstart", "ondragmove", "ondragcancel"], Drag);
module.exports.register = function() {
hsp.registerCustomAttributes(["ondrag", "ondragstart", "ondragmove", "ondragcancel"], Drag);
};
3 changes: 2 additions & 1 deletion hsp/gestures/gesture.js
@@ -1,5 +1,5 @@
/*
* Copyright 2012 Amadeus s.a.s.
* Copyright 2014 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var klass = require("../klass");
var touchEvent = require("./touchEvent");

Expand Down
39 changes: 32 additions & 7 deletions hsp/gestures/index.js
@@ -1,7 +1,32 @@
require("./doubleTap");
require("./drag");
require("./longPress");
require("./pinch");
require("./singleTap");
require("./swipe");
require("./tap");
/*
* Copyright 2014 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var doubleTap = require("./doubleTap");
var drag = require("./drag");
var longPress = require("./longPress");
var pinch = require("./pinch");
var singleTap = require("./singleTap");
var swipe = require("./swipe");
var tap = require("./tap");

module.exports.register = function() {
doubleTap.register();
drag.register();
longPress.register();
pinch.register();
singleTap.register();
swipe.register();
tap.register();
};
19 changes: 18 additions & 1 deletion hsp/gestures/longPress.js
@@ -1,3 +1,18 @@
/*
* Copyright 2014 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var hsp = require("../rt");
var klass = require("../klass");
var touchEvent = require("./touchEvent");
Expand Down Expand Up @@ -127,4 +142,6 @@ var LongPress = klass({

});

hsp.registerCustomAttributes(["onlongpress", "onlongpressstart", "onlongpresscancel"], LongPress);
module.exports.register = function() {
hsp.registerCustomAttributes(["onlongpress", "onlongpressstart", "onlongpresscancel"], LongPress);
};
19 changes: 18 additions & 1 deletion hsp/gestures/pinch.js
@@ -1,3 +1,18 @@
/*
* Copyright 2014 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var hsp = require("../rt");
var klass = require("../klass");
var touchEvent = require("./touchEvent");
Expand Down Expand Up @@ -180,4 +195,6 @@ var Pinch = klass({

});

hsp.registerCustomAttributes(["onpinch", "onpinchstart", "onpinchmove", "onpinchcancel"], Pinch);
module.exports.register = function() {
hsp.registerCustomAttributes(["onpinch", "onpinchstart", "onpinchmove", "onpinchcancel"], Pinch);
};
19 changes: 18 additions & 1 deletion hsp/gestures/singleTap.js
@@ -1,3 +1,18 @@
/*
* Copyright 2014 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var hsp = require("../rt");
var klass = require("../klass");
var touchEvent = require("./touchEvent");
Expand Down Expand Up @@ -156,4 +171,6 @@ var SingleTap = klass({

});

hsp.registerCustomAttributes(["onsingletap", "onsingletapstart", "onsingletapcancel"], SingleTap);
module.exports.register = function() {
hsp.registerCustomAttributes(["onsingletap", "onsingletapstart", "onsingletapcancel"], SingleTap);
};
19 changes: 18 additions & 1 deletion hsp/gestures/swipe.js
@@ -1,3 +1,18 @@
/*
* Copyright 2014 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var hsp = require("../rt");
var klass = require("../klass");
var touchEvent = require("./touchEvent");
Expand Down Expand Up @@ -156,4 +171,6 @@ var Swipe = klass({

});

hsp.registerCustomAttributes(["onswipe", "onswipestart", "onswipemove", "onswipecancel"], Swipe);
module.exports.register = function() {
hsp.registerCustomAttributes(["onswipe", "onswipestart", "onswipemove", "onswipecancel"], Swipe);
};
19 changes: 18 additions & 1 deletion hsp/gestures/tap.js
@@ -1,3 +1,18 @@
/*
* Copyright 2014 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var hsp = require("../rt");
var klass = require("../klass");
var touchEvent = require("./touchEvent");
Expand Down Expand Up @@ -93,4 +108,6 @@ var Tap = klass({

});

hsp.registerCustomAttributes(["ontap", "ontapstart", "ontapcancel"], Tap);
module.exports.register = function() {
hsp.registerCustomAttributes(["ontap", "ontapstart", "ontapcancel"], Tap);
};
2 changes: 1 addition & 1 deletion hsp/gestures/touchEvent.js
@@ -1,5 +1,5 @@
/*
* Copyright 2012 Amadeus s.a.s.
* Copyright 2014 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down
20 changes: 12 additions & 8 deletions hsp/rt.js
Expand Up @@ -211,13 +211,16 @@ var customAttributesRegistry = [];
* @param {Array|String} names the name of the attributes.
* @param {Object} handler the attribute handler function, which can implement:
* - $constructor(nodeInstance, callback): used to create the handler instance.
* - setValue(name, value): called each time the attribute value changed, including when the initial value is set.
* - $dispose(): used to dispose the handler instance.
* - $setValue(name, value): called each time the attribute value changed, including when the initial value is set.
* - $onAttributesRefresh(): called at the end of the attributes'refresh process, i.e. once all attributes have their new value.
* - $handleEvent(event): called when an event for which the custom attribute registered for is fired.
* - $dispose(): used to dispose the handler instance.
* It is instanciated on each element node with one of the custom attributes.
* WARNING: when $constructor is executed, the node instance tree is not fully built, so links with other nodes (parent, children, siblinngs) must be done in setValue.
* @param {Integer} priority the priority of the handler, default value is 0, the higher the more priority (i.e. higher executed first).
* @param {Array} tags the list of tags on which the handler will apply, undefined means all.
*/
exports.registerCustomAttributes = function (names, handler, priority) {
exports.registerCustomAttributes = function (names, handler, priority, tags) {
var customAttributes = names;
if (names.constructor !== Array) {
customAttributes = [names];
Expand All @@ -227,7 +230,8 @@ exports.registerCustomAttributes = function (names, handler, priority) {
var entry = {
names: customAttributes,
handler: handler,
priority: prio
priority: prio,
tags: tags
};
customAttributesRegistry.push(entry);
}
Expand All @@ -237,16 +241,16 @@ function _handlerSorter(a, b) {
return b.priority - a.priority;
}
/**
* Returns the list of custom attributes.
* Returns the list of custom attributes for an element of type tag.
* @param {String} name the name of the attribute
* @param {String} tag the element's tag
* @return {Array} the list
*
*/
exports.getCustomAttributes = function(name) {
exports.getCustomAttributeHandlers = function(name, tag) {
var results = [];
for (var i = 0; i < customAttributesRegistry.length; i++) {
var entry = customAttributesRegistry[i];
if (entry.names.indexOf(name) > -1) {
if (entry.names.indexOf(name) > -1 && (typeof entry.tags === "undefined" || entry.tags.indexOf(tag) > -1)) {
results.push(entry);
}
}
Expand Down
2 changes: 0 additions & 2 deletions hsp/rt/$root.js
Expand Up @@ -114,7 +114,6 @@ var $RootNode = klass({
}
this.childNodes = ch;
this.argNames = argnames;
this.afterNodeCreation();
},

$dispose : function () {
Expand Down Expand Up @@ -618,7 +617,6 @@ var $CptNode = klass({
this.adirty = false;
}
TNode.refresh.call(this);
this.afterNodeCreation();
},

/**
Expand Down
17 changes: 16 additions & 1 deletion hsp/rt/attributes/class.js
@@ -1,3 +1,18 @@
/*
* Copyright 2014 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var klass = require("../../klass");

var ClassHandler = klass({
Expand All @@ -6,7 +21,7 @@ var ClassHandler = klass({
this.previousClasses = null;
},

setValue: function (name, newClasses) {
$setValue: function (name, newClasses) {
var currentClasses = this.nodeInstance.node.className;
var results = currentClasses? currentClasses.split(' '): [];
if (this.previousClasses) {
Expand Down

0 comments on commit d84f8b4

Please sign in to comment.