From db1511a11d7fe89dbb8cdbff1fd6c08c894c2f9d Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Fri, 23 May 2014 18:49:16 +0200 Subject: [PATCH 1/8] add a slideup mechanism --- core/js/app.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/base.php | 1 + 2 files changed, 66 insertions(+) create mode 100644 core/js/app.js diff --git a/core/js/app.js b/core/js/app.js new file mode 100644 index 0000000000..8f3f04187b --- /dev/null +++ b/core/js/app.js @@ -0,0 +1,65 @@ +/** + * ownCloud - core + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt + * @copyright Bernhard Posselt 2014 + */ + +(function (document, $) { + + 'use strict'; + + /** + * Provides a way to slide down a target area through a button and slide it + * up if the user clicks somewhere else. Used for the news app settings and + * add new field. + * + * Usage: + * + *
I'm sliding up
+ */ + var registerAppsSlideToggle = function () { + // use only buttons that are already in the dom + var buttons = $('[data-apps-slide-toggle]'); + + $(document).click(function (event) { + + buttons.each(function (index, button) { + + var areaSelector = $(button).data('apps-slide-toggle'); + var area = $(areaSelector); + + // do nothing if the area is animated + if (!area.is(':animated')) { + + // button slides up the area + if (button === event.target) { + if (area.is(':visible')) { + area.slideUp(); + } else { + area.slideDown(); + } + + // all other areas that have not been clicked but are open + // should be slid up + } else { + var closest = ($(event.target).closest(areaSelector)); + if (area.is(':visible') && closest[0] !== area[0]) { + area.slideUp(); + } + } + } + }); + + }); + } + + + $(document).ready(function () { + registerAppsSlideToggle(); + }); + +}(document, jQuery)); \ No newline at end of file diff --git a/lib/base.php b/lib/base.php index a022b9d005..8c75d0b5c1 100644 --- a/lib/base.php +++ b/lib/base.php @@ -319,6 +319,7 @@ class OC { //OC_Util::addScript( "multiselect" ); OC_Util::addScript('search', 'result'); OC_Util::addScript("oc-requesttoken"); + OC_Util::addScript("app"); // avatars if (\OC_Config::getValue('enable_avatars', true) === true) { From 044ba9726327669d7c03992b078b129d0510119d Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Fri, 23 May 2014 19:14:28 +0200 Subject: [PATCH 2/8] remove unecessary parenths --- core/js/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/js/app.js b/core/js/app.js index 8f3f04187b..d6a3f9e2fb 100644 --- a/core/js/app.js +++ b/core/js/app.js @@ -35,7 +35,7 @@ // do nothing if the area is animated if (!area.is(':animated')) { - // button slides up the area + // button toggles the area if (button === event.target) { if (area.is(':visible')) { area.slideUp(); @@ -46,7 +46,7 @@ // all other areas that have not been clicked but are open // should be slid up } else { - var closest = ($(event.target).closest(areaSelector)); + var closest = $(event.target).closest(areaSelector); if (area.is(':visible') && closest[0] !== area[0]) { area.slideUp(); } From 41b7e4b8b86efa0692291a2b98f82979774a6773 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Fri, 23 May 2014 21:28:34 +0200 Subject: [PATCH 3/8] add ; to make jshint happy --- core/js/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/js/app.js b/core/js/app.js index d6a3f9e2fb..59b5d14419 100644 --- a/core/js/app.js +++ b/core/js/app.js @@ -55,7 +55,7 @@ }); }); - } + }; $(document).ready(function () { From 11c5ded96c52ec909f7324df46f29f25b5bea9ad Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 24 May 2014 14:23:44 +0200 Subject: [PATCH 4/8] allow apps to add buttons on runtime without negatively impacting performance --- core/js/app.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/core/js/app.js b/core/js/app.js index 59b5d14419..6592ea93b2 100644 --- a/core/js/app.js +++ b/core/js/app.js @@ -7,11 +7,24 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ - -(function (document, $) { +(function (document, $, exports) { 'use strict'; + var buttons = $(); + + /** + * Allow apps to register buttons at runtime to not impact performance + * negatively on document click + * @param $ button wrapped in jquery result + */ + exports.Apps = { + registerSlideToggleButton: function (button) { + buttons = buttons.add(button); + } + }; + + /** * Provides a way to slide down a target area through a button and slide it * up if the user clicks somewhere else. Used for the news app settings and @@ -23,7 +36,7 @@ */ var registerAppsSlideToggle = function () { // use only buttons that are already in the dom - var buttons = $('[data-apps-slide-toggle]'); + buttons = buttons.add($('[data-apps-slide-toggle]')); $(document).click(function (event) { @@ -62,4 +75,4 @@ registerAppsSlideToggle(); }); -}(document, jQuery)); \ No newline at end of file +}(document, jQuery, OC)); \ No newline at end of file From 8a30fe8ce3b803faaa5b9893b3b060b2027e0fc6 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 24 May 2014 14:24:46 +0200 Subject: [PATCH 5/8] use different ns --- core/js/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/js/app.js b/core/js/app.js index 6592ea93b2..17fc225089 100644 --- a/core/js/app.js +++ b/core/js/app.js @@ -18,7 +18,7 @@ * negatively on document click * @param $ button wrapped in jquery result */ - exports.Apps = { + exports.App = { registerSlideToggleButton: function (button) { buttons = buttons.add(button); } From 9112386cbf0eb1baf28aedd6fce07cef75fa1d68 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 24 May 2014 14:28:24 +0200 Subject: [PATCH 6/8] query buttons on every click to not worry about weird edge case scenarios --- core/js/app.js | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/core/js/app.js b/core/js/app.js index 17fc225089..0308d1fef0 100644 --- a/core/js/app.js +++ b/core/js/app.js @@ -7,24 +7,11 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -(function (document, $, exports) { + +(function (document, $) { 'use strict'; - var buttons = $(); - - /** - * Allow apps to register buttons at runtime to not impact performance - * negatively on document click - * @param $ button wrapped in jquery result - */ - exports.App = { - registerSlideToggleButton: function (button) { - buttons = buttons.add(button); - } - }; - - /** * Provides a way to slide down a target area through a button and slide it * up if the user clicks somewhere else. Used for the news app settings and @@ -35,11 +22,10 @@ *
I'm sliding up
*/ var registerAppsSlideToggle = function () { - // use only buttons that are already in the dom - buttons = buttons.add($('[data-apps-slide-toggle]')); - $(document).click(function (event) { + var buttons = $('[data-apps-slide-toggle]'); + buttons.each(function (index, button) { var areaSelector = $(button).data('apps-slide-toggle'); @@ -75,4 +61,4 @@ registerAppsSlideToggle(); }); -}(document, jQuery, OC)); \ No newline at end of file +}(document, jQuery)); \ No newline at end of file From c2330e558ebc8396f60be12db95a7ebb9f4e9385 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 26 May 2014 17:31:41 +0200 Subject: [PATCH 7/8] rename to apps.js --- core/js/{app.js => apps.js} | 0 lib/base.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename core/js/{app.js => apps.js} (100%) diff --git a/core/js/app.js b/core/js/apps.js similarity index 100% rename from core/js/app.js rename to core/js/apps.js diff --git a/lib/base.php b/lib/base.php index 8c75d0b5c1..fd0bbb074f 100644 --- a/lib/base.php +++ b/lib/base.php @@ -319,7 +319,7 @@ class OC { //OC_Util::addScript( "multiselect" ); OC_Util::addScript('search', 'result'); OC_Util::addScript("oc-requesttoken"); - OC_Util::addScript("app"); + OC_Util::addScript("apps"); // avatars if (\OC_Config::getValue('enable_avatars', true) === true) { From daecf4b2c14bccb27cc6c5462570c675aa558816 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 26 May 2014 18:06:47 +0200 Subject: [PATCH 8/8] disable dynamic slide toggle by default and offer a way to enable it --- core/js/apps.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/core/js/apps.js b/core/js/apps.js index 0308d1fef0..5f221bb982 100644 --- a/core/js/apps.js +++ b/core/js/apps.js @@ -8,10 +8,18 @@ * @copyright Bernhard Posselt 2014 */ -(function (document, $) { +(function (document, $, exports) { 'use strict'; + var dynamicSlideToggleEnabled = false; + + exports.Apps = { + enableDynamicSlideToggle: function () { + dynamicSlideToggleEnabled = true; + } + }; + /** * Provides a way to slide down a target area through a button and slide it * up if the user clicks somewhere else. Used for the news app settings and @@ -22,9 +30,13 @@ *
I'm sliding up
*/ var registerAppsSlideToggle = function () { + var buttons = $('[data-apps-slide-toggle]'); + $(document).click(function (event) { - var buttons = $('[data-apps-slide-toggle]'); + if (dynamicSlideToggleEnabled) { + buttons = $('[data-apps-slide-toggle]'); + } buttons.each(function (index, button) { @@ -61,4 +73,4 @@ registerAppsSlideToggle(); }); -}(document, jQuery)); \ No newline at end of file +}(document, jQuery, OC)); \ No newline at end of file