{"action":"created","comment":{"url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/pulls/comments/22729562","id":22729562,"diff_hunk":"@@ -0,0 +1,218 @@\n+/**\n+ * Copyright 2015 ArcBees Inc.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n+ * use this file except in compliance with the License. You may obtain a copy of\n+ * the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n+ * License for the specific language governing permissions and limitations under\n+ * the License.\n+ */\n+\n+package com.arcbees.gquery.appear.client;\n+\n+import java.util.HashMap;\n+import java.util.Map;\n+\n+import com.google.gwt.core.client.Scheduler;\n+import com.google.gwt.dom.client.Document;\n+import com.google.gwt.dom.client.Element;\n+import com.google.gwt.event.shared.HandlerRegistration;\n+import com.google.gwt.query.client.Function;\n+import com.google.gwt.query.client.GQuery;\n+import com.google.gwt.query.client.plugin.Observe;\n+import com.google.gwt.query.client.plugins.Plugin;\n+import com.google.gwt.user.client.Window;\n+\n+public class Appear extends GQuery {\n+    public static final Class<Appear> Appear = GQuery.registerPlugin(Appear.class, new Plugin<Appear>() {\n+        public Appear init(GQuery gq) {\n+            return new Appear(gq);\n+        }\n+    });\n+\n+    private static final String DISAPPEAR_EVENT = \"disappear\";\n+    private static final String APPEAR_EVENT = \"appear\";\n+    private static final Map<Element, AppearImpl> impls = new HashMap<Element, AppearImpl>();\n+\n+    private static HandlerRegistration handlerRegistration;\n+\n+    protected Appear(GQuery gq) {\n+        super(gq);\n+    }\n+\n+    public Appear appear(Function... f) {\n+        on(APPEAR_EVENT, f);\n+\n+        for (Element element : elements()) {\n+            AppearImpl impl = getOrCreateImpl(element);\n+            impl.setAppear(true);\n+        }\n+\n+        maybeInitHandlers();\n+\n+        return this;\n+    }\n+\n+    public Appear appearOff() {\n+        off(APPEAR_EVENT);\n+\n+        for (Element element : elements()) {\n+            AppearImpl impl = getImpl(element);\n+            if (impl != null) {\n+                if (impl.isDisappear()) {\n+                    impl.setAppear(false);\n+                } else {\n+                    impls.remove(impl);\n+                }\n+            }\n+        }\n+\n+        maybeUnbindHandlers();\n+\n+        return this;\n+    }\n+\n+    public Appear disappear(Function... f) {\n+        on(DISAPPEAR_EVENT, f);\n+\n+        for (Element element : elements()) {\n+            AppearImpl impl = getOrCreateImpl(element);\n+\n+            impl.setDisappear(true);\n+        }\n+\n+        maybeInitHandlers();\n+\n+        return this;\n+    }\n+\n+    public Appear disappearOff() {\n+        off(DISAPPEAR_EVENT);\n+\n+        for (Element element : elements()) {\n+            AppearImpl impl = getImpl(element);\n+\n+            if (impl != null) {\n+                if (impl.isAppear()) {\n+                    impl.setDisappear(false);\n+                } else {\n+                    impls.remove(impl);\n+                }\n+            }\n+        }\n+\n+        maybeUnbindHandlers();\n+\n+        return this;\n+    }\n+\n+    private void maybeUnbindHandlers() {\n+        if (impls.isEmpty()) {\n+            handlerRegistration.removeHandler();\n+            handlerRegistration = null;\n+        }\n+    }\n+\n+    private void maybeInitHandlers() {\n+        if (handlerRegistration == null) {\n+            final HandlerRegistration scrollHandler = Window.addWindowScrollHandler(new Window.ScrollHandler() {\n+                @Override\n+                public void onWindowScroll(Window.ScrollEvent event) {\n+                    checkElementsAppearance();\n+                }\n+            });\n+\n+            final Observe observeHandler = $(Document.get()).as(Observe.Observe)","path":"appear/src/main/java/com/arcbees/gquery/appear/client/Appear.java","position":131,"original_position":131,"commit_id":"6d2a0d7a8781d0af2aaaa55c9ff85414ede7ab0b","original_commit_id":"f03e5b7baa42a90ecebde91d97b33ae9c0aaffcb","user":{"login":"meriouma","id":1082552,"avatar_url":"https://avatars.githubusercontent.com/u/1082552?v=3","gravatar_id":"","url":"https://api.github.com/users/meriouma","html_url":"https://github.com/meriouma","followers_url":"https://api.github.com/users/meriouma/followers","following_url":"https://api.github.com/users/meriouma/following{/other_user}","gists_url":"https://api.github.com/users/meriouma/gists{/gist_id}","starred_url":"https://api.github.com/users/meriouma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meriouma/subscriptions","organizations_url":"https://api.github.com/users/meriouma/orgs","repos_url":"https://api.github.com/users/meriouma/repos","events_url":"https://api.github.com/users/meriouma/events{/privacy}","received_events_url":"https://api.github.com/users/meriouma/received_events","type":"User","site_admin":false},"body":"Although it could be both I guess, as if it's by selected elements I'd still need the observer on the document if it's enabled for some elements","created_at":"2015-01-09T17:31:39Z","updated_at":"2015-01-09T17:31:39Z","html_url":"https://github.com/ArcBees/gwtquery-appear-plugin/pull/1#discussion_r22729562","pull_request_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/pulls/comments/22729562"},"html":{"href":"https://github.com/ArcBees/gwtquery-appear-plugin/pull/1#discussion_r22729562"},"pull_request":{"href":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/pulls/1","id":27112858,"html_url":"https://github.com/ArcBees/gwtquery-appear-plugin/pull/1","diff_url":"https://github.com/ArcBees/gwtquery-appear-plugin/pull/1.diff","patch_url":"https://github.com/ArcBees/gwtquery-appear-plugin/pull/1.patch","issue_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/issues/1","number":1,"state":"open","locked":false,"title":"Created Appear plugin","user":{"login":"meriouma","id":1082552,"avatar_url":"https://avatars.githubusercontent.com/u/1082552?v=3","gravatar_id":"","url":"https://api.github.com/users/meriouma","html_url":"https://github.com/meriouma","followers_url":"https://api.github.com/users/meriouma/followers","following_url":"https://api.github.com/users/meriouma/following{/other_user}","gists_url":"https://api.github.com/users/meriouma/gists{/gist_id}","starred_url":"https://api.github.com/users/meriouma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meriouma/subscriptions","organizations_url":"https://api.github.com/users/meriouma/orgs","repos_url":"https://api.github.com/users/meriouma/repos","events_url":"https://api.github.com/users/meriouma/events{/privacy}","received_events_url":"https://api.github.com/users/meriouma/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-01-09T16:55:05Z","updated_at":"2015-01-09T17:31:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e2361533a4f892b907eb2969857d2a90b7fcece1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/pulls/1/commits","review_comments_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/pulls/1/comments","review_comment_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/pulls/comments/{number}","comments_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/issues/1/comments","statuses_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/statuses/6d2a0d7a8781d0af2aaaa55c9ff85414ede7ab0b","head":{"label":"ArcBees:create_plugin","ref":"create_plugin","sha":"6d2a0d7a8781d0af2aaaa55c9ff85414ede7ab0b","user":{"login":"ArcBees","id":853947,"avatar_url":"https://avatars.githubusercontent.com/u/853947?v=3","gravatar_id":"","url":"https://api.github.com/users/ArcBees","html_url":"https://github.com/ArcBees","followers_url":"https://api.github.com/users/ArcBees/followers","following_url":"https://api.github.com/users/ArcBees/following{/other_user}","gists_url":"https://api.github.com/users/ArcBees/gists{/gist_id}","starred_url":"https://api.github.com/users/ArcBees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ArcBees/subscriptions","organizations_url":"https://api.github.com/users/ArcBees/orgs","repos_url":"https://api.github.com/users/ArcBees/repos","events_url":"https://api.github.com/users/ArcBees/events{/privacy}","received_events_url":"https://api.github.com/users/ArcBees/received_events","type":"Organization","site_admin":false},"repo":{"id":29025399,"name":"gwtquery-appear-plugin","full_name":"ArcBees/gwtquery-appear-plugin","owner":{"login":"ArcBees","id":853947,"avatar_url":"https://avatars.githubusercontent.com/u/853947?v=3","gravatar_id":"","url":"https://api.github.com/users/ArcBees","html_url":"https://github.com/ArcBees","followers_url":"https://api.github.com/users/ArcBees/followers","following_url":"https://api.github.com/users/ArcBees/following{/other_user}","gists_url":"https://api.github.com/users/ArcBees/gists{/gist_id}","starred_url":"https://api.github.com/users/ArcBees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ArcBees/subscriptions","organizations_url":"https://api.github.com/users/ArcBees/orgs","repos_url":"https://api.github.com/users/ArcBees/repos","events_url":"https://api.github.com/users/ArcBees/events{/privacy}","received_events_url":"https://api.github.com/users/ArcBees/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ArcBees/gwtquery-appear-plugin","description":"ArcBees GQuery Appear Plugins","fork":false,"url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin","forks_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/forks","keys_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/teams","hooks_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/hooks","issue_events_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/events","assignees_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/tags","blobs_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/languages","stargazers_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/stargazers","contributors_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/contributors","subscribers_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/subscribers","subscription_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/subscription","commits_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/issues/comments/{number}","contents_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/merges","archive_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/downloads","issues_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/labels{/name}","releases_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/releases{/id}","created_at":"2015-01-09T16:45:38Z","updated_at":"2015-01-09T16:45:38Z","pushed_at":"2015-01-09T17:24:34Z","git_url":"git://github.com/ArcBees/gwtquery-appear-plugin.git","ssh_url":"git@github.com:ArcBees/gwtquery-appear-plugin.git","clone_url":"https://github.com/ArcBees/gwtquery-appear-plugin.git","svn_url":"https://github.com/ArcBees/gwtquery-appear-plugin","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"ArcBees:master","ref":"master","sha":"23bb61cbdd4bd11ee87e09209a1172568fc773e1","user":{"login":"ArcBees","id":853947,"avatar_url":"https://avatars.githubusercontent.com/u/853947?v=3","gravatar_id":"","url":"https://api.github.com/users/ArcBees","html_url":"https://github.com/ArcBees","followers_url":"https://api.github.com/users/ArcBees/followers","following_url":"https://api.github.com/users/ArcBees/following{/other_user}","gists_url":"https://api.github.com/users/ArcBees/gists{/gist_id}","starred_url":"https://api.github.com/users/ArcBees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ArcBees/subscriptions","organizations_url":"https://api.github.com/users/ArcBees/orgs","repos_url":"https://api.github.com/users/ArcBees/repos","events_url":"https://api.github.com/users/ArcBees/events{/privacy}","received_events_url":"https://api.github.com/users/ArcBees/received_events","type":"Organization","site_admin":false},"repo":{"id":29025399,"name":"gwtquery-appear-plugin","full_name":"ArcBees/gwtquery-appear-plugin","owner":{"login":"ArcBees","id":853947,"avatar_url":"https://avatars.githubusercontent.com/u/853947?v=3","gravatar_id":"","url":"https://api.github.com/users/ArcBees","html_url":"https://github.com/ArcBees","followers_url":"https://api.github.com/users/ArcBees/followers","following_url":"https://api.github.com/users/ArcBees/following{/other_user}","gists_url":"https://api.github.com/users/ArcBees/gists{/gist_id}","starred_url":"https://api.github.com/users/ArcBees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ArcBees/subscriptions","organizations_url":"https://api.github.com/users/ArcBees/orgs","repos_url":"https://api.github.com/users/ArcBees/repos","events_url":"https://api.github.com/users/ArcBees/events{/privacy}","received_events_url":"https://api.github.com/users/ArcBees/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ArcBees/gwtquery-appear-plugin","description":"ArcBees GQuery Appear Plugins","fork":false,"url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin","forks_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/forks","keys_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/teams","hooks_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/hooks","issue_events_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/events","assignees_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/tags","blobs_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/languages","stargazers_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/stargazers","contributors_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/contributors","subscribers_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/subscribers","subscription_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/subscription","commits_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/issues/comments/{number}","contents_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/merges","archive_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/downloads","issues_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/labels{/name}","releases_url":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/releases{/id}","created_at":"2015-01-09T16:45:38Z","updated_at":"2015-01-09T16:45:38Z","pushed_at":"2015-01-09T17:24:34Z","git_url":"git://github.com/ArcBees/gwtquery-appear-plugin.git","ssh_url":"git@github.com:ArcBees/gwtquery-appear-plugin.git","clone_url":"https://github.com/ArcBees/gwtquery-appear-plugin.git","svn_url":"https://github.com/ArcBees/gwtquery-appear-plugin","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/pulls/1"},"html":{"href":"https://github.com/ArcBees/gwtquery-appear-plugin/pull/1"},"issue":{"href":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/issues/1"},"comments":{"href":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/ArcBees/gwtquery-appear-plugin/statuses/6d2a0d7a8781d0af2aaaa55c9ff85414ede7ab0b"}}}}