You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2013/07/22 01:49:33 UTC

[4/6] git commit: Remove some triggerReflow() logic Add ability to execute a block with trigger reflows disabled

Remove some triggerReflow() logic
Add ability to execute a block with trigger reflows disabled


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/430b1a7a
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/430b1a7a
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/430b1a7a

Branch: refs/heads/master
Commit: 430b1a7a34a9f2d00e82c5c41c6ac7dbcfdbf3b2
Parents: fdda179
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Sun Jul 21 16:41:44 2013 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Sun Jul 21 16:41:44 2013 -0700

----------------------------------------------------------------------
 .../org/apache/tapestry5/t5-core-dom.coffee     | 22 ++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/430b1a7a/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee b/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
index f141f3d..186ec90 100644
--- a/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
+++ b/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
@@ -42,6 +42,8 @@ define ["underscore", "./utils", "./events", "jquery"],
   # and RequireJS together, here: https://github.com/jrburke/requirejs/issues/534
   $ = window.$
 
+  reflowEventsEnabled = true
+
   # Fires a native event; something that Prototype does not normally do.
   # Returns true if the event completed normally, false if it was canceled.
   fireNativeEvent = (element, eventName) ->
@@ -68,7 +70,6 @@ define ["underscore", "./utils", "./events", "jquery"],
         styles[styleName] = finalValue
         element.setStyle styles
         window.clearInterval timeoutID
-        triggerReflow()
         callbacks.oncomplete and callbacks.oncomplete()
 
       # TODO: Add an easein/easeout function
@@ -453,7 +454,6 @@ define ["underscore", "./utils", "./events", "jquery"],
     fadeIn: (duration, callback) ->
 #if jquery
       @$.fadeIn duration * 1000, ->
-        triggerReflow()
         callback and callback()
 #elseif prototype
       animate @element, "opacity", 0, 1, duration * 1000,
@@ -471,7 +471,6 @@ define ["underscore", "./utils", "./events", "jquery"],
     fadeOut: (duration, callback) ->
 #if jquery
       @$.fadeOut duration * 1000, ->
-        triggerReflow()
         callback and callback()
 #elseif prototype
       animate @element, "opacity", 1, 0, duration * 1000,
@@ -806,7 +805,8 @@ define ["underscore", "./utils", "./events", "jquery"],
 
     return exports
 
-  triggerReflow =
+  triggerReflow = ->
+    return unless reflowEventsEnabled
 #if jquery
     _.debounce (-> $(document).trigger events.document.reflow), 250
 #elseif prototype
@@ -875,6 +875,20 @@ define ["underscore", "./utils", "./events", "jquery"],
 
     ajaxRequest: ajaxRequest
 
+    # Executes a block (provided as a function of no parameters) with automatic reflow events
+    # disabled. This is useful when the executed code will not affect the layout of the page in a way
+    # that can affect absolutely positioned elements.
+    withReflowEventsDisabled: (fn) ->
+
+      try
+        stored = reflowEventsEnabled
+
+        reflowEventsEnabled = false
+
+        fn()
+      finally
+        reflowEventsEnabled = stored
+
     # Used to add an event handler to an element (possibly from elements below it in the hierarch).
     #
     # * selector - CSS selector used to select elements to attach handler to; alternately,