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 <[email protected]> 8 * @copyright Bernhard Posselt 2014 9 */ 10 11(function (document, $, exports) { 12 13 'use strict'; 14 15 var dynamicSlideToggleEnabled = false; 16 17 exports.Apps = { 18 enableDynamicSlideToggle: function () { 19 dynamicSlideToggleEnabled = true; 20 } 21 }; 22 23 /** 24 * Shows the #app-sidebar and add .with-app-sidebar to subsequent siblings 25 * 26 * @param {Object} [$el] sidebar element to show, defaults to $('#app-sidebar') 27 */ 28 exports.Apps.showAppSidebar = function($el) { 29 var $appSidebar = $el || $('#app-sidebar'); 30 $appSidebar.removeClass('disappear'); 31 $('#app-content').addClass('with-app-sidebar').trigger(new $.Event('appresized')); 32 33 }; 34 35 /** 36 * Shows the #app-sidebar and removes .with-app-sidebar from subsequent 37 * siblings 38 * 39 * @param {Object} [$el] sidebar element to hide, defaults to $('#app-sidebar') 40 */ 41 exports.Apps.hideAppSidebar = function($el) { 42 var $appSidebar = $el || $('#app-sidebar'); 43 $appSidebar.addClass('disappear'); 44 $('#app-content').removeClass('with-app-sidebar').trigger(new $.Event('appresized')); 45 }; 46 47 /** 48 * Check if sidebar is visible/hidden 49 * 50 * @param {Object} [$el] sidebar element to check, defaults to $('#app-sidebar') 51 */ 52 53 exports.Apps.AppSidebarVisible = function($el) { 54 var $appSidebar = $el || $('#app-sidebar'); 55 return !$appSidebar.hasClass('disappear'); 56 }; 57 58 /** 59 * Provides a way to slide down a target area through a button and slide it 60 * up if the user clicks somewhere else. Used for the news app settings and 61 * add new field. 62 * 63 * Usage: 64 * <button data-apps-slide-toggle=".slide-area">slide</button> 65 * <div class=".slide-area" class="hidden">I'm sliding up</div> 66 */ 67 var registerAppsSlideToggle = function () { 68 var buttons = $('[data-apps-slide-toggle]'); 69 70 $(document).click(function (event) { 71 72 if (dynamicSlideToggleEnabled) { 73 buttons = $('[data-apps-slide-toggle]'); 74 } 75 76 buttons.each(function (index, button) { 77 78 var areaSelector = $(button).data('apps-slide-toggle'); 79 var area = $(areaSelector); 80 81 function hideArea() { 82 area.slideUp(OC.menuSpeed*4, function() { 83 area.trigger(new $.Event('hide')); 84 }); 85 } 86 function showArea() { 87 area.slideDown(OC.menuSpeed*4, function() { 88 area.trigger(new $.Event('show')); 89 }); 90 } 91 92 // do nothing if the area is animated 93 if (!area.is(':animated')) { 94 95 // button toggles the area 96 if ($(button).is($(event.target).closest('[data-apps-slide-toggle]'))) { 97 if (area.is(':visible')) { 98 hideArea(); 99 } else { 100 showArea(); 101 } 102 103 // all other areas that have not been clicked but are open 104 // should be slid up 105 } else { 106 var closest = $(event.target).closest(areaSelector); 107 if (area.is(':visible') && closest[0] !== area[0]) { 108 hideArea(); 109 } 110 } 111 } 112 }); 113 114 }); 115 }; 116 117 118 $(document).ready(function () { 119 registerAppsSlideToggle(); 120 }); 121 122}(document, jQuery, OC));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.