From db1511a11d7fe89dbb8cdbff1fd6c08c894c2f9d Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Fri, 23 May 2014 18:49:16 +0200 Subject: add a slideup mechanism --- core/js/app.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 core/js/app.js (limited to 'core') diff --git a/core/js/app.js b/core/js/app.js new file mode 100644 index 00000000000..8f3f04187b7 --- /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 -- cgit v1.2.3