apps.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * ownCloud - core
  3. *
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later. See the COPYING file.
  6. *
  7. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  8. * @copyright Bernhard Posselt 2014
  9. */
  10. (function (document, $, exports) {
  11. 'use strict';
  12. var dynamicSlideToggleEnabled = false;
  13. exports.Apps = {
  14. enableDynamicSlideToggle: function () {
  15. dynamicSlideToggleEnabled = true;
  16. }
  17. };
  18. /**
  19. * Provides a way to slide down a target area through a button and slide it
  20. * up if the user clicks somewhere else. Used for the news app settings and
  21. * add new field.
  22. *
  23. * Usage:
  24. * <button data-apps-slide-toggle=".slide-area">slide</button>
  25. * <div class=".slide-area" class="hidden">I'm sliding up</div>
  26. */
  27. var registerAppsSlideToggle = function () {
  28. var buttons = $('[data-apps-slide-toggle]');
  29. $(document).click(function (event) {
  30. if (dynamicSlideToggleEnabled) {
  31. buttons = $('[data-apps-slide-toggle]');
  32. }
  33. buttons.each(function (index, button) {
  34. var areaSelector = $(button).data('apps-slide-toggle');
  35. var area = $(areaSelector);
  36. function hideArea() {
  37. area.slideUp(OC.menuSpeed*4, function() {
  38. area.trigger(new $.Event('hide'));
  39. });
  40. }
  41. function showArea() {
  42. area.slideDown(OC.menuSpeed*4, function() {
  43. area.trigger(new $.Event('show'));
  44. });
  45. }
  46. // do nothing if the area is animated
  47. if (!area.is(':animated')) {
  48. // button toggles the area
  49. if (button === event.target) {
  50. if (area.is(':visible')) {
  51. hideArea();
  52. } else {
  53. showArea();
  54. }
  55. // all other areas that have not been clicked but are open
  56. // should be slid up
  57. } else {
  58. var closest = $(event.target).closest(areaSelector);
  59. if (area.is(':visible') && closest[0] !== area[0]) {
  60. hideArea();
  61. }
  62. }
  63. }
  64. });
  65. });
  66. };
  67. $(document).ready(function () {
  68. registerAppsSlideToggle();
  69. });
  70. }(document, jQuery, OC));