Author: nbelaevski
Date: 2008-06-18 18:20:15 -0400 (Wed, 18 Jun 2008)
New Revision: 9103
Modified:
trunk/sandbox/ui/hotKey/src/main/config/component/hotKey.xml
trunk/sandbox/ui/hotKey/src/main/java/org/richfaces/component/UIHotKey.java
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/hotKey.js
trunk/sandbox/ui/hotKey/src/main/templates/org/richfaces/htmlHotKey.jspx
Log:
Updated hotKey version committed
Modified: trunk/sandbox/ui/hotKey/src/main/config/component/hotKey.xml
===================================================================
--- trunk/sandbox/ui/hotKey/src/main/config/component/hotKey.xml 2008-06-18 22:20:05 UTC
(rev 9102)
+++ trunk/sandbox/ui/hotKey/src/main/config/component/hotKey.xml 2008-06-18 22:20:15 UTC
(rev 9103)
@@ -43,7 +43,7 @@
<defaultvalue>"immediate"</defaultvalue>
</property>
<property>
- <name>target</name>
+ <name>selector</name>
<classname>java.lang.String</classname>
<description>
</description>
@@ -57,12 +57,6 @@
<defaultvalue>""</defaultvalue>
</property>
<property>
- <name>propagate</name>
- <classname>java.lang.Boolean</classname>
- <description>
- </description>
- </property>
- <property>
<name>disableInInput</name>
<classname>java.lang.Boolean</classname>
<description>
Modified: trunk/sandbox/ui/hotKey/src/main/java/org/richfaces/component/UIHotKey.java
===================================================================
--- trunk/sandbox/ui/hotKey/src/main/java/org/richfaces/component/UIHotKey.java 2008-06-18
22:20:05 UTC (rev 9102)
+++ trunk/sandbox/ui/hotKey/src/main/java/org/richfaces/component/UIHotKey.java 2008-06-18
22:20:15 UTC (rev 9103)
@@ -1,5 +1,22 @@
/**
+ * License Agreement.
*
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.richfaces.component;
Modified:
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/hotKey.js
===================================================================
---
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/hotKey.js 2008-06-18
22:20:05 UTC (rev 9102)
+++
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/hotKey.js 2008-06-18
22:20:15 UTC (rev 9103)
@@ -1,15 +1,25 @@
if (!window.Richfaces) window.Richfaces = {};
-Richfaces.hotKey = function() {
+Richfaces.hotKey = function() {
this.initialize.apply(this, arguments);
};
+Richfaces.hotKey.resolveHandler = function(handlerBody) {
+ if (handlerBody) {
+ if (typeof handlerBody == "function") {
+ return handlerBody;
+ } else {
+ return new Function("event", handlerBody);
+ }
+ }
+};
+
jQuery.extend(Richfaces.hotKey.prototype, {
- initialize: function(id, key, targetId, options, handler) {
+ initialize: function(id, key, selector, options, handler) {
this.id = id;
- this.targetId = targetId;
+ this.selector = selector;
this.key = key;
- this.options = options;
+ this.baseOptions = options;
this.handler = handler;
this["rich:destructor"] = "destroy";
@@ -17,38 +27,119 @@
this.element.component = this;
if ("immediate" == options.timing) {
- this.add();
+ this.enable();
} else if ("onload" == options.timing) {
var _this = this;
jQuery(document).ready(function() {
- _this.add();
+ _this.enable();
});
}
},
destroy: function() {
- this.remove();
+ this.disable();
this.element.component = null;
this.element = null;
},
- _hasTarget: function() {
- return !this.targetId || this.options.target;
+ buildOptions: function(selector, argOptions) {
+ var result = new Array();
+
+ var elts;
+
+ if (typeof selector == "string") {
+ elts = jQuery(selector);
+ } else if (selector.constructor == Array) {
+ elts = new Array();
+
+ for (var i = 0; i < selector.length; i++) {
+ var s = selector[i];
+
+ if (!s.nodeType) {
+ var q = jQuery(s);
+ for (var j = 0; j < q.length; j++) {
+ elts.push(q[j]);
+ }
+ } else {
+ elts.push(s);
+ }
+ }
+ } else {
+ elts = [selector];
+ }
+
+ for (var i = 0; i < elts.length; i++) {
+
+ var options = jQuery.extend({}, this.baseOptions, argOptions);
+ options.target = elts[i];
+
+ result.push(options);
+ }
+
+ return result;
},
- add: function () {
- if (this.targetId) {
- this.options.target = jQuery(this.targetId)[0];
- }
+ _getComponentControlParameters: function(args) {
+ return args.length <= 1 ? args[0] : args[1];
+ },
+
+ _generalAdd: function(key, options, handler) {
+ var _handler = function() {
+ if (handler.apply(this, arguments) === false) {
+ var event = arguments[0];
+
+ event.stopPropagation();
+ event.preventDefault();
+ }
+ };
- if (this._hasTarget()) {
- jQuery.hotkeys.add(this.key, this.options, this.handler);
+ for (var i = 0; i < options.length; i++) {
+ jQuery.hotkeys.add(key, options[i], _handler);
}
},
+
+ _generalRemove: function(key, options) {
+ for (var i = 0; i < options.length; i++) {
+ jQuery.hotkeys.remove(key, options[i]);
+ }
+ },
- remove: function () {
- if (this._hasTarget()) {
- jQuery.hotkeys.remove(this.key, this.options);
+ enable: function () {
+ if (!this.options) {
+ this.options = this.buildOptions(this.selector);
}
+
+ this._generalAdd(this.key, this.options, this.handler);
+ },
+
+ add: function() {
+ var parameters = this._getComponentControlParameters(arguments);
+
+ var selector = parameters.selector || this.selector;
+ var key = parameters.key || this.key;
+ var handler = parameters.handler || this.handler;
+
+ var options = this.buildOptions(selector, parameters);
+
+ this._generalAdd(key, options, this.constructor.resolveHandler(handler));
+ },
+
+ disable: function () {
+ if (!this.options) {
+ this.options = this.buildOptions(this.selector);
+ }
+
+ this._generalRemove(this.key, this.options);
+ },
+
+ remove: function() {
+ var parameters = this._getComponentControlParameters(arguments);
+
+ var selector = parameters.selector || this.selector;
+ var key = parameters.key || this.key;
+
+ var options = this.buildOptions(selector, parameters);
+
+ this._generalRemove(key, options);
}
-})
\ No newline at end of file
+});
\ No newline at end of file
Modified: trunk/sandbox/ui/hotKey/src/main/templates/org/richfaces/htmlHotKey.jspx
===================================================================
--- trunk/sandbox/ui/hotKey/src/main/templates/org/richfaces/htmlHotKey.jspx 2008-06-18
22:20:05 UTC (rev 9102)
+++ trunk/sandbox/ui/hotKey/src/main/templates/org/richfaces/htmlHotKey.jspx 2008-06-18
22:20:15 UTC (rev 9103)
@@ -22,8 +22,16 @@
options = new StringBuilder("{");
String timing = (String) attributes.get("timing");
+
+ if (!"onload".equals(timing) &&
!"immediate".equals(timing) &&
+ !"onregistercall".equals(timing)) {
+
+ throw new IllegalArgumentException("The timing attribute of the hotKey component
(id='"+clientId+"') has an invalid value:'"+ timing +
+ "'. It may have only the following values: 'immediate',
'onload', 'onregistercall'");
+ }
+
options.append("timing:'");
- options.append(timing);
+ options.append(timing.toString());
options.append("'");
String type = (String) attributes.get("type");
@@ -55,12 +63,12 @@
]]>
</jsp:scriptlet>
- <c:object var="targetId" type="java.lang.String"
value=""/>
+ <c:object var="selector" type="java.lang.String"
value=""/>
<jsp:scriptlet>
<![CDATA[
- targetId = (String) attributes.get("target");
- if (targetId != null && targetId.length() != 0) {
- targetId = HtmlUtil.expandIdSelector(targetId, component, context);
+ selector = (String) attributes.get("selector");
+ if (selector != null && selector.length() != 0) {
+ selector = HtmlUtil.expandIdSelector(selector, component, context);
}
]]>
</jsp:scriptlet>
@@ -70,7 +78,7 @@
<script>
- new
Richfaces.hotKey("#{clientId}","#{attributes['key']}","#{targetId}",
#{options}, function() { #{attributes['handler']} });
+ new
Richfaces.hotKey("#{clientId}","#{attributes['key']}","#{selector}",
#{options}, function(event) { #{attributes['handler']} });
</script>
</span>
</f:root>
\ No newline at end of file