1/* 2Copyright The Infusion copyright holders 3See the AUTHORS.md file at the top-level directory of this distribution and at 4https://github.com/fluid-project/infusion/raw/master/AUTHORS.md. 5 6Licensed under the Educational Community License (ECL), Version 2.0 or the New 7BSD license. You may not use this file except in compliance with one these 8Licenses. 9 10You may obtain a copy of the ECL 2.0 License and BSD License at 11https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt 12*/ 13 14var fluid_3_0_0 = fluid_3_0_0 || {}; 15 16(function ($, fluid) { 17 "use strict"; 18 19 /************************************************************************************ 20 * Scrolling Panel Prefs Editor: * 21 * This is a mixin grade to be applied to a fluid.prefs.prefsEditor type component. * 22 * Typically used for responsive small screen presentations of the separated panel * 23 * to allow for scrolling by clicking on left/right arrows * 24 ************************************************************************************/ 25 26 fluid.defaults("fluid.prefs.arrowScrolling", { 27 gradeNames: ["fluid.modelComponent"], 28 selectors: { 29 // panels: "", // should be supplied by the fluid.prefs.prefsEditor grade. 30 scrollContainer: ".flc-prefsEditor-scrollContainer" 31 }, 32 onScrollDelay: 100, // in ms, used to set the delay for debouncing the scroll event relay 33 model: { 34 // panelMaxIndex: null, // determined by the number of panels calculated after the onPrefsEditorMarkupReady event fired 35 36 // Due to FLUID-6249 ( https://issues.fluidproject.org/browse/FLUID-6249 ) the default value for panelIndex 37 // needs to be commented out or it will interfere with reading in the panelIndex value saved in the store. 38 // panelIndex: 0 // the index of the panel to open on 39 }, 40 events: { 41 beforeReset: null, // should be fired by the fluid.prefs.prefsEditor grade 42 onScroll: null 43 }, 44 modelRelay: { 45 target: "panelIndex", 46 forward: {excludeSource: "init"}, 47 namespace: "limitPanelIndex", 48 singleTransform: { 49 type: "fluid.transforms.limitRange", 50 input: "{that}.model.panelIndex", 51 min: 0, 52 max: "{that}.model.panelMaxIndex" 53 } 54 }, 55 modelListeners: { 56 "panelIndex": { 57 listener: "fluid.prefs.arrowScrolling.scrollToPanel", 58 args: ["{that}", "{change}.value"], 59 excludeSource: ["scrollEvent"], 60 namespace: "scrollToPanel" 61 } 62 }, 63 listeners: { 64 "onReady.scrollEvent": { 65 "this": "{that}
65.dom.scrollContainer", 66 method: "scroll", 67 args: [{ 68 expander: { 69 // Relaying the scroll event to onScroll but debounced to reduce the rate of fire. A high rate 70 // of fire may negatively effect performance for complex handlers. 71 func: "fluid.debounce", 72 args: ["{that}.events.onScroll.fire", "{that}.options.onScrollDelay"] 73 } 74 }] 75 }, 76 "onReady.windowResize": { 77 "this": window, 78 method: "addEventListener", 79 args: ["resize", "{that}.events.onSignificantDOMChange.fire"] 80 }, 81 "onDestroy.removeWindowResize": { 82 "this": window, 83 method: "removeEventListener", 84 args: ["resize", "{that}.events.onSignificantDOMChange.fire"] 85 }, 86 // Need to set panelMaxIndex after onPrefsEditorMarkupReady to ensure that the template has been 87 // rendered before we try to get the number of panels. 88 "onPrefsEditorMarkupReady.setPanelMaxIndex": { 89 changePath: "panelMaxIndex", 90 value: { 91 expander: { 92 funcName: "fluid.prefs.arrowScrolling.calculatePanelMaxIndex", 93 args: ["{that}.dom.panels"] 94 } 95 } 96 }, 97 "beforeReset.resetPanelIndex": { 98 listener: "{that}.applier.fireChangeRequest", 99 args: {path: "panelIndex", value: 0, type: "ADD", source: "reset"} 100 }, 101 "onScroll.setPanelIndex": { 102 changePath: "panelIndex", 103 value: { 104 expander: { 105 funcName: "fluid.prefs.arrowScrolling.getClosestPanelIndex", 106 args: "{that}.dom.panels" 107 } 108 }, 109 source: "scrollEvent" 110 } 111 }, 112 invokers: { 113 eventToScrollIndex: { 114 funcName: "fluid.prefs.arrowScrolling.eventToScrollIndex", 115 args: ["{that}", "{arguments}.0"] 116 } 117 }, 118 distributeOptions: { 119 "arrowScrolling.panel.listeners.bindScrollArrows": { 120 record: { 121 "afterRender.bindScrollArrows": { 122 "this": "{that}.dom.header", 123 method: "click", 124 args: ["{prefsEditor}.eventToScrollIndex"] 125 } 126 }, 127 target: "{that > fluid.prefs.panel}.options.listeners" 128 } 129 } 130 }); 131 132 fluid.prefs.arrowScrolling.calculatePanelMaxIndex = function (panels) { 133 return Math.max(0, panels.length - 1); 134 }; 135 136 fluid.prefs.arrowScrolling.eventToScrollIndex = function (that, event) { 137 event.preventDefault(); 138 var target = $(event.target); 139 var midPoint = target.width() / 2; 140 var currentIndex = that.model.panelIndex || 0; 141 var scrollToIndex = currentIndex + (event.offsetX < midPoint ? -1 : 1); 142 that.applier.change("panelIndex", scrollToIndex, "ADD", "eventToScrollIndex"); 143 }; 144 145 fluid.prefs.arrowScrolling.scrollToPanel = function (that, panelIndex) { 146 panelIndex = panelIndex || 0; 147 var panels = that.locate("panels"); 148 var scrollContainer = that.locate("scrollContainer"); 149 var panel = panels.eq(panelIndex); 150 151 // only attempt to scroll the container if the panel exists and has been rendered. 152 if (panel.width()) { 153 scrollContainer.scrollLeft(scrollContainer.scrollLeft() + panels.eq(panelIndex).offset().left); 154 } 155 }; 156 157 fluid.prefs.arrowScrolling.getClosestPanelIndex = function (panels) { 158 var panelArray = fluid.transform(panels, function (panel, idx) { 159 return { 160 index: idx, 161 offset: Math.abs($(panel).offset().left) 162 }; 163 }); 164 panelArray.sort(function (a, b) { 165 return a.offset - b.offset; 166 }); 167 return fluid.get(panelArray, ["0", "index"]) || 0; 168 }; 169 170})(jQuery, fluid_3_0_0);
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.