From 4aa45834f57cd0e1eacd3f56dc466354e1bba43d Mon Sep 17 00:00:00 2001 From: Jack Lukic Date: Wed, 29 May 2013 11:00:51 -0400 Subject: [PATCH] performance improvements to dropdown Former-commit-id: 44b1ecdc44fb0652e1d2fca49a8a1f3996bdd24c Former-commit-id: 675919b75ada24e107422c9a59702e18f98c1779 --- build/minified/modules/dropdown.js | 3 ++- build/minified/modules/dropdown.min.js | 2 +- build/packaged/modules/dropdown.js | 3 ++- build/packaged/semantic.min.js.REMOVED.git-id | 2 +- build/uncompressed/modules/dropdown.js | 3 ++- node/src/files/components/semantic/modules/dropdown.js | 3 ++- src/modules/dropdown.js | 3 ++- 7 files changed, 12 insertions(+), 7 deletions(-) diff --git a/build/minified/modules/dropdown.js b/build/minified/modules/dropdown.js index c5405037d..36b67483e 100644 --- a/build/minified/modules/dropdown.js +++ b/build/minified/modules/dropdown.js @@ -115,7 +115,7 @@ $.fn.dropdown = function(parameters) { item: { - click: function () { + click: function (event) { var $choice = $(this), text = $choice.data(metadata.text) || $choice.text(), @@ -130,6 +130,7 @@ $.fn.dropdown = function(parameters) { ; module.action.determine(text, value); $.proxy(settings.onChange, $menu.get())(text, value); + event.stopPropagation(); } } diff --git a/build/minified/modules/dropdown.min.js b/build/minified/modules/dropdown.min.js index 898310a5a..da7eefb5f 100644 --- a/build/minified/modules/dropdown.min.js +++ b/build/minified/modules/dropdown.min.js @@ -1 +1 @@ -(function(e,t,n,o){e.fn.dropdown=function(t){var i,a=e(this),s=e(n),r=e.extend(!0,{},e.fn.dropdown.settings,t),c="."+r.namespace,l="module-"+r.namespace,u=(a.selector||"",(new Date).getTime()),d=[],m=arguments[0],f="string"==typeof m,g=[].slice.call(arguments,1);return a.each(function(){var t,p=e(this),h=e(this).find(r.selector.menu),v=e(this).find(r.selector.item),b=e(this).find(r.selector.text),y=e(this).find(r.selector.input),x="ontouchstart"in n.documentElement,C=p.selector||"",w=this,T=p.data("module-"+r.namespace),k=r.className,N=r.metadata,z=r.namespace,P=r.animation,E=r.errors;t={initialize:function(){t.verbose("Initializing dropdown with bound events",p),x?p.on("touchstart"+c,t.event.test.toggle):"click"==r.on?p.on("click"+c,t.event.test.toggle):"hover"==r.on?p.on("mouseenter"+c,t.show).on("mouseleave"+c,t.delayedHide):p.on(r.on+c,t.toggle),"form"==r.action&&t.set.selected(),v.on(t.get.selectEvent()+c,t.event.item.click),p.data(l,t)},destroy:function(){t.verbose("Destroying previous module for",p),p.off(z)},event:{stopPropagation:function(e){e.stopPropagation()},test:{toggle:function(e){t.intent.test(e,t.toggle),e.stopPropagation()},hide:function(e){t.intent.test(e,t.hide),e.stopPropagation()}},item:{click:function(){var n=e(this),o=n.data(N.text)||n.text(),i=n.data(N.value)||o;t.verbose("Adding active state to selected item"),v.removeClass(k.active),n.addClass(k.active),t.action.determine(o,i),e.proxy(r.onChange,h.get())(o,i)}}},intent:{test:function(n,o){t.debug("Determining whether event occurred in dropdown",n.target),o=o||function(){},0===e(n.target).closest(h).size()?(t.verbose("Triggering event",o),o()):t.verbose("Event occurred in dropdown, canceling callback")},bind:function(){t.verbose("Binding hide intent event to document"),s.on(t.get.selectEvent(),t.event.test.hide)},unbind:function(){t.verbose("Removing hide intent event from document"),s.off(t.get.selectEvent())}},action:{determine:function(n,o){e.isFunction(t.action[r.action])?(t.verbose("Triggering preset action",r.action),t.action[r.action](n,o)):e.isFunction(r.action)?(t.verbose("Triggering user action",r.action),r.action(n,o)):t.error(E.action)},nothing:function(){},hide:function(){t.hide()},changeText:function(e){t.set.text(e),t.hide()},form:function(e,n){t.set.text(e),t.set.value(n),t.hide()}},get:{selectEvent:function(){return x?"touchstart":"click"},text:function(){return b.text()},value:function(){return y.val()},item:function(t){var n;return t=t||y.val(),v.each(function(){e(this).data(N.value)==t&&(n=e(this))}),n||!1}},set:{text:function(e){t.debug("Changing text",e),b.text(e)},value:function(e){t.debug("Adding selected value to hidden input",e),y.val(e)},selected:function(e){var n,o=(e||y.val(),t.get.item(e));o&&(t.debug("Setting selected menu item to",o),n=o.data(N.text)||o.text(),v.removeClass(k.active),o.addClass(k.active),t.set.text(n))}},is:{visible:function(){return h.is(":visible")},hidden:function(){return h.is(":not(:visible)")}},can:{click:function(){return x||"click"==r.on},show:function(){return!p.hasClass(k.disabled)}},animate:{show:function(){t.verbose("Doing menu showing animation"),"show"==P.show?h.show():"slide"==P.show&&h.clearQueue().children().clearQueue().css("opacity",0).delay(100).animate({opacity:1},300,"easeOutQuad").end().slideDown(200,"easeOutQuad")},hide:function(){t.verbose("Doing menu hiding animation"),"hide"==P.hide?h.hide():"slide"==P.hide&&h.clearQueue().children().clearQueue().css("opacity",1).animate({opacity:0},300,"easeOutQuad").end().delay(100).slideUp(200,"easeOutQuad")}},show:function(){clearTimeout(t.graceTimer),t.is.visible()||(t.debug("Showing dropdown"),p.addClass(k.visible),t.animate.show(),t.can.click()&&t.intent.bind(),e.proxy(r.onShow,h.get())())},delayedHide:function(){t.verbose("User moused away setting timer to hide dropdown"),t.graceTimer=setTimeout(t.hide,r.gracePeriod)},hide:function(){t.is.hidden()||(t.debug("Hiding dropdown"),p.removeClass(k.visible),t.can.click()&&t.intent.unbind(),t.animate.hide(),e.proxy(r.onHide,h.get())())},toggle:function(){t.verbose("Toggling menu visibility"),t.can.show()?t.show():t.hide()},setting:function(t,n){return n===o?r[t]:(e.isPlainObject(t)?e.extend(!0,r,t):r[t]=n,o)},internal:function(n,i){return i===o?t[n]:(e.isPlainObject(n)?e.extend(!0,t,n):t[n]=i,o)},debug:function(){r.debug&&(r.performance?t.performance.log(arguments):t.debug=Function.prototype.bind.call(console.info,console,r.moduleName+":"))},verbose:function(){r.verbose&&r.debug&&(r.performance?t.performance.log(arguments):t.verbose=Function.prototype.bind.call(console.info,console,r.moduleName+":"))},error:function(){t.error=Function.prototype.bind.call(console.log,console,r.moduleName+":")},performance:{log:function(e){var n,o,i;r.performance&&(n=(new Date).getTime(),i=u||n,o=n-i,u=n,d.push({Element:w,Name:e[0],Arguments:e[1]||"None","Execution Time":o}),clearTimeout(t.performance.timer),t.performance.timer=setTimeout(t.performance.display,100))},display:function(){var t=r.moduleName,n=(r.moduleName+": "+C+"("+a.size()+" elements)",0);C&&(t+=" Performance ("+C+")"),(console.group!==o||console.table!==o)&&d.length>0&&(console.groupCollapsed(t),console.table?(e.each(d,function(e,t){n+=t["Execution Time"]}),console.table(d)):e.each(d,function(e,t){n+=t["Execution Time"],console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.log("Total Execution Time:",n+"ms"),console.groupEnd(),d=[],u=!1)}},invoke:function(n,i,a){var s,r;return i=i||g,a=w||a,"string"==typeof n&&T!==o&&(n=n.split("."),s=n.length-1,e.each(n,function(n,i){return e.isPlainObject(T[i])&&n!=s?(T=T[i],!0):T[i]!==o?(r=T[i],!0):(t.error(E.method),!1)})),e.isFunction(r)?(t.verbose("Executing invoked function",r),r.apply(a,i)):r||!1}},f?(T===o&&t.initialize(),i=t.invoke(m)):(T!==o&&t.destroy(),t.initialize())}),i?i:this},e.fn.dropdown.settings={moduleName:"Dropdown Module",namespace:"dropdown",verbose:!0,debug:!0,performance:!0,on:"click",gracePeriod:300,action:"hide",animation:{show:"slide",hide:"slide"},onChange:function(){},onShow:function(){},onHide:function(){},errors:{action:"You called a dropdown action that was not defined",method:"The method you called is not defined."},metadata:{text:"text",value:"value"},selector:{menu:".menu",item:".menu > .item",text:"> .text",input:'> input[type="hidden"]'},className:{active:"active",disabled:"disabled",visible:"visible"}}})(jQuery,window,document); \ No newline at end of file +(function(e,t,n,o){e.fn.dropdown=function(t){var i,a=e(this),s=e(n),r=e.extend(!0,{},e.fn.dropdown.settings,t),c="."+r.namespace,l="module-"+r.namespace,u=(a.selector||"",(new Date).getTime()),d=[],m=arguments[0],f="string"==typeof m,g=[].slice.call(arguments,1);return a.each(function(){var t,p=e(this),h=e(this).find(r.selector.menu),v=e(this).find(r.selector.item),b=e(this).find(r.selector.text),y=e(this).find(r.selector.input),x="ontouchstart"in n.documentElement,C=p.selector||"",w=this,T=p.data("module-"+r.namespace),k=r.className,N=r.metadata,z=r.namespace,P=r.animation,E=r.errors;t={initialize:function(){t.verbose("Initializing dropdown with bound events",p),x?p.on("touchstart"+c,t.event.test.toggle):"click"==r.on?p.on("click"+c,t.event.test.toggle):"hover"==r.on?p.on("mouseenter"+c,t.show).on("mouseleave"+c,t.delayedHide):p.on(r.on+c,t.toggle),"form"==r.action&&t.set.selected(),v.on(t.get.selectEvent()+c,t.event.item.click),p.data(l,t)},destroy:function(){t.verbose("Destroying previous module for",p),p.off(z)},event:{stopPropagation:function(e){e.stopPropagation()},test:{toggle:function(e){t.intent.test(e,t.toggle),e.stopPropagation()},hide:function(e){t.intent.test(e,t.hide),e.stopPropagation()}},item:{click:function(n){var o=e(this),i=o.data(N.text)||o.text(),a=o.data(N.value)||i;t.verbose("Adding active state to selected item"),v.removeClass(k.active),o.addClass(k.active),t.action.determine(i,a),e.proxy(r.onChange,h.get())(i,a),n.stopPropagation()}}},intent:{test:function(n,o){t.debug("Determining whether event occurred in dropdown",n.target),o=o||function(){},0===e(n.target).closest(h).size()?(t.verbose("Triggering event",o),o()):t.verbose("Event occurred in dropdown, canceling callback")},bind:function(){t.verbose("Binding hide intent event to document"),s.on(t.get.selectEvent(),t.event.test.hide)},unbind:function(){t.verbose("Removing hide intent event from document"),s.off(t.get.selectEvent())}},action:{determine:function(n,o){e.isFunction(t.action[r.action])?(t.verbose("Triggering preset action",r.action),t.action[r.action](n,o)):e.isFunction(r.action)?(t.verbose("Triggering user action",r.action),r.action(n,o)):t.error(E.action)},nothing:function(){},hide:function(){t.hide()},changeText:function(e){t.set.text(e),t.hide()},form:function(e,n){t.set.text(e),t.set.value(n),t.hide()}},get:{selectEvent:function(){return x?"touchstart":"click"},text:function(){return b.text()},value:function(){return y.val()},item:function(t){var n;return t=t||y.val(),v.each(function(){e(this).data(N.value)==t&&(n=e(this))}),n||!1}},set:{text:function(e){t.debug("Changing text",e),b.text(e)},value:function(e){t.debug("Adding selected value to hidden input",e),y.val(e)},selected:function(e){var n,o=(e||y.val(),t.get.item(e));o&&(t.debug("Setting selected menu item to",o),n=o.data(N.text)||o.text(),v.removeClass(k.active),o.addClass(k.active),t.set.text(n))}},is:{visible:function(){return h.is(":visible")},hidden:function(){return h.is(":not(:visible)")}},can:{click:function(){return x||"click"==r.on},show:function(){return!p.hasClass(k.disabled)}},animate:{show:function(){t.verbose("Doing menu showing animation"),"show"==P.show?h.show():"slide"==P.show&&h.clearQueue().children().clearQueue().css("opacity",0).delay(100).animate({opacity:1},300,"easeOutQuad").end().slideDown(200,"easeOutQuad")},hide:function(){t.verbose("Doing menu hiding animation"),"hide"==P.hide?h.hide():"slide"==P.hide&&h.clearQueue().children().clearQueue().css("opacity",1).animate({opacity:0},300,"easeOutQuad").end().delay(100).slideUp(200,"easeOutQuad")}},show:function(){clearTimeout(t.graceTimer),t.is.visible()||(t.debug("Showing dropdown"),p.addClass(k.visible),t.animate.show(),t.can.click()&&t.intent.bind(),e.proxy(r.onShow,h.get())())},delayedHide:function(){t.verbose("User moused away setting timer to hide dropdown"),t.graceTimer=setTimeout(t.hide,r.gracePeriod)},hide:function(){t.is.hidden()||(t.debug("Hiding dropdown"),p.removeClass(k.visible),t.can.click()&&t.intent.unbind(),t.animate.hide(),e.proxy(r.onHide,h.get())())},toggle:function(){t.verbose("Toggling menu visibility"),t.can.show()?t.show():t.hide()},setting:function(t,n){return n===o?r[t]:(e.isPlainObject(t)?e.extend(!0,r,t):r[t]=n,o)},internal:function(n,i){return i===o?t[n]:(e.isPlainObject(n)?e.extend(!0,t,n):t[n]=i,o)},debug:function(){r.debug&&(r.performance?t.performance.log(arguments):t.debug=Function.prototype.bind.call(console.info,console,r.moduleName+":"))},verbose:function(){r.verbose&&r.debug&&(r.performance?t.performance.log(arguments):t.verbose=Function.prototype.bind.call(console.info,console,r.moduleName+":"))},error:function(){t.error=Function.prototype.bind.call(console.log,console,r.moduleName+":")},performance:{log:function(e){var n,o,i;r.performance&&(n=(new Date).getTime(),i=u||n,o=n-i,u=n,d.push({Element:w,Name:e[0],Arguments:e[1]||"None","Execution Time":o}),clearTimeout(t.performance.timer),t.performance.timer=setTimeout(t.performance.display,100))},display:function(){var t=r.moduleName,n=(r.moduleName+": "+C+"("+a.size()+" elements)",0);C&&(t+=" Performance ("+C+")"),(console.group!==o||console.table!==o)&&d.length>0&&(console.groupCollapsed(t),console.table?(e.each(d,function(e,t){n+=t["Execution Time"]}),console.table(d)):e.each(d,function(e,t){n+=t["Execution Time"],console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.log("Total Execution Time:",n+"ms"),console.groupEnd(),d=[],u=!1)}},invoke:function(n,i,a){var s,r;return i=i||g,a=w||a,"string"==typeof n&&T!==o&&(n=n.split("."),s=n.length-1,e.each(n,function(n,i){return e.isPlainObject(T[i])&&n!=s?(T=T[i],!0):T[i]!==o?(r=T[i],!0):(t.error(E.method),!1)})),e.isFunction(r)?(t.verbose("Executing invoked function",r),r.apply(a,i)):r||!1}},f?(T===o&&t.initialize(),i=t.invoke(m)):(T!==o&&t.destroy(),t.initialize())}),i?i:this},e.fn.dropdown.settings={moduleName:"Dropdown Module",namespace:"dropdown",verbose:!0,debug:!0,performance:!0,on:"click",gracePeriod:300,action:"hide",animation:{show:"slide",hide:"slide"},onChange:function(){},onShow:function(){},onHide:function(){},errors:{action:"You called a dropdown action that was not defined",method:"The method you called is not defined."},metadata:{text:"text",value:"value"},selector:{menu:".menu",item:".menu > .item",text:"> .text",input:'> input[type="hidden"]'},className:{active:"active",disabled:"disabled",visible:"visible"}}})(jQuery,window,document); \ No newline at end of file diff --git a/build/packaged/modules/dropdown.js b/build/packaged/modules/dropdown.js index c5405037d..36b67483e 100644 --- a/build/packaged/modules/dropdown.js +++ b/build/packaged/modules/dropdown.js @@ -115,7 +115,7 @@ $.fn.dropdown = function(parameters) { item: { - click: function () { + click: function (event) { var $choice = $(this), text = $choice.data(metadata.text) || $choice.text(), @@ -130,6 +130,7 @@ $.fn.dropdown = function(parameters) { ; module.action.determine(text, value); $.proxy(settings.onChange, $menu.get())(text, value); + event.stopPropagation(); } } diff --git a/build/packaged/semantic.min.js.REMOVED.git-id b/build/packaged/semantic.min.js.REMOVED.git-id index f9b09ebc5..00cd3122f 100644 --- a/build/packaged/semantic.min.js.REMOVED.git-id +++ b/build/packaged/semantic.min.js.REMOVED.git-id @@ -1 +1 @@ -7d3c8b4fe3fb583f87cf300a7c5210b2e18ea1c2 \ No newline at end of file +d876032258d1a67275200e157a4230e6f2d8260e \ No newline at end of file diff --git a/build/uncompressed/modules/dropdown.js b/build/uncompressed/modules/dropdown.js index c5405037d..36b67483e 100644 --- a/build/uncompressed/modules/dropdown.js +++ b/build/uncompressed/modules/dropdown.js @@ -115,7 +115,7 @@ $.fn.dropdown = function(parameters) { item: { - click: function () { + click: function (event) { var $choice = $(this), text = $choice.data(metadata.text) || $choice.text(), @@ -130,6 +130,7 @@ $.fn.dropdown = function(parameters) { ; module.action.determine(text, value); $.proxy(settings.onChange, $menu.get())(text, value); + event.stopPropagation(); } } diff --git a/node/src/files/components/semantic/modules/dropdown.js b/node/src/files/components/semantic/modules/dropdown.js index c5405037d..36b67483e 100644 --- a/node/src/files/components/semantic/modules/dropdown.js +++ b/node/src/files/components/semantic/modules/dropdown.js @@ -115,7 +115,7 @@ $.fn.dropdown = function(parameters) { item: { - click: function () { + click: function (event) { var $choice = $(this), text = $choice.data(metadata.text) || $choice.text(), @@ -130,6 +130,7 @@ $.fn.dropdown = function(parameters) { ; module.action.determine(text, value); $.proxy(settings.onChange, $menu.get())(text, value); + event.stopPropagation(); } } diff --git a/src/modules/dropdown.js b/src/modules/dropdown.js index c5405037d..36b67483e 100755 --- a/src/modules/dropdown.js +++ b/src/modules/dropdown.js @@ -115,7 +115,7 @@ $.fn.dropdown = function(parameters) { item: { - click: function () { + click: function (event) { var $choice = $(this), text = $choice.data(metadata.text) || $choice.text(), @@ -130,6 +130,7 @@ $.fn.dropdown = function(parameters) { ; module.action.determine(text, value); $.proxy(settings.onChange, $menu.get())(text, value); + event.stopPropagation(); } }