From: Julien Dramaix Date: Wed, 22 Aug 2012 22:01:02 +0000 (+0000) Subject: implements mouseleave mouseenter special events + bug fixing on event mechanism X-Git-Tag: release-1.3.2~67 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a428b4a1b58a126a3e8190a04cd129543b96d895;p=gwtquery.git implements mouseleave mouseenter special events + bug fixing on event mechanism --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java index 134e84cb..7bbae11e 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java @@ -1,16 +1,14 @@ /* * Copyright 2011, The gwtquery team. * - * 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 + * 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 + * 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. */ package com.google.gwt.query.client; @@ -76,7 +74,7 @@ public class GQuery implements Lazy { private enum DomMan { AFTER, APPEND, BEFORE, PREPEND; } - + /** * A POJO used to store the top/left CSS positioning values of an element. */ @@ -99,16 +97,16 @@ public class GQuery implements Lazy { } /** - * Class used internally to create DOM element from html snippet + * Class used internally to create DOM element from html snippet */ private static class TagWrapper { public static final TagWrapper DEFAULT = new TagWrapper(0, "", ""); - private String postWrap; + private String postWrap; private String preWrap; private int wrapDepth; - + public TagWrapper(int wrapDepth, String preWrap, String postWrap) { - this.wrapDepth=wrapDepth; + this.wrapDepth = wrapDepth; this.postWrap = postWrap; this.preWrap = preWrap; } @@ -123,17 +121,17 @@ public class GQuery implements Lazy { * The body element in the current page. */ public static final BodyElement body = Document.get().getBody(); - + /** * Object to store element data. */ protected static JsCache dataCache = null; - + /** * The document element in the current page. */ public static final Document document = Document.get(); - + /** * Static reference Effects plugin */ @@ -153,14 +151,15 @@ public class GQuery implements Lazy { * A static reference to the GQuery class. */ public static Class GQUERY = GQuery.class; - + private static final String OLD_DATA_PREFIX = "old-"; private static JsMap, Plugin> plugins; // Sizzle POS regex : usefull in some methods // TODO: Share this static with SelectorEngineSizzle - private static final String POS_REGEX = ":(nth|eq|gt|lt|first|last|even|odd)(?:\\((\\d*)\\))?(?=[^\\-]|$)"; + private static final String POS_REGEX = + ":(nth|eq|gt|lt|first|last|even|odd)(?:\\((\\d*)\\))?(?=[^\\-]|$)"; /** * Implementation class used for style manipulations. @@ -173,23 +172,23 @@ public class GQuery implements Lazy { * Static reference to the Widgets plugin */ public static Class Widgets = com.google.gwt.query.client.plugins.Widgets.Widgets; - + /** * The window object. */ public static final Element window = window(); - + private static Element windowData = null; - + private static JsNamedArray wrapperMap; - + /** * Create an empty GQuery object. */ public static GQuery $() { return new GQuery(JsNodeArray.create()); } - + /** * Wrap a GQuery around an existing element. */ @@ -201,8 +200,7 @@ public class GQuery implements Lazy { * Wrap a GQuery around an event's target element. */ public static GQuery $(Event event) { - return event == null ? $() - : $((Element) event.getCurrentEventTarget().cast()); + return event == null ? $() : $((Element) event.getCurrentEventTarget().cast()); } /** @@ -211,19 +209,16 @@ public class GQuery implements Lazy { public static GQuery $(Function f) { return $(f.getElement()); } - + /** * Wrap a GQuery around an existing element, event, node or nodelist. */ public static GQuery $(JavaScriptObject e) { - return - JsUtils.isWindow(e) ? GQuery.$(e.cast()) : - JsUtils.isElement(e) ? GQuery.$(e.cast()) : - JsUtils.isEvent(e) ? GQuery.$(e.cast()) : - JsUtils.isNodeList(e) ? GQuery.$(e.>cast()) : - $(); + return JsUtils.isWindow(e) ? GQuery.$(e. cast()) : JsUtils.isElement(e) ? GQuery.$(e + . cast()) : JsUtils.isEvent(e) ? GQuery.$(e. cast()) : JsUtils + .isNodeList(e) ? GQuery.$(e.> cast()) : $(); } - + /** * Create a new GQuery given a list of nodes, elements or widgets */ @@ -245,7 +240,7 @@ public class GQuery implements Lazy { * Wrap a GQuery around an existing node. */ public static GQuery $(Node n) { - return $((Element)n); + return $((Element) n); } /** @@ -256,20 +251,18 @@ public class GQuery implements Lazy { } /** - * This function accepts a string containing a CSS selector which is then used - * to match a set of elements, or it accepts raw HTML creating a GQuery - * element containing those elements. - * Xpath selector is supported in browsers with native xpath engine. + * This function accepts a string containing a CSS selector which is then used to match a set of + * elements, or it accepts raw HTML creating a GQuery element containing those elements. Xpath + * selector is supported in browsers with native xpath engine. */ public static GQuery $(String selectorOrHtml) { return $(selectorOrHtml, document); } /** - * This function accepts a string containing a CSS selector which is then used - * to match a set of elements, or it accepts raw HTML creating a GQuery - * element containing those elements. The second parameter is is a class - * reference to a plugin to be used. + * This function accepts a string containing a CSS selector which is then used to match a set of + * elements, or it accepts raw HTML creating a GQuery element containing those elements. The + * second parameter is is a class reference to a plugin to be used. * * Xpath selector is supported in browsers with native xpath engine. */ @@ -278,11 +271,10 @@ public class GQuery implements Lazy { } /** - * This function accepts a string containing a CSS selector which is then used - * to match a set of elements, or it accepts raw HTML creating a GQuery - * element containing those elements. The second parameter is the context to - * use for the selector, or the document where the new elements will be - * created. + * This function accepts a string containing a CSS selector which is then used to match a set of + * elements, or it accepts raw HTML creating a GQuery element containing those elements. The + * second parameter is the context to use for the selector, or the document where the new elements + * will be created. * * Xpath selector is supported in browsers with native xpath engine. */ @@ -297,21 +289,19 @@ public class GQuery implements Lazy { return new GQuery().select(selectorOrHtml, ctx); } - /** - * This function accepts a string containing a CSS selector which is then used - * to match a set of elements, or it accepts raw HTML creating a GQuery - * element containing those elements. The second parameter is the context to - * use for the selector. The third parameter is the class plugin to use. + /** + * This function accepts a string containing a CSS selector which is then used to match a set of + * elements, or it accepts raw HTML creating a GQuery element containing those elements. The + * second parameter is the context to use for the selector. The third parameter is the class + * plugin to use. * * Xpath selector is supported in browsers with native xpath engine. */ @SuppressWarnings("unchecked") - public static T $(String selector, Node context, - Class plugin) { + public static T $(String selector, Node context, Class plugin) { try { if (plugins != null) { - T gquery = (T) plugins.get(plugin).init( - new GQuery().select(selector, context)); + T gquery = (T) plugins.get(plugin).init(new GQuery().select(selector, context)); return gquery; } throw new RuntimeException("No plugin for class " + plugin); @@ -320,12 +310,11 @@ public class GQuery implements Lazy { } } - /** - * This function accepts a string containing a CSS selector which is then used - * to match a set of elements, or it accepts raw HTML creating a GQuery - * element containing those elements. The second parameter is the context to - * use for the selector, or the document where the new elements will be - * created. + /** + * This function accepts a string containing a CSS selector which is then used to match a set of + * elements, or it accepts raw HTML creating a GQuery element containing those elements. The + * second parameter is the context to use for the selector, or the document where the new elements + * will be created. * * Xpath selector is supported in browsers with native xpath engine. */ @@ -334,19 +323,18 @@ public class GQuery implements Lazy { } /** - * This function accepts a string containing a CSS selector which is then used - * to match a set of elements, or it accepts raw HTML creating a GQuery - * element containing those elements. The second parameter is the context to - * use for the selector. The third parameter is the class plugin to use. - * + * This function accepts a string containing a CSS selector which is then used to match a set of + * elements, or it accepts raw HTML creating a GQuery element containing those elements. The + * second parameter is the context to use for the selector. The third parameter is the class + * plugin to use. + * * Xpath selector is supported in browsers with native xpath engine. */ - public static T $(String selector, Widget context, - Class plugin) { + public static T $(String selector, Widget context, Class plugin) { return $(selector, context.getElement(), plugin); } - /** + /** * wraps a GQuery or a plugin object */ public static T $(T gq) { @@ -370,43 +358,43 @@ public class GQuery implements Lazy { /** * Perform an ajax request to the server. */ - public static void ajax(Properties p) { - ajax(p); - } + public static void ajax(Properties p) { + ajax(p); + } /** * Perform an ajax request to the server. */ - public static void ajax(Settings settings) { - Ajax.ajax(settings); - } + public static void ajax(Settings settings) { + Ajax.ajax(settings); + } /** * Perform an ajax request to the server. */ - public static void ajax(String url, Settings settings) { - Ajax.ajax(url, settings); - } + public static void ajax(String url, Settings settings) { + Ajax.ajax(url, settings); + } @SuppressWarnings("unchecked") protected static GQuery cleanHtmlString(String elem, Document doc) { - + String tag = tagNameRegex.exec(elem).get(1); - - if (tag == null){ - throw new RuntimeException("HTML snippet doesn't contain any tag"); + + if (tag == null) { + throw new RuntimeException("HTML snippet doesn't contain any tag"); } - - if (wrapperMap == null){ + + if (wrapperMap == null) { initWrapperMap(); } - + TagWrapper wrapper = wrapperMap.get(tag.toLowerCase()); - - if (wrapper == null){ + + if (wrapper == null) { wrapper = TagWrapper.DEFAULT; } - + // TODO: fix IE link tag serialization // TODO: fix IE