You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

apps.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. * Shows the #app-sidebar and add .with-app-sidebar to subsequent siblings
  20. *
  21. * @param {Object} [$el] sidebar element to show, defaults to $('#app-sidebar')
  22. */
  23. exports.Apps.showAppSidebar = function($el) {
  24. var $appSidebar = $el || $('#app-sidebar');
  25. $appSidebar.removeClass('disappear')
  26. .show('slide', { direction: 'right' }, 200);
  27. $('#app-content').addClass('with-app-sidebar', 200).trigger(new $.Event('appresized'));
  28. };
  29. /**
  30. * Shows the #app-sidebar and removes .with-app-sidebar from subsequent
  31. * siblings
  32. *
  33. * @param {Object} [$el] sidebar element to hide, defaults to $('#app-sidebar')
  34. */
  35. exports.Apps.hideAppSidebar = function($el) {
  36. var $appSidebar = $el || $('#app-sidebar');
  37. $appSidebar.hide('slide', { direction: 'right' }, 100,
  38. function() {
  39. $appSidebar.addClass('disappear');
  40. });
  41. $('#app-content').removeClass('with-app-sidebar', 100).trigger(new $.Event('appresized'));
  42. };
  43. /**
  44. * Provides a way to slide down a target area through a button and slide it
  45. * up if the user clicks somewhere else. Used for the news app settings and
  46. * add new field.
  47. *
  48. * Usage:
  49. * <button data-apps-slide-toggle=".slide-area">slide</button>
  50. * <div class=".slide-area" class="hidden">I'm sliding up</div>
  51. */
  52. var registerAppsSlideToggle = function () {
  53. var buttons = $('[data-apps-slide-toggle]');
  54. $(document).click(function (event) {
  55. if (dynamicSlideToggleEnabled) {
  56. buttons = $('[data-apps-slide-toggle]');
  57. }
  58. buttons.each(function (index, button) {
  59. var areaSelector = $(button).data('apps-slide-toggle');
  60. var area = $(areaSelector);
  61. function hideArea() {
  62. area.slideUp(OC.menuSpeed*4, function() {
  63. area.trigger(new $.Event('hide'));
  64. });
  65. }
  66. function showArea() {
  67. area.slideDown(OC.menuSpeed*4, function() {
  68. area.trigger(new $.Event('show'));
  69. });
  70. }
  71. // do nothing if the area is animated
  72. if (!area.is(':animated')) {
  73. // button toggles the area
  74. if ($(button).is($(event.target).closest('[data-apps-slide-toggle]'))) {
  75. if (area.is(':visible')) {
  76. hideArea();
  77. } else {
  78. showArea();
  79. }
  80. // all other areas that have not been clicked but are open
  81. // should be slid up
  82. } else {
  83. var closest = $(event.target).closest(areaSelector);
  84. if (area.is(':visible') && closest[0] !== area[0]) {
  85. hideArea();
  86. }
  87. }
  88. }
  89. });
  90. });
  91. };
  92. $(document).ready(function () {
  93. registerAppsSlideToggle();
  94. });
  95. }(document, jQuery, OC));