1/** 2 * @module jira/ajs/layer/inline-layer/options-descriptor 3 */ 4define('jira/ajs/layer/inline-layer/options-descriptor', ['jira/ajs/layer/layer-constants', 'jira/ajs/descriptor', 'jira/ajs/contentretriever/ajax-content-retriever', 'jira/ajs/contentretriever/deferred-content-retriever', 'jira/ajs/contentretriever/dom-content-retriever', 'jira/ajs/layer/inline-layer/iframe-positioning', 'jira/ajs/layer/inline-layer/window-positioning', 'jira/ajs/layer/inline-layer/standard-positioning', 'aui/params', 'jquery'], function (LayerConstants, Descriptor, AjaxContentRetriever, DeferredContentRetriever, DOMContentRetriever, IframePositioning, WindowPositioning, StandardPositioning, params, jQuery) { 5 'use strict'; 6 7 /** 8 * Defines interface and 'intelligent' guesses intended behaviour for inline dialog 9 * 10 * @class InlineLayer.OptionsDescriptor 11 * @extends Descriptor 12 */ 13 return Descriptor.extend({ 14 /** 15 * @constructs 16 * @inheritdoc 17 */ 18 init: function init(properties) { 19 this._super(properties); 20 if (!this.contentRetriever()) { 21 if (this.ajaxOptions()) { 22 this.contentRetriever(new AjaxContentRetriever(this.ajaxOptions())); 23 } else if (typeof this.content() === 'function') { 24 this.contentRetriever(new DeferredContentRetriever(this.content())); 25 } else if (this.content()) { 26 this.contentRetriever(new DOMContentRetriever(this.content())); 27 } else { 28 throw new Error("InlineLayer.OptionsDescriptor: Expected either [ajaxOptions] or [contentRetriever] or [content] to be defined"); 29 } 30 } 31 if (!this.positioningController()) { 32 if (!params.ignoreFrame && this._inIFrame()) { 33 this.positioningController(new IframePositioning()); 34 } else { 35 var $body = jQuery("body"); 36 var isBodyOverflowHidden = $body.css("overflow") === "hidden" || $body.css("overflowY") === "hidden"; 37 if (isBodyOverflowHidden) { 38 this.positioningController(new WindowPositioning()); 39 } else { 40 this.positioningController(new StandardPositioning()); 41 } 42 } 43 } 44 if (!this.offsetTarget() && this.content() instanceof jQuery) { 45 this.offsetTarget(this.content().prev()); 46 } 47 }, 48 _inIFrame: function _inIFrame() { 49 // The following is equivalent to ... 50 // return top !== self && top.AJS; 51 // ... with added cross-origin checks. 52 var parentWindow = window;
53 try { 54 while (parentWindow.parent.window !== parentWindow.window) { 55 // Note: Accessing parentWindow.parent.window might throw an error. 56 parentWindow = parentWindow.parent; 57 if (parentWindow.AJS) { 58 return true; 59 } 60 } 61 } catch (error) { 62 // The same-origin policy prevents access to parentWindow.parent. 63 // Ignore this error and return false. 64 } 65 return false; 66 }, 67 /** 68 * Gets default options 69 * 70 * @return {Object} 71 */ 72 _getDefaultOptions: function _getDefaultOptions() { 73 return { 74 alignment: LayerConstants.INTELLIGENT_GUESS, 75 hideOnScroll: ".form-body", 76 cushion: 20, 77 width: 200 78 }; 79 }, 80 /** 81 * Sets/Gets positioningController. 82 * 83 * @param {Object} positioningController 84 */ 85 positioningController: function positioningController(_positioningController) { 86 if (_positioningController) { 87 this.properties.positioningController = _positioningController; 88 } else { 89 return this.properties.positioningController; 90 } 91 }, 92 /** 93 * Sets/Gets ajaxOptions. If ajaxOptions is a string it will treat it as the url for the request. 94 * 95 * @param {String | Object} ajaxOptions 96 */ 97 ajaxOptions: function ajaxOptions(_ajaxOptions) { 98 if (_ajaxOptions) { 99 this.properties.ajaxOptions = _ajaxOptions; 100 } else { 101 return this.properties.ajaxOptions; 102 } 103 }, 104 /** 105 * Sets/Gets content, this is the element that will be appended to the dropdown. 106 * 107 * @param {String | HTMLElement | jQuery} content 108 * @return {undefined | jQuery} 109 */ 110 content: function content(_content) { 111 if (_content) { 112 _content = jQuery(_content); 113 if (_content.length) { 114 this.properties.content = _content; 115 } 116 } else if (this.properties.content && (this.properties.content.length || typeof this.properties.content === 'function')) { 117 return this.properties.content; 118 } 119 }, 120 /** 121 * Sets/Gets content retriever. A content retriever is an object that defines the mechanisms for retrieving content. 122 * It is possible to define your own content retriever. As long as the object defines specific methods. You can look 123 * at {@link DOMContentRetriever} as an example 124 * 125 * @param {AjaxContentRetriever | DOMContentRetriever | *} contentRetriever 126 * @return {ContentRetriever | *} contentRetriever 127 */ 128 contentRetriever: function contentRetriever(_contentRetriever) { 129 if (_contentRetriever) { 130 this.properties.contentRetriever = _contentRetriever; 131 } else { 132 return this.properties.contentRetriever; 133 } 134 }, 135 /** 136 * Sets/Gets offset target. 137 * 138 * @return {jQuery} 139 */ 140 offsetTarget: function offsetTarget(_offsetTarget) { 141 if (_offsetTarget) { 142 _offsetTarget = jQuery(_offsetTarget); 143 if (_offsetTarget.length) { 144 this.properties.offsetTarget = _offsetTarget; 145 } 146 } else if (this.properties.offsetTarget && (this.properties.offsetTarget.length || typeof this.properties.offsetTarget === 'function')) { 147 return this.properties.offsetTarget; 148 } 149 }, 150 /** 151 * Sets/Gets appendToTrigger property, If true the dropdown will be appended to the trigger element in DOM 152 * 153 * @return {boolean} 154 */ 155 appendToTrigger: function appendToTrigger(_appendToTrigger) { 156 if (_appendToTrigger) { 157 this.properties.appendToTrigger = _appendToTrigger; 158 } else { 159 return this.properties.appendToTrigger; 160 } 161 }, 162 /** 163 * Gets/Sets ignoreFixedParents. If true, the positioning controller will ignore fixed parents when calculating position. 164 * 165 * @return {boolean} 166 * **/ 167 disableFixedPositioning: function disableFixedPositioning(_disableFixedPositioning) { 168 if (typeof _disableFixedPositioning !== 'undefined') { 169 this.properties.disableFixedPositioning = _disableFixedPositioning; 170 } else { 171 return this.properties.disableFixedPositioning; 172 } 173 }, 174 /** 175 * Gets/Sets cushion. This is the pixel buffer between the bottom edge of the InlineLayer DOM element and the bottom 176 * of the window. 177 * 178 * @param {Number} cushion 179 * @return {Number} 180 */ 181 cushion: function cushion(_cushion) { 182 if (_cushion) { 183 this.properties.cushion = _cushion; 184 } else { 185 return this.properties.cushion; 186 } 187 }, 188 /** 189 * Gets/Sets styleClass. This is class/classes applied to the dropdown div 190 */ 191 styleClass: function styleClass(_styleClass) { 192 if (_styleClass) { 193 this.properties.styleClass = _styleClass; 194 } else { 195 return this.properties.styleClass; 196 } 197 }, 198 /** 199 * Gets/Sets hideOnScroll selector. This is a parent element of the layer that when scrolled will hide inl
199ineLayer. 200 * 201 * @param {String} hideOnScroll 202 * @return {String} 203 */ 204 hideOnScroll: function hideOnScroll(_hideOnScroll) { 205 if (_hideOnScroll) { 206 this.properties.hideOnScroll = _hideOnScroll; 207 } else { 208 return this.properties.hideOnScroll; 209 } 210 }, 211 /** 212 * Sets the alignment of the inline layer in reference to it's offset element. If {@link LayerConstants.INTELLIGENT_GUESS}, will 213 * determine if the the offsetElement is further to the right or left of the window. If further to the right will 214 * align right and vice versa. 215 * 216 * @param {LayerConstants.LEFT | LayerConstants.RIGHT | LayerConstants.INTELLIGENT_GUESS} alignment 217 * @return {LayerConstants.LEFT | LayerConstants.RIGHT | LayerConstants.INTELLIGENT_GUESS} 218 */ 219 alignment: function alignment(_alignment) { 220 if (_alignment) { 221 this.properties.alignment = _alignment; 222 } else { 223 return this.properties.alignment; 224 } 225 }, 226 /** 227 * Sets the width of the inline layer in reference to it's offset element. 228 * 229 * @param {Number} width 230 * @return {Number} 231 */ 232 width: function width(_width) { 233 if (_width) { 234 this.properties.width = _width; 235 } else { 236 if (typeof this.properties.width === 'function') { 237 return this.properties.width.call(this); 238 } else { 239 return this.properties.width; 240 } 241 } 242 }, 243 /** 244 * Sets whether it's possible to downsize the inline layer beneath it's scrollWidth. 245 * 246 * @param {Boolean} allowDownsize 247 * @return {Boolean} 248 */ 249 allowDownsize: function allowDownsize(_allowDownsize) { 250 if (_allowDownsize) { 251 this.properties.allowDownsize = _allowDownsize; 252 } else { 253 return this.properties.allowDownsize; 254 } 255 }, 256 /** 257 * Sets the custom events used for this layer. 258 * 259 * The format of customEvents is: 260 * 261 * { 262 * "selector": { 263 * "eventType": function handler(){} 264 * } 265 * } 266 * 267 * @param {Object!} customEvents - custom events to add 268 * @return {Object} 269 */ 270 customEvents: function customEvents(_customEvents) { 271 if (_customEvents) { 272 this.properties.customEvents = _customEvents; 273 } else { 274 return this.properties.customEvents; 275 } 276 } 277 }); 278});
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.