From dd8e5583d7da4d30f90110600acbf4d73febcf8c Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 12 Aug 2014 16:33:53 -0400 Subject: [PATCH] ES6: Transition helper --- .../discourse/lib/after-transition.js.es6 | 29 +++++++++++++ .../discourse/lib/transition_helper.js | 43 ------------------- .../discourse/views/composer.js.es6 | 3 +- 3 files changed, 31 insertions(+), 44 deletions(-) create mode 100644 app/assets/javascripts/discourse/lib/after-transition.js.es6 delete mode 100644 app/assets/javascripts/discourse/lib/transition_helper.js diff --git a/app/assets/javascripts/discourse/lib/after-transition.js.es6 b/app/assets/javascripts/discourse/lib/after-transition.js.es6 new file mode 100644 index 00000000000..30cc3054f0e --- /dev/null +++ b/app/assets/javascripts/discourse/lib/after-transition.js.es6 @@ -0,0 +1,29 @@ +/** + CSS transitions are a PITA, often we need to queue some js after a transition, this helper ensures + it happens after the transition. + + SO: http://stackoverflow.com/questions/9943435/css3-animation-end-techniques +**/ +var dummy = document.createElement("div"), + eventNameHash = { + webkit: "webkitTransitionEnd", + Moz: "transitionend", + O: "oTransitionEnd", + ms: "MSTransitionEnd" + }; + +var transitionEnd = function() { + var retValue; + retValue = "transitionend"; + Object.keys(eventNameHash).some(function(vendor) { + if (vendor + "TransitionProperty" in dummy.style) { + retValue = eventNameHash[vendor]; + return true; + } + }); + return retValue; +}(); + +export default function (element, callback) { + return $(element).on(transitionEnd, callback); +} diff --git a/app/assets/javascripts/discourse/lib/transition_helper.js b/app/assets/javascripts/discourse/lib/transition_helper.js deleted file mode 100644 index 262bc887ea9..00000000000 --- a/app/assets/javascripts/discourse/lib/transition_helper.js +++ /dev/null @@ -1,43 +0,0 @@ -/** - CSS transitions are a PITA, often we need to queue some js after a transition, this helper ensures - it happens after the transition. - - SO: http://stackoverflow.com/questions/9943435/css3-animation-end-techniques - - - @class TransitionHelper - @namespace Discourse - @module Discourse -**/ - -var dummy, eventNameHash, transitionEnd, _getTransitionEndEventName; - -dummy = document.createElement("div"); - -eventNameHash = { - webkit: "webkitTransitionEnd", - Moz: "transitionend", - O: "oTransitionEnd", - ms: "MSTransitionEnd" -}; - -_getTransitionEndEventName = function() { - var retValue; - retValue = "transitionend"; - Object.keys(eventNameHash).some(function(vendor) { - if (vendor + "TransitionProperty" in dummy.style) { - retValue = eventNameHash[vendor]; - return true; - } - }); - return retValue; -}; -transitionEnd = _getTransitionEndEventName(); - -Discourse.TransitionHelper = { - after: function(element, callback) { - return $(element).on(transitionEnd, callback); - } -}; - - diff --git a/app/assets/javascripts/discourse/views/composer.js.es6 b/app/assets/javascripts/discourse/views/composer.js.es6 index 64b568fecd3..a1e3cffd867 100644 --- a/app/assets/javascripts/discourse/views/composer.js.es6 +++ b/app/assets/javascripts/discourse/views/composer.js.es6 @@ -1,6 +1,7 @@ /*global assetPath:true */ import userSearch from 'discourse/lib/user-search'; +import afterTransition from 'discourse/lib/after-transition'; var ComposerView = Discourse.View.extend(Ember.Evented, { templateName: 'composer', @@ -106,7 +107,7 @@ var ComposerView = Discourse.View.extend(Ember.Evented, { resize: this.resize, onDrag: function (sizePx) { self.movePanels.apply(self, [sizePx]); } }); - Discourse.TransitionHelper.after($replyControl, this.resize); + afterTransition($replyControl, this.resize); this.ensureMaximumDimensionForImagesInPreview(); this.set('controller.view', this); }.on('didInsertElement'),