Author: nbelaevski
Date: 2008-06-12 18:32:30 -0400 (Thu, 12 Jun 2008)
New Revision: 9024
Modified:
trunk/sandbox/ui/hotKey/src/main/config/component/hotKey.xml
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/jquery.hotkeys.js
trunk/sandbox/ui/hotKey/src/main/templates/org/richfaces/htmlHotKey.jspx
Log:
Latest updates for rich:hotKey
Modified: trunk/sandbox/ui/hotKey/src/main/config/component/hotKey.xml
===================================================================
--- trunk/sandbox/ui/hotKey/src/main/config/component/hotKey.xml 2008-06-12 22:32:22 UTC
(rev 9023)
+++ trunk/sandbox/ui/hotKey/src/main/config/component/hotKey.xml 2008-06-12 22:32:30 UTC
(rev 9024)
@@ -57,7 +57,7 @@
<defaultvalue>""</defaultvalue>
</property>
<property>
- <name>propagete</name>
+ <name>propagate</name>
<classname>java.lang.Boolean</classname>
<description>
</description>
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-12
22:32:22 UTC (rev 9023)
+++
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/hotKey.js 2008-06-12
22:32:30 UTC (rev 9024)
@@ -1,38 +1,54 @@
if (!window.Richfaces) window.Richfaces = {};
-Richfaces.hotKey = function(id, key, options, handler) {
- this.id = id;
- this.key = key;
- this.options = options;
- this.handler = handler;
- this["rich:destructor"] = "destroy";
- document.getElementById(id).component = this;
+Richfaces.hotKey = function() {
+ this.initialize.apply(this, arguments);
+};
+
+jQuery.extend(Richfaces.hotKey.prototype, {
+ initialize: function(id, key, targetId, options, handler) {
+ this.id = id;
+ this.targetId = targetId;
+ this.key = key;
+ this.options = options;
+ this.handler = handler;
+ this["rich:destructor"] = "destroy";
- this.invoke = function() {
- this.add(this.key, this.options, this.handler);
- }
- this.destroy = function() {
+ this.element = document.getElementById(id);
+ this.element.component = this;
+
+ if ("immediate" == options.timing) {
+ this.add();
+ } else if ("onload" == options.timing) {
+ var _this = this;
+ jQuery(document).ready(function() {
+ _this.add();
+ });
+ }
+ },
+
+ destroy: function() {
+ this.remove();
this.element.component = null;
this.element = null;
- this.hotKey = null;
- }
- this.add = function (key, options, handler) {
- jQuery.hotkeys.add(key, options, function(){ eval(handler) });
- }
+ },
- this.remove = function () {
- jQuery.hotkeys.remove(this.key, this.options);
- }
+ _hasTarget: function() {
+ return !this.targetId || this.options.target;
+ },
+
+ add: function () {
+ if (this.targetId) {
+ this.options.target = jQuery(this.targetId)[0];
+ }
+
+ if (this._hasTarget()) {
+ jQuery.hotkeys.add(this.key, this.options, this.handler);
+ }
+ },
- if ("immediate" == options.timing) {
- this.invoke();
- } else if ("onload" == options.timing) {
- jQuery(document).ready(function() {
- if ("add" == options.operation)
- jQuery.hotkeys.add(key, options, function(){ eval(handler) });
- else if ("remove" == options.operation)
- jQuery.hotkeys.remove(key, options);
- });
+ remove: function () {
+ if (this._hasTarget()) {
+ jQuery.hotkeys.remove(this.key, this.options);
+ }
}
-
-};
\ No newline at end of file
+})
\ No newline at end of file
Modified:
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/jquery.hotkeys.js
===================================================================
---
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/jquery.hotkeys.js 2008-06-12
22:32:22 UTC (rev 9023)
+++
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/jquery.hotkeys.js 2008-06-12
22:32:30 UTC (rev 9024)
@@ -37,7 +37,25 @@
this.shift_nums = { "`":"~", "1":"!",
"2":"@", "3":"#", "4":"$",
"5":"%", "6":"^", "7":"&",
"8":"*", "9":"(",
"0":")", "-":"_", "=":"+",
";":":", "'":"\"",
",":"<",
".":">", "/":"?",
"\\":"|" };
-
+
+ this._uniqueIDIndex = 1;
+
+ this._uniqueIDExpando = "_jQuery_hotKeys";
+
+ this._uniqueID = function(node) {
+ var id = node[this._uniqueIDExpando];
+
+ if (!id) {
+ id = node[this._uniqueIDExpando] = this._uniqueIDIndex++;
+ }
+
+ return id;
+ };
+
+ this._checkUniqueID = function(node) {
+ return node[this._uniqueIDExpando];
+ };
+
this.add = function(combi, options, callback) {
if (jQuery.isFunction(options)){
callback = options;
@@ -76,12 +94,12 @@
// for example: 'keydown' might be associated with HtmlBodyElement
// or the element where you last clicked with your mouse.
if (jQuery.browser.opera || jQuery.browser.safari || opt.checkParent){
- while (!that.all[element] && element.parentNode){
+ while (!that.all[that._checkUniqueID(element)] &&
element.parentNode){
element = element.parentNode;
}
}
- var cbMap = that.all[element].events[type].callbackMap;
+ var cbMap = that.all[that._checkUniqueID(element)].events[type].callbackMap;
if(!shift && !ctrl && !alt) { // No Modifiers
mapPoint = cbMap[special] || cbMap[character]
}
@@ -103,15 +121,18 @@
}
}
};
+
+ var targetData = this._uniqueID(opt.target);
+
// first hook for this element
- if (!this.all[opt.target]){
- this.all[opt.target] = {events:{}};
+ if (!this.all[targetData]){
+ this.all[targetData] = {events:{}};
}
- if (!this.all[opt.target].events[opt.type]){
- this.all[opt.target].events[opt.type] = {callbackMap: {}}
+ if (!this.all[targetData].events[opt.type]){
+ this.all[targetData].events[opt.type] = {callbackMap: {}}
jQuery.event.add(opt.target, opt.type, inspector);
}
- this.all[opt.target].events[opt.type].callbackMap[combi] = {cb: callback,
propagate:opt.propagate};
+ this.all[targetData].events[opt.type].callbackMap[combi] = {cb: callback,
propagate:opt.propagate};
return jQuery;
};
this.remove = function(exp, opt) {
@@ -119,7 +140,7 @@
target = opt.target || jQuery('html')[0];
type = opt.type || 'keydown';
exp = exp.toLowerCase();
- delete this.all[target].events[type].callbackMap[exp]
+ delete this.all[this._checkUniqueID(target)].events[type].callbackMap[exp]
return jQuery;
};
jQuery.hotkeys = this;
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-12
22:32:22 UTC (rev 9023)
+++ trunk/sandbox/ui/hotKey/src/main/templates/org/richfaces/htmlHotKey.jspx 2008-06-12
22:32:30 UTC (rev 9024)
@@ -10,60 +10,67 @@
component="org.richfaces.component.UIHotKey"
<f:clientid var="clientId"/>
- <c:set var="key"
value="#{component.attributes['key']}"/>
- <c:set var="timing"
value="#{component.attributes['timing']}"/>
- <c:set var="type"
value="#{component.attributes['type']}"/>
- <c:set var="propagete"
value="#{component.attributes['propagete']}"/>
- <c:set var="disableInInput"
value="#{component.attributes['disableInInput']}"/>
- <c:set var="checkParent"
value="#{component.attributes['checkParent']}"/>
- <c:set var="handler"
value="#{component.attributes['handler']}"/>
+
+ <c:object var="attributes" type="java.util.Map"
value="#{component.attributes}" />
+ <c:object var="options" type="java.lang.StringBuilder" />
+ <jsp:directive.page import="org.richfaces.component.util.HtmlUtil" />
+
<h:scripts>/org/richfaces/renderkit/html/scripts/jquery/jquery.js,/org/richfaces/renderkit/html/scripts/jquery.hotkeys.js,/org/richfaces/renderkit/html/scripts/hotKey.js</h:scripts>
<jsp:scriptlet>
<![CDATA[
+ options = new StringBuilder("{");
- StringBuffer options = new StringBuffer("{");
-
- String timing = (String) variables.getVariable("timing");
+ String timing = (String) attributes.get("timing");
options.append("timing:'");
options.append(timing);
options.append("'");
- String type = (String) variables.getVariable("type");
- if (! type.equals("")) {
+ String type = (String) attributes.get("type");
+ if (type != null && type.length() != 0) {
options.append(",type:'");
options.append(type);
options.append("'");
}
- String propagete = (String) variables.getVariable("propagete");
- if (propagete!=null) {
- options.append(",propagete:");
- options.append(propagete);
+
+ Boolean propagate = (Boolean) attributes.get("propagate");
+ if (propagate != null) {
+ options.append(",propagate:");
+ options.append(propagate);
}
- String disableInInput = (String) variables.getVariable("disableInInput");
- if (disableInInput!=null) {
+ Boolean disableInInput = (Boolean) attributes.get("disableInInput");
+ if (disableInInput != null) {
options.append(",disableInInput:");
options.append(disableInInput);
}
- String checkParent = (String) variables.getVariable("checkParent");
- if (checkParent!=null) {
+ Boolean checkParent = (Boolean) attributes.get("checkParent");
+ if (checkParent != null) {
options.append(",checkParent:");
options.append(checkParent);
}
-
options.append("}");
- variables.setVariable("options", options);
]]>
</jsp:scriptlet>
+
+ <c:object var="targetId" 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);
+ }
+ ]]>
+ </jsp:scriptlet>
+
<span id="#{clientId}" style="display:none"
x:passThruWithExclusions="id"
<script>
- new Richfaces.hotKey("#{clientId}","#{key}", #{options},
"#{handler}");
+ new
Richfaces.hotKey("#{clientId}","#{attributes['key']}","#{targetId}",
#{options}, function() { #{attributes['handler']} });
</script>
</span>
</f:root>
\ No newline at end of file