Author: pyaschenko
Date: 2010-03-16 10:26:13 -0400 (Tue, 16 Mar 2010)
New Revision: 16583
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-base-component.js
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-event.js
root/framework/trunk/impl/src/test/resources/javascript/richfaces-client-api.html
root/framework/trunk/impl/src/test/resources/javascript/richfaces-event-qunit.js
Log:
Events api changes + new qtest was added
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-base-component.js
===================================================================
---
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-base-component.js 2010-03-16
11:17:44 UTC (rev 16582)
+++
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-base-component.js 2010-03-16
14:26:13 UTC (rev 16583)
@@ -25,6 +25,9 @@
}
result[result.length] = this.name;
return result.join(', ');
+ },
+ getEventElement: function() {
+ return "#"+this.id;
}
};
})(params));
@@ -34,7 +37,7 @@
(function (jQuery, richfaces, params) {
richfaces.MyComponent = function(componentId) {
- $super.constructor.call(this);
+ $super.constructor.call(this, componentId);
};
var $super = richfaces.BaseComponent.extend(richfaces.BaseComponent,
richfaces.MyComponent);
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-event.js
===================================================================
---
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-event.js 2010-03-16
11:17:44 UTC (rev 16582)
+++
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-event.js 2010-03-16
14:26:13 UTC (rev 16583)
@@ -1,6 +1,20 @@
(function($, richfaces) {
richfaces.Event = richfaces.Event || {};
+ var getEventElement = function (selector) {
+ if (!selector) {
+ throw "RichFaces.Event: empty selector";
+ }
+ var element;
+ if (RichFaces.BaseComponent && selector instanceof RichFaces.BaseComponent) {
+ element = jQuery(selector.getEventElement());
+ } else {
+ element = jQuery(selector);
+ }
+
+ return element;
+ }
+
$.extend(richfaces.Event, {
RICH_NAMESPACE : "RICH:",
ready : function(fn) {
@@ -17,7 +31,7 @@
var f = function (e,d){
e.data.fn.call(e.data.component||this, e, this, d);
};
- $(selector).bind(type, {component: data, fn:fn}, f);
+ getEventElement(selector).bind(type, {component: data, fn:fn}, f);
return f;
},
bindById : function(id, type, fn, data) {
@@ -33,7 +47,7 @@
var f = function (e,d){
e.data.fn.call(e.data.component||this, e, this, d);
};
- $(selector).one(type, {component: data, fn:fn}, f);
+ getEventElement(selector).one(type, {component: data, fn:fn}, f);
return f;
},
bindOneById: function(id, type, fn, data) {
@@ -46,20 +60,20 @@
},
unbind : function(selector, type, fn) {
// type: namespace can be used, like onclick.rf.conponentName
- return $(selector).unbind(type, fn);
+ return getEventElement(selector).unbind(type, fn);
},
unbindById : function(id, type, fn) {
// type: namespace can be used, like onclick.rf.conponentName
return $(document.getElementById(id)).unbind(type, fn);
},
fire : function(selector, event, data) {
- return $(selector).trigger(event, data);
+ return getEventElement(selector).trigger(event, data);
},
fireById : function(id, event, data) {
return $(document.getElementById(id)).trigger(event, data);
},
callHandler : function(selector, event, data) {
- return $(selector).triggerHandler(event, data);
+ return getEventElement(selector).triggerHandler(event, data);
},
callHandlerById : function(id, event, data) {
return $(document.getElementById(id)).triggerHandler(event, data);
Modified:
root/framework/trunk/impl/src/test/resources/javascript/richfaces-client-api.html
===================================================================
---
root/framework/trunk/impl/src/test/resources/javascript/richfaces-client-api.html 2010-03-16
11:17:44 UTC (rev 16582)
+++
root/framework/trunk/impl/src/test/resources/javascript/richfaces-client-api.html 2010-03-16
14:26:13 UTC (rev 16583)
@@ -8,6 +8,7 @@
<script type="text/javascript"
src="../../classes/META-INF/resources/jquery.js"></script>
<script type="text/javascript"
src="qunit/qunit.js"></script>
<script type="text/javascript"
src="../../classes/META-INF/resources/richfaces.js"></script>
+ <script type="text/javascript"
src="../../classes/META-INF/resources/richfaces-base-component.js"></script>
<script type="text/javascript"
src="../../classes/META-INF/resources/richfaces-event.js"></script>
<script type="text/javascript"
src="richfaces-qunit.js"></script>
<script type="text/javascript"
src="richfaces-event-qunit.js"></script>
Modified:
root/framework/trunk/impl/src/test/resources/javascript/richfaces-event-qunit.js
===================================================================
---
root/framework/trunk/impl/src/test/resources/javascript/richfaces-event-qunit.js 2010-03-16
11:17:44 UTC (rev 16582)
+++
root/framework/trunk/impl/src/test/resources/javascript/richfaces-event-qunit.js 2010-03-16
14:26:13 UTC (rev 16583)
@@ -50,6 +50,18 @@
RichFaces.Event.fire("#"+elementId, "click");
ok(element.onEvent, "fire event");
});
+
+ // component bind test
+ test("RichFaces.Event.bind selector as BaseComponent", function() {
+ expect(2);
+ var element = createNextTestElement();
+ var c = new RichFaces.BaseComponent(element.id);
+ var fn = setupEmptyCallback(element);
+ var f = RichFaces.Event.bind(c, "click", fn);
+ equals(typeof f, "function");
+ RichFaces.Event.fire(c, "click");
+ ok(element.onEvent, "fire event");
+ });
// fire test
test("RichFaces.Event.fire", function() {