code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function getScrollParent(element) { // Return body, `getScroll` will take care to get the correct `scrollTop` from it if (!element) { return document.body; } switch (element.nodeName) { case 'HTML': case 'BODY': return element.ownerDocument.body; case '#document': return element.body; } // Firefox want us to check `-x` and `-y` variations as well var _getStyleComputedProp = getStyleComputedProperty(element), overflow = _getStyleComputedProp.overflow, overflowX = _getStyleComputedProp.overflowX, overflowY = _getStyleComputedProp.overflowY; if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) { return element; } return getScrollParent(getParentNode(element)); }
Returns the scrolling parent of the given element @method @memberof Popper.Utils @argument {Element} element @returns {Element} scroll parent
getScrollParent
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function isIE(version) { if (version === 11) { return isIE11; } if (version === 10) { return isIE10; } return isIE11 || isIE10; }
Determines if the browser is Internet Explorer @method @memberof Popper.Utils @param {Number} version to check @returns {Boolean} isIE
isIE
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getOffsetParent(element) { if (!element) { return document.documentElement; } var noOffsetParent = isIE(10) ? document.body : null; // NOTE: 1 DOM access here var offsetParent = element.offsetParent || null; // Skip hidden elements which don't have an offsetParent while (offsetParent === noOffsetParent && element.nextElementSibling) { offsetParent = (element = element.nextElementSibling).offsetParent; } var nodeName = offsetParent && offsetParent.nodeName; if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') { return element ? element.ownerDocument.documentElement : document.documentElement; } // .offsetParent will return the closest TH, TD or TABLE in case // no offsetParent is present, I hate this job... if (['TH', 'TD', 'TABLE'].indexOf(offsetParent.nodeName) !== -1 && getStyleComputedProperty(offsetParent, 'position') === 'static') { return getOffsetParent(offsetParent); } return offsetParent; }
Returns the offset parent of the given element @method @memberof Popper.Utils @argument {Element} element @returns {Element} offset parent
getOffsetParent
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function isOffsetContainer(element) { var nodeName = element.nodeName; if (nodeName === 'BODY') { return false; } return nodeName === 'HTML' || getOffsetParent(element.firstElementChild) === element; }
Returns the offset parent of the given element @method @memberof Popper.Utils @argument {Element} element @returns {Element} offset parent
isOffsetContainer
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getRoot(node) { if (node.parentNode !== null) { return getRoot(node.parentNode); } return node; }
Finds the root node (document, shadowDOM root) of the given element @method @memberof Popper.Utils @argument {Element} node @returns {Element} root node
getRoot
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function findCommonOffsetParent(element1, element2) { // This check is needed to avoid errors in case one of the elements isn't defined for any reason if (!element1 || !element1.nodeType || !element2 || !element2.nodeType) { return document.documentElement; } // Here we make sure to give as "start" the element that comes first in the DOM var order = element1.compareDocumentPosition(element2) & Node.DOCUMENT_POSITION_FOLLOWING; var start = order ? element1 : element2; var end = order ? element2 : element1; // Get common ancestor container var range = document.createRange(); range.setStart(start, 0); range.setEnd(end, 0); var commonAncestorContainer = range.commonAncestorContainer; // Both nodes are inside #document if (element1 !== commonAncestorContainer && element2 !== commonAncestorContainer || start.contains(end)) { if (isOffsetContainer(commonAncestorContainer)) { return commonAncestorContainer; } return getOffsetParent(commonAncestorContainer); } // one of the nodes is inside shadowDOM, find which one var element1root = getRoot(element1); if (element1root.host) { return findCommonOffsetParent(element1root.host, element2); } else { return findCommonOffsetParent(element1, getRoot(element2).host); } }
Finds the offset parent common to the two provided nodes @method @memberof Popper.Utils @argument {Element} element1 @argument {Element} element2 @returns {Element} common offset parent
findCommonOffsetParent
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getScroll(element) { var side = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'top'; var upperSide = side === 'top' ? 'scrollTop' : 'scrollLeft'; var nodeName = element.nodeName; if (nodeName === 'BODY' || nodeName === 'HTML') { var html = element.ownerDocument.documentElement; var scrollingElement = element.ownerDocument.scrollingElement || html; return scrollingElement[upperSide]; } return element[upperSide]; }
Gets the scroll value of the given element in the given side (top and left) @method @memberof Popper.Utils @argument {Element} element @argument {String} side `top` or `left` @returns {number} amount of scrolled pixels
getScroll
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function includeScroll(rect, element) { var subtract = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; var scrollTop = getScroll(element, 'top'); var scrollLeft = getScroll(element, 'left'); var modifier = subtract ? -1 : 1; rect.top += scrollTop * modifier; rect.bottom += scrollTop * modifier; rect.left += scrollLeft * modifier; rect.right += scrollLeft * modifier; return rect; }
Gets the scroll value of the given element in the given side (top and left) @method @memberof Popper.Utils @argument {Element} element @argument {String} side `top` or `left` @returns {number} amount of scrolled pixels
includeScroll
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getBordersSize(styles, axis) { var sideA = axis === 'x' ? 'Left' : 'Top'; var sideB = sideA === 'Left' ? 'Right' : 'Bottom'; return parseFloat(styles['border' + sideA + 'Width'], 10) + parseFloat(styles['border' + sideB + 'Width'], 10); }
Gets the scroll value of the given element in the given side (top and left) @method @memberof Popper.Utils @argument {Element} element @argument {String} side `top` or `left` @returns {number} amount of scrolled pixels
getBordersSize
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getSize(axis, body, html, computedStyle) { return Math.max(body['offset' + axis], body['scroll' + axis], html['client' + axis], html['offset' + axis], html['scroll' + axis], isIE(10) ? parseInt(html['offset' + axis]) + parseInt(computedStyle['margin' + (axis === 'Height' ? 'Top' : 'Left')]) + parseInt(computedStyle['margin' + (axis === 'Height' ? 'Bottom' : 'Right')]) : 0); }
Gets the scroll value of the given element in the given side (top and left) @method @memberof Popper.Utils @argument {Element} element @argument {String} side `top` or `left` @returns {number} amount of scrolled pixels
getSize
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getWindowSizes(document) { var body = document.body; var html = document.documentElement; var computedStyle = isIE(10) && getComputedStyle(html); return { height: getSize('Height', body, html, computedStyle), width: getSize('Width', body, html, computedStyle) }; }
Gets the scroll value of the given element in the given side (top and left) @method @memberof Popper.Utils @argument {Element} element @argument {String} side `top` or `left` @returns {number} amount of scrolled pixels
getWindowSizes
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Gets the scroll value of the given element in the given side (top and left) @method @memberof Popper.Utils @argument {Element} element @argument {String} side `top` or `left` @returns {number} amount of scrolled pixels
classCallCheck
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
Gets the scroll value of the given element in the given side (top and left) @method @memberof Popper.Utils @argument {Element} element @argument {String} side `top` or `left` @returns {number} amount of scrolled pixels
defineProperties
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
defineProperty = function (obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
Gets the scroll value of the given element in the given side (top and left) @method @memberof Popper.Utils @argument {Element} element @argument {String} side `top` or `left` @returns {number} amount of scrolled pixels
defineProperty
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getClientRect(offsets) { return _extends({}, offsets, { right: offsets.left + offsets.width, bottom: offsets.top + offsets.height }); }
Given element offsets, generate an output similar to getBoundingClientRect @method @memberof Popper.Utils @argument {Object} offsets @returns {Object} ClientRect like output
getClientRect
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getBoundingClientRect(element) { var rect = {}; // IE10 10 FIX: Please, don't ask, the element isn't // considered in DOM in some circumstances... // This isn't reproducible in IE10 compatibility mode of IE11 try { if (isIE(10)) { rect = element.getBoundingClientRect(); var scrollTop = getScroll(element, 'top'); var scrollLeft = getScroll(element, 'left'); rect.top += scrollTop; rect.left += scrollLeft; rect.bottom += scrollTop; rect.right += scrollLeft; } else { rect = element.getBoundingClientRect(); } } catch (e) {} var result = { left: rect.left, top: rect.top, width: rect.right - rect.left, height: rect.bottom - rect.top }; // subtract scrollbar size from sizes var sizes = element.nodeName === 'HTML' ? getWindowSizes(element.ownerDocument) : {}; var width = sizes.width || element.clientWidth || result.right - result.left; var height = sizes.height || element.clientHeight || result.bottom - result.top; var horizScrollbar = element.offsetWidth - width; var vertScrollbar = element.offsetHeight - height; // if an hypothetical scrollbar is detected, we must be sure it's not a `border` // we make this check conditional for performance reasons if (horizScrollbar || vertScrollbar) { var styles = getStyleComputedProperty(element); horizScrollbar -= getBordersSize(styles, 'x'); vertScrollbar -= getBordersSize(styles, 'y'); result.width -= horizScrollbar; result.height -= vertScrollbar; } return getClientRect(result); }
Get bounding client rect of given element @method @memberof Popper.Utils @param {HTMLElement} element @return {Object} client rect
getBoundingClientRect
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getOffsetRectRelativeToArbitraryNode(children, parent) { var fixedPosition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; var isIE10 = isIE(10); var isHTML = parent.nodeName === 'HTML'; var childrenRect = getBoundingClientRect(children); var parentRect = getBoundingClientRect(parent); var scrollParent = getScrollParent(children); var styles = getStyleComputedProperty(parent); var borderTopWidth = parseFloat(styles.borderTopWidth, 10); var borderLeftWidth = parseFloat(styles.borderLeftWidth, 10); // In cases where the parent is fixed, we must ignore negative scroll in offset calc if (fixedPosition && isHTML) { parentRect.top = Math.max(parentRect.top, 0); parentRect.left = Math.max(parentRect.left, 0); } var offsets = getClientRect({ top: childrenRect.top - parentRect.top - borderTopWidth, left: childrenRect.left - parentRect.left - borderLeftWidth, width: childrenRect.width, height: childrenRect.height }); offsets.marginTop = 0; offsets.marginLeft = 0; // Subtract margins of documentElement in case it's being used as parent // we do this only on HTML because it's the only element that behaves // differently when margins are applied to it. The margins are included in // the box of the documentElement, in the other cases not. if (!isIE10 && isHTML) { var marginTop = parseFloat(styles.marginTop, 10); var marginLeft = parseFloat(styles.marginLeft, 10); offsets.top -= borderTopWidth - marginTop; offsets.bottom -= borderTopWidth - marginTop; offsets.left -= borderLeftWidth - marginLeft; offsets.right -= borderLeftWidth - marginLeft; // Attach marginTop and marginLeft because in some circumstances we may need them offsets.marginTop = marginTop; offsets.marginLeft = marginLeft; } if (isIE10 && !fixedPosition ? parent.contains(scrollParent) : parent === scrollParent && scrollParent.nodeName !== 'BODY') { offsets = includeScroll(offsets, parent); } return offsets; }
Get bounding client rect of given element @method @memberof Popper.Utils @param {HTMLElement} element @return {Object} client rect
getOffsetRectRelativeToArbitraryNode
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getViewportOffsetRectRelativeToArtbitraryNode(element) { var excludeScroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var html = element.ownerDocument.documentElement; var relativeOffset = getOffsetRectRelativeToArbitraryNode(element, html); var width = Math.max(html.clientWidth, window.innerWidth || 0); var height = Math.max(html.clientHeight, window.innerHeight || 0); var scrollTop = !excludeScroll ? getScroll(html) : 0; var scrollLeft = !excludeScroll ? getScroll(html, 'left') : 0; var offset = { top: scrollTop - relativeOffset.top + relativeOffset.marginTop, left: scrollLeft - relativeOffset.left + relativeOffset.marginLeft, width: width, height: height }; return getClientRect(offset); }
Get bounding client rect of given element @method @memberof Popper.Utils @param {HTMLElement} element @return {Object} client rect
getViewportOffsetRectRelativeToArtbitraryNode
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function isFixed(element) { var nodeName = element.nodeName; if (nodeName === 'BODY' || nodeName === 'HTML') { return false; } if (getStyleComputedProperty(element, 'position') === 'fixed') { return true; } var parentNode = getParentNode(element); if (!parentNode) { return false; } return isFixed(parentNode); }
Check if the given element is fixed or is inside a fixed parent @method @memberof Popper.Utils @argument {Element} element @argument {Element} customContainer @returns {Boolean} answer to "isFixed?"
isFixed
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getFixedPositionOffsetParent(element) { // This check is needed to avoid errors in case one of the elements isn't defined for any reason if (!element || !element.parentElement || isIE()) { return document.documentElement; } var el = element.parentElement; while (el && getStyleComputedProperty(el, 'transform') === 'none') { el = el.parentElement; } return el || document.documentElement; }
Finds the first parent of an element that has a transformed property defined @method @memberof Popper.Utils @argument {Element} element @returns {Element} first transformed parent or documentElement
getFixedPositionOffsetParent
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function computeAutoPlacement(placement, refRect, popper, reference, boundariesElement) { var padding = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0; if (placement.indexOf('auto') === -1) { return placement; } var boundaries = getBoundaries(popper, reference, padding, boundariesElement); var rects = { top: { width: boundaries.width, height: refRect.top - boundaries.top }, right: { width: boundaries.right - refRect.right, height: boundaries.height }, bottom: { width: boundaries.width, height: boundaries.bottom - refRect.bottom }, left: { width: refRect.left - boundaries.left, height: boundaries.height } }; var sortedAreas = Object.keys(rects).map(function (key) { return _extends({ key: key }, rects[key], { area: getArea(rects[key]) }); }).sort(function (a, b) { return b.area - a.area; }); var filteredAreas = sortedAreas.filter(function (_ref2) { var width = _ref2.width, height = _ref2.height; return width >= popper.clientWidth && height >= popper.clientHeight; }); var computedPlacement = filteredAreas.length > 0 ? filteredAreas[0].key : sortedAreas[0].key; var variation = placement.split('-')[1]; return computedPlacement + (variation ? '-' + variation : ''); }
Utility used to transform the `auto` placement to the placement with more available space. @method @memberof Popper.Utils @argument {Object} data - The data object generated by update method @argument {Object} options - Modifiers configuration and options @returns {Object} The data object, properly modified
computeAutoPlacement
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getReferenceOffsets(state, popper, reference) { var fixedPosition = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; var commonOffsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, reference); return getOffsetRectRelativeToArbitraryNode(reference, commonOffsetParent, fixedPosition); }
Get offsets to the reference element @method @memberof Popper.Utils @param {Object} state @param {Element} popper - the popper element @param {Element} reference - the reference element (the popper will be relative to this) @param {Element} fixedPosition - is in fixed position mode @returns {Object} An object containing the offsets which will be applied to the popper
getReferenceOffsets
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getOuterSizes(element) { var window = element.ownerDocument.defaultView; var styles = window.getComputedStyle(element); var x = parseFloat(styles.marginTop || 0) + parseFloat(styles.marginBottom || 0); var y = parseFloat(styles.marginLeft || 0) + parseFloat(styles.marginRight || 0); var result = { width: element.offsetWidth + y, height: element.offsetHeight + x }; return result; }
Get the outer sizes of the given element (offset size + margins) @method @memberof Popper.Utils @argument {Element} element @returns {Object} object containing width and height properties
getOuterSizes
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getOppositePlacement(placement) { var hash = { left: 'right', right: 'left', bottom: 'top', top: 'bottom' }; return placement.replace(/left|right|bottom|top/g, function (matched) { return hash[matched]; }); }
Get the opposite placement of the given one @method @memberof Popper.Utils @argument {String} placement @returns {String} flipped placement
getOppositePlacement
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getPopperOffsets(popper, referenceOffsets, placement) { placement = placement.split('-')[0]; // Get popper node sizes var popperRect = getOuterSizes(popper); // Add position, width and height to our offsets object var popperOffsets = { width: popperRect.width, height: popperRect.height }; // depending by the popper placement we have to compute its offsets slightly differently var isHoriz = ['right', 'left'].indexOf(placement) !== -1; var mainSide = isHoriz ? 'top' : 'left'; var secondarySide = isHoriz ? 'left' : 'top'; var measurement = isHoriz ? 'height' : 'width'; var secondaryMeasurement = !isHoriz ? 'height' : 'width'; popperOffsets[mainSide] = referenceOffsets[mainSide] + referenceOffsets[measurement] / 2 - popperRect[measurement] / 2; if (placement === secondarySide) { popperOffsets[secondarySide] = referenceOffsets[secondarySide] - popperRect[secondaryMeasurement]; } else { popperOffsets[secondarySide] = referenceOffsets[getOppositePlacement(secondarySide)]; } return popperOffsets; }
Get offsets to the popper @method @memberof Popper.Utils @param {Object} position - CSS position the Popper will get applied @param {HTMLElement} popper - the popper element @param {Object} referenceOffsets - the reference offsets (the popper will be relative to this) @param {String} placement - one of the valid placement options @returns {Object} popperOffsets - An object containing the offsets which will be applied to the popper
getPopperOffsets
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function find(arr, check) { // use native find if supported if (Array.prototype.find) { return arr.find(check); } // use `filter` to obtain the same behavior of `find` return arr.filter(check)[0]; }
Mimics the `find` method of Array @method @memberof Popper.Utils @argument {Array} arr @argument prop @argument value @returns index or -1
find
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function findIndex(arr, prop, value) { // use native findIndex if supported if (Array.prototype.findIndex) { return arr.findIndex(function (cur) { return cur[prop] === value; }); } // use `find` + `indexOf` if `findIndex` isn't supported var match = find(arr, function (obj) { return obj[prop] === value; }); return arr.indexOf(match); }
Return the index of the matching object @method @memberof Popper.Utils @argument {Array} arr @argument prop @argument value @returns index or -1
findIndex
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function runModifiers(modifiers, data, ends) { var modifiersToRun = ends === undefined ? modifiers : modifiers.slice(0, findIndex(modifiers, 'name', ends)); modifiersToRun.forEach(function (modifier) { if (modifier['function']) { // eslint-disable-line dot-notation console.warn('`modifier.function` is deprecated, use `modifier.fn`!'); } var fn = modifier['function'] || modifier.fn; // eslint-disable-line dot-notation if (modifier.enabled && isFunction(fn)) { // Add properties to offsets to make them a complete clientRect object // we do this before each modifier to make sure the previous one doesn't // mess with these values data.offsets.popper = getClientRect(data.offsets.popper); data.offsets.reference = getClientRect(data.offsets.reference); data = fn(data, modifier); } }); return data; }
Loop trough the list of modifiers and run them in order, each of them will then edit the data object. @method @memberof Popper.Utils @param {dataObject} data @param {Array} modifiers @param {String} ends - Optional modifier name used as stopper @returns {dataObject}
runModifiers
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function update() { // if popper is destroyed, don't perform any further update if (this.state.isDestroyed) { return; } var data = { instance: this, styles: {}, arrowStyles: {}, attributes: {}, flipped: false, offsets: {} }; // compute reference element offsets data.offsets.reference = getReferenceOffsets(this.state, this.popper, this.reference, this.options.positionFixed); // compute auto placement, store placement inside the data object, // modifiers will be able to edit `placement` if needed // and refer to originalPlacement to know the original value data.placement = computeAutoPlacement(this.options.placement, data.offsets.reference, this.popper, this.reference, this.options.modifiers.flip.boundariesElement, this.options.modifiers.flip.padding); // store the computed placement inside `originalPlacement` data.originalPlacement = data.placement; data.positionFixed = this.options.positionFixed; // compute the popper offsets data.offsets.popper = getPopperOffsets(this.popper, data.offsets.reference, data.placement); data.offsets.popper.position = this.options.positionFixed ? 'fixed' : 'absolute'; // run the modifiers data = runModifiers(this.modifiers, data); // the first `update` will call `onCreate` callback // the other ones will call `onUpdate` callback if (!this.state.isCreated) { this.state.isCreated = true; this.options.onCreate(data); } else { this.options.onUpdate(data); } }
Updates the position of the popper, computing the new offsets and applying the new style.<br /> Prefer `scheduleUpdate` over `update` because of performance reasons. @method @memberof Popper
update
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function isModifierEnabled(modifiers, modifierName) { return modifiers.some(function (_ref) { var name = _ref.name, enabled = _ref.enabled; return enabled && name === modifierName; }); }
Helper used to know if the given modifier is enabled. @method @memberof Popper.Utils @returns {Boolean}
isModifierEnabled
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getSupportedPropertyName(property) { var prefixes = [false, 'ms', 'Webkit', 'Moz', 'O']; var upperProp = property.charAt(0).toUpperCase() + property.slice(1); for (var i = 0; i < prefixes.length; i++) { var prefix = prefixes[i]; var toCheck = prefix ? '' + prefix + upperProp : property; if (typeof document.body.style[toCheck] !== 'undefined') { return toCheck; } } return null; }
Get the prefixed supported property name @method @memberof Popper.Utils @argument {String} property (camelCase) @returns {String} prefixed property (camelCase or PascalCase, depending on the vendor prefix)
getSupportedPropertyName
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function destroy() { this.state.isDestroyed = true; // touch DOM only if `applyStyle` modifier is enabled if (isModifierEnabled(this.modifiers, 'applyStyle')) { this.popper.removeAttribute('x-placement'); this.popper.style.position = ''; this.popper.style.top = ''; this.popper.style.left = ''; this.popper.style.right = ''; this.popper.style.bottom = ''; this.popper.style.willChange = ''; this.popper.style[getSupportedPropertyName('transform')] = ''; } this.disableEventListeners(); // remove the popper if user explicity asked for the deletion on destroy // do not use `remove` because IE11 doesn't support it if (this.options.removeOnDestroy) { this.popper.parentNode.removeChild(this.popper); } return this; }
Destroys the popper. @method @memberof Popper
destroy
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getWindow(element) { var ownerDocument = element.ownerDocument; return ownerDocument ? ownerDocument.defaultView : window; }
Get the window associated with the element @argument {Element} element @returns {Window}
getWindow
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function attachToScrollParents(scrollParent, event, callback, scrollParents) { var isBody = scrollParent.nodeName === 'BODY'; var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent; target.addEventListener(event, callback, { passive: true }); if (!isBody) { attachToScrollParents(getScrollParent(target.parentNode), event, callback, scrollParents); } scrollParents.push(target); }
Get the window associated with the element @argument {Element} element @returns {Window}
attachToScrollParents
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function setupEventListeners(reference, options, state, updateBound) { // Resize event listener on window state.updateBound = updateBound; getWindow(reference).addEventListener('resize', state.updateBound, { passive: true }); // Scroll event listener on scroll parents var scrollElement = getScrollParent(reference); attachToScrollParents(scrollElement, 'scroll', state.updateBound, state.scrollParents); state.scrollElement = scrollElement; state.eventsEnabled = true; return state; }
Setup needed event listeners used to update the popper position @method @memberof Popper.Utils @private
setupEventListeners
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function enableEventListeners() { if (!this.state.eventsEnabled) { this.state = setupEventListeners(this.reference, this.options, this.state, this.scheduleUpdate); } }
It will add resize/scroll events and start recalculating position of the popper element when they are triggered. @method @memberof Popper
enableEventListeners
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function removeEventListeners(reference, state) { // Remove resize event listener on window getWindow(reference).removeEventListener('resize', state.updateBound); // Remove scroll event listener on scroll parents state.scrollParents.forEach(function (target) { target.removeEventListener('scroll', state.updateBound); }); // Reset state state.updateBound = null; state.scrollParents = []; state.scrollElement = null; state.eventsEnabled = false; return state; }
Remove event listeners used to update the popper position @method @memberof Popper.Utils @private
removeEventListeners
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function disableEventListeners() { if (this.state.eventsEnabled) { cancelAnimationFrame(this.scheduleUpdate); this.state = removeEventListeners(this.reference, this.state); } }
It will remove resize/scroll events and won't recalculate popper position when they are triggered. It also won't trigger `onUpdate` callback anymore, unless you call `update` method manually. @method @memberof Popper
disableEventListeners
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function isNumeric(n) { return n !== '' && !isNaN(parseFloat(n)) && isFinite(n); }
Tells if a given input is a number @method @memberof Popper.Utils @param {*} input to check @return {Boolean}
isNumeric
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function setStyles(element, styles) { Object.keys(styles).forEach(function (prop) { var unit = ''; // add unit if the value is numeric and is one of the following if (['width', 'height', 'top', 'right', 'bottom', 'left'].indexOf(prop) !== -1 && isNumeric(styles[prop])) { unit = 'px'; } element.style[prop] = styles[prop] + unit; }); }
Set the style to the given popper @method @memberof Popper.Utils @argument {Element} element - Element to apply the style to @argument {Object} styles Object with a list of properties and values which will be applied to the element
setStyles
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function setAttributes(element, attributes) { Object.keys(attributes).forEach(function (prop) { var value = attributes[prop]; if (value !== false) { element.setAttribute(prop, attributes[prop]); } else { element.removeAttribute(prop); } }); }
Set the attributes to the given popper @method @memberof Popper.Utils @argument {Element} element - Element to apply the attributes to @argument {Object} styles Object with a list of properties and values which will be applied to the element
setAttributes
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function applyStyle(data) { // any property present in `data.styles` will be applied to the popper, // in this way we can make the 3rd party modifiers add custom styles to it // Be aware, modifiers could override the properties defined in the previous // lines of this modifier! setStyles(data.instance.popper, data.styles); // any property present in `data.attributes` will be applied to the popper, // they will be set as HTML attributes of the element setAttributes(data.instance.popper, data.attributes); // if arrowElement is defined and arrowStyles has some properties if (data.arrowElement && Object.keys(data.arrowStyles).length) { setStyles(data.arrowElement, data.arrowStyles); } return data; }
@function @memberof Modifiers @argument {Object} data - The data object generated by `update` method @argument {Object} data.styles - List of style properties - values to apply to popper element @argument {Object} data.attributes - List of attribute properties - values to apply to popper element @argument {Object} options - Modifiers configuration and options @returns {Object} The same data object
applyStyle
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function applyStyleOnLoad(reference, popper, options, modifierOptions, state) { // compute reference element offsets var referenceOffsets = getReferenceOffsets(state, popper, reference, options.positionFixed); // compute auto placement, store placement inside the data object, // modifiers will be able to edit `placement` if needed // and refer to originalPlacement to know the original value var placement = computeAutoPlacement(options.placement, referenceOffsets, popper, reference, options.modifiers.flip.boundariesElement, options.modifiers.flip.padding); popper.setAttribute('x-placement', placement); // Apply `position` to popper before anything else because // without the position applied we can't guarantee correct computations setStyles(popper, { position: options.positionFixed ? 'fixed' : 'absolute' }); return options; }
Set the x-placement attribute before everything else because it could be used to add margins to the popper margins needs to be calculated to get the correct popper offsets. @method @memberof Popper.modifiers @param {HTMLElement} reference - The reference element used to position the popper @param {HTMLElement} popper - The HTML element used as popper @param {Object} options - Popper.js options
applyStyleOnLoad
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getRoundedOffsets(data, shouldRound) { var _data$offsets = data.offsets, popper = _data$offsets.popper, reference = _data$offsets.reference; var round = Math.round, floor = Math.floor; var noRound = function noRound(v) { return v; }; var referenceWidth = round(reference.width); var popperWidth = round(popper.width); var isVertical = ['left', 'right'].indexOf(data.placement) !== -1; var isVariation = data.placement.indexOf('-') !== -1; var sameWidthParity = referenceWidth % 2 === popperWidth % 2; var bothOddWidth = referenceWidth % 2 === 1 && popperWidth % 2 === 1; var horizontalToInteger = !shouldRound ? noRound : isVertical || isVariation || sameWidthParity ? round : floor; var verticalToInteger = !shouldRound ? noRound : round; return { left: horizontalToInteger(bothOddWidth && !isVariation && shouldRound ? popper.left - 1 : popper.left), top: verticalToInteger(popper.top), bottom: verticalToInteger(popper.bottom), right: horizontalToInteger(popper.right) }; }
@function @memberof Popper.Utils @argument {Object} data - The data object generated by `update` method @argument {Boolean} shouldRound - If the offsets should be rounded at all @returns {Object} The popper's position offsets rounded The tale of pixel-perfect positioning. It's still not 100% perfect, but as good as it can be within reason. Discussion here: https://github.com/FezVrasta/popper.js/pull/715 Low DPI screens cause a popper to be blurry if not using full pixels (Safari as well on High DPI screens). Firefox prefers no rounding for positioning and does not have blurriness on high DPI screens. Only horizontal placement and left/right values need to be considered.
getRoundedOffsets
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
noRound = function noRound(v) { return v; }
@function @memberof Popper.Utils @argument {Object} data - The data object generated by `update` method @argument {Boolean} shouldRound - If the offsets should be rounded at all @returns {Object} The popper's position offsets rounded The tale of pixel-perfect positioning. It's still not 100% perfect, but as good as it can be within reason. Discussion here: https://github.com/FezVrasta/popper.js/pull/715 Low DPI screens cause a popper to be blurry if not using full pixels (Safari as well on High DPI screens). Firefox prefers no rounding for positioning and does not have blurriness on high DPI screens. Only horizontal placement and left/right values need to be considered.
noRound
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function computeStyle(data, options) { var x = options.x, y = options.y; var popper = data.offsets.popper; // Remove this legacy support in Popper.js v2 var legacyGpuAccelerationOption = find(data.instance.modifiers, function (modifier) { return modifier.name === 'applyStyle'; }).gpuAcceleration; if (legacyGpuAccelerationOption !== undefined) { console.warn('WARNING: `gpuAcceleration` option moved to `computeStyle` modifier and will not be supported in future versions of Popper.js!'); } var gpuAcceleration = legacyGpuAccelerationOption !== undefined ? legacyGpuAccelerationOption : options.gpuAcceleration; var offsetParent = getOffsetParent(data.instance.popper); var offsetParentRect = getBoundingClientRect(offsetParent); // Styles var styles = { position: popper.position }; var offsets = getRoundedOffsets(data, window.devicePixelRatio < 2 || !isFirefox); var sideA = x === 'bottom' ? 'top' : 'bottom'; var sideB = y === 'right' ? 'left' : 'right'; // if gpuAcceleration is set to `true` and transform is supported, // we use `translate3d` to apply the position to the popper we // automatically use the supported prefixed version if needed var prefixedProperty = getSupportedPropertyName('transform'); // now, let's make a step back and look at this code closely (wtf?) // If the content of the popper grows once it's been positioned, it // may happen that the popper gets misplaced because of the new content // overflowing its reference element // To avoid this problem, we provide two options (x and y), which allow // the consumer to define the offset origin. // If we position a popper on top of a reference element, we can set // `x` to `top` to make the popper grow towards its top instead of // its bottom. var left = void 0, top = void 0; if (sideA === 'bottom') { // when offsetParent is <html> the positioning is relative to the bottom of the screen (excluding the scrollbar) // and not the bottom of the html element if (offsetParent.nodeName === 'HTML') { top = -offsetParent.clientHeight + offsets.bottom; } else { top = -offsetParentRect.height + offsets.bottom; } } else { top = offsets.top; } if (sideB === 'right') { if (offsetParent.nodeName === 'HTML') { left = -offsetParent.clientWidth + offsets.right; } else { left = -offsetParentRect.width + offsets.right; } } else { left = offsets.left; } if (gpuAcceleration && prefixedProperty) { styles[prefixedProperty] = 'translate3d(' + left + 'px, ' + top + 'px, 0)'; styles[sideA] = 0; styles[sideB] = 0; styles.willChange = 'transform'; } else { // othwerise, we use the standard `top`, `left`, `bottom` and `right` properties var invertTop = sideA === 'bottom' ? -1 : 1; var invertLeft = sideB === 'right' ? -1 : 1; styles[sideA] = top * invertTop; styles[sideB] = left * invertLeft; styles.willChange = sideA + ', ' + sideB; } // Attributes var attributes = { 'x-placement': data.placement }; // Update `data` attributes, styles and arrowStyles data.attributes = _extends({}, attributes, data.attributes); data.styles = _extends({}, styles, data.styles); data.arrowStyles = _extends({}, data.offsets.arrow, data.arrowStyles); return data; }
@function @memberof Modifiers @argument {Object} data - The data object generated by `update` method @argument {Object} options - Modifiers configuration and options @returns {Object} The data object, properly modified
computeStyle
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function isModifierRequired(modifiers, requestingName, requestedName) { var requesting = find(modifiers, function (_ref) { var name = _ref.name; return name === requestingName; }); var isRequired = !!requesting && modifiers.some(function (modifier) { return modifier.name === requestedName && modifier.enabled && modifier.order < requesting.order; }); if (!isRequired) { var _requesting = '`' + requestingName + '`'; var requested = '`' + requestedName + '`'; console.warn(requested + ' modifier is required by ' + _requesting + ' modifier in order to work, be sure to include it before ' + _requesting + '!'); } return isRequired; }
Helper used to know if the given modifier depends from another one.<br /> It checks if the needed modifier is listed and enabled. @method @memberof Popper.Utils @param {Array} modifiers - list of modifiers @param {String} requestingName - name of requesting modifier @param {String} requestedName - name of requested modifier @returns {Boolean}
isModifierRequired
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function arrow(data, options) { var _data$offsets$arrow; // arrow depends on keepTogether in order to work if (!isModifierRequired(data.instance.modifiers, 'arrow', 'keepTogether')) { return data; } var arrowElement = options.element; // if arrowElement is a string, suppose it's a CSS selector if (typeof arrowElement === 'string') { arrowElement = data.instance.popper.querySelector(arrowElement); // if arrowElement is not found, don't run the modifier if (!arrowElement) { return data; } } else { // if the arrowElement isn't a query selector we must check that the // provided DOM node is child of its popper node if (!data.instance.popper.contains(arrowElement)) { console.warn('WARNING: `arrow.element` must be child of its popper element!'); return data; } } var placement = data.placement.split('-')[0]; var _data$offsets = data.offsets, popper = _data$offsets.popper, reference = _data$offsets.reference; var isVertical = ['left', 'right'].indexOf(placement) !== -1; var len = isVertical ? 'height' : 'width'; var sideCapitalized = isVertical ? 'Top' : 'Left'; var side = sideCapitalized.toLowerCase(); var altSide = isVertical ? 'left' : 'top'; var opSide = isVertical ? 'bottom' : 'right'; var arrowElementSize = getOuterSizes(arrowElement)[len]; // // extends keepTogether behavior making sure the popper and its // reference have enough pixels in conjunction // // top/left side if (reference[opSide] - arrowElementSize < popper[side]) { data.offsets.popper[side] -= popper[side] - (reference[opSide] - arrowElementSize); } // bottom/right side if (reference[side] + arrowElementSize > popper[opSide]) { data.offsets.popper[side] += reference[side] + arrowElementSize - popper[opSide]; } data.offsets.popper = getClientRect(data.offsets.popper); // compute center of the popper var center = reference[side] + reference[len] / 2 - arrowElementSize / 2; // Compute the sideValue using the updated popper offsets // take popper margin in account because we don't have this info available var css = getStyleComputedProperty(data.instance.popper); var popperMarginSide = parseFloat(css['margin' + sideCapitalized], 10); var popperBorderSide = parseFloat(css['border' + sideCapitalized + 'Width'], 10); var sideValue = center - data.offsets.popper[side] - popperMarginSide - popperBorderSide; // prevent arrowElement from being placed not contiguously to its popper sideValue = Math.max(Math.min(popper[len] - arrowElementSize, sideValue), 0); data.arrowElement = arrowElement; data.offsets.arrow = (_data$offsets$arrow = {}, defineProperty(_data$offsets$arrow, side, Math.round(sideValue)), defineProperty(_data$offsets$arrow, altSide, ''), _data$offsets$arrow); return data; }
@function @memberof Modifiers @argument {Object} data - The data object generated by update method @argument {Object} options - Modifiers configuration and options @returns {Object} The data object, properly modified
arrow
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function getOppositeVariation(variation) { if (variation === 'end') { return 'start'; } else if (variation === 'start') { return 'end'; } return variation; }
Get the opposite placement variation of the given one @method @memberof Popper.Utils @argument {String} placement variation @returns {String} flipped placement variation
getOppositeVariation
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function clockwise(placement) { var counter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var index = validPlacements.indexOf(placement); var arr = validPlacements.slice(index + 1).concat(validPlacements.slice(0, index)); return counter ? arr.reverse() : arr; }
Given an initial placement, returns all the subsequent placements clockwise (or counter-clockwise). @method @memberof Popper.Utils @argument {String} placement - A valid placement (it accepts variations) @argument {Boolean} counter - Set to true to walk the placements counterclockwise @returns {Array} placements including their variations
clockwise
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function flip(data, options) { // if `inner` modifier is enabled, we can't use the `flip` modifier if (isModifierEnabled(data.instance.modifiers, 'inner')) { return data; } if (data.flipped && data.placement === data.originalPlacement) { // seems like flip is trying to loop, probably there's not enough space on any of the flippable sides return data; } var boundaries = getBoundaries(data.instance.popper, data.instance.reference, options.padding, options.boundariesElement, data.positionFixed); var placement = data.placement.split('-')[0]; var placementOpposite = getOppositePlacement(placement); var variation = data.placement.split('-')[1] || ''; var flipOrder = []; switch (options.behavior) { case BEHAVIORS.FLIP: flipOrder = [placement, placementOpposite]; break; case BEHAVIORS.CLOCKWISE: flipOrder = clockwise(placement); break; case BEHAVIORS.COUNTERCLOCKWISE: flipOrder = clockwise(placement, true); break; default: flipOrder = options.behavior; } flipOrder.forEach(function (step, index) { if (placement !== step || flipOrder.length === index + 1) { return data; } placement = data.placement.split('-')[0]; placementOpposite = getOppositePlacement(placement); var popperOffsets = data.offsets.popper; var refOffsets = data.offsets.reference; // using floor because the reference offsets may contain decimals we are not going to consider here var floor = Math.floor; var overlapsRef = placement === 'left' && floor(popperOffsets.right) > floor(refOffsets.left) || placement === 'right' && floor(popperOffsets.left) < floor(refOffsets.right) || placement === 'top' && floor(popperOffsets.bottom) > floor(refOffsets.top) || placement === 'bottom' && floor(popperOffsets.top) < floor(refOffsets.bottom); var overflowsLeft = floor(popperOffsets.left) < floor(boundaries.left); var overflowsRight = floor(popperOffsets.right) > floor(boundaries.right); var overflowsTop = floor(popperOffsets.top) < floor(boundaries.top); var overflowsBottom = floor(popperOffsets.bottom) > floor(boundaries.bottom); var overflowsBoundaries = placement === 'left' && overflowsLeft || placement === 'right' && overflowsRight || placement === 'top' && overflowsTop || placement === 'bottom' && overflowsBottom; // flip the variation if required var isVertical = ['top', 'bottom'].indexOf(placement) !== -1; var flippedVariation = !!options.flipVariations && (isVertical && variation === 'start' && overflowsLeft || isVertical && variation === 'end' && overflowsRight || !isVertical && variation === 'start' && overflowsTop || !isVertical && variation === 'end' && overflowsBottom); if (overlapsRef || overflowsBoundaries || flippedVariation) { // this boolean to detect any flip loop data.flipped = true; if (overlapsRef || overflowsBoundaries) { placement = flipOrder[index + 1]; } if (flippedVariation) { variation = getOppositeVariation(variation); } data.placement = placement + (variation ? '-' + variation : ''); // this object contains `position`, we want to preserve it along with // any additional property we may add in the future data.offsets.popper = _extends({}, data.offsets.popper, getPopperOffsets(data.instance.popper, data.offsets.reference, data.placement)); data = runModifiers(data.instance.modifiers, data, 'flip'); } }); return data; }
@function @memberof Modifiers @argument {Object} data - The data object generated by update method @argument {Object} options - Modifiers configuration and options @returns {Object} The data object, properly modified
flip
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function keepTogether(data) { var _data$offsets = data.offsets, popper = _data$offsets.popper, reference = _data$offsets.reference; var placement = data.placement.split('-')[0]; var floor = Math.floor; var isVertical = ['top', 'bottom'].indexOf(placement) !== -1; var side = isVertical ? 'right' : 'bottom'; var opSide = isVertical ? 'left' : 'top'; var measurement = isVertical ? 'width' : 'height'; if (popper[side] < floor(reference[opSide])) { data.offsets.popper[opSide] = floor(reference[opSide]) - popper[measurement]; } if (popper[opSide] > floor(reference[side])) { data.offsets.popper[opSide] = floor(reference[side]); } return data; }
@function @memberof Modifiers @argument {Object} data - The data object generated by update method @argument {Object} options - Modifiers configuration and options @returns {Object} The data object, properly modified
keepTogether
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function toValue(str, measurement, popperOffsets, referenceOffsets) { // separate value from unit var split = str.match(/((?:\-|\+)?\d*\.?\d*)(.*)/); var value = +split[1]; var unit = split[2]; // If it's not a number it's an operator, I guess if (!value) { return str; } if (unit.indexOf('%') === 0) { var element = void 0; switch (unit) { case '%p': element = popperOffsets; break; case '%': case '%r': default: element = referenceOffsets; } var rect = getClientRect(element); return rect[measurement] / 100 * value; } else if (unit === 'vh' || unit === 'vw') { // if is a vh or vw, we calculate the size based on the viewport var size = void 0; if (unit === 'vh') { size = Math.max(document.documentElement.clientHeight, window.innerHeight || 0); } else { size = Math.max(document.documentElement.clientWidth, window.innerWidth || 0); } return size / 100 * value; } else { // if is an explicit pixel unit, we get rid of the unit and keep the value // if is an implicit unit, it's px, and we return just the value return value; } }
Converts a string containing value + unit into a px value number @function @memberof {modifiers~offset} @private @argument {String} str - Value + unit string @argument {String} measurement - `height` or `width` @argument {Object} popperOffsets @argument {Object} referenceOffsets @returns {Number|String} Value in pixels, or original string if no values were extracted
toValue
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function parseOffset(offset, popperOffsets, referenceOffsets, basePlacement) { var offsets = [0, 0]; // Use height if placement is left or right and index is 0 otherwise use width // in this way the first offset will use an axis and the second one // will use the other one var useHeight = ['right', 'left'].indexOf(basePlacement) !== -1; // Split the offset string to obtain a list of values and operands // The regex addresses values with the plus or minus sign in front (+10, -20, etc) var fragments = offset.split(/(\+|\-)/).map(function (frag) { return frag.trim(); }); // Detect if the offset string contains a pair of values or a single one // they could be separated by comma or space var divider = fragments.indexOf(find(fragments, function (frag) { return frag.search(/,|\s/) !== -1; })); if (fragments[divider] && fragments[divider].indexOf(',') === -1) { console.warn('Offsets separated by white space(s) are deprecated, use a comma (,) instead.'); } // If divider is found, we divide the list of values and operands to divide // them by ofset X and Y. var splitRegex = /\s*,\s*|\s+/; var ops = divider !== -1 ? [fragments.slice(0, divider).concat([fragments[divider].split(splitRegex)[0]]), [fragments[divider].split(splitRegex)[1]].concat(fragments.slice(divider + 1))] : [fragments]; // Convert the values with units to absolute pixels to allow our computations ops = ops.map(function (op, index) { // Most of the units rely on the orientation of the popper var measurement = (index === 1 ? !useHeight : useHeight) ? 'height' : 'width'; var mergeWithPrevious = false; return op // This aggregates any `+` or `-` sign that aren't considered operators // e.g.: 10 + +5 => [10, +, +5] .reduce(function (a, b) { if (a[a.length - 1] === '' && ['+', '-'].indexOf(b) !== -1) { a[a.length - 1] = b; mergeWithPrevious = true; return a; } else if (mergeWithPrevious) { a[a.length - 1] += b; mergeWithPrevious = false; return a; } else { return a.concat(b); } }, []) // Here we convert the string values into number values (in px) .map(function (str) { return toValue(str, measurement, popperOffsets, referenceOffsets); }); }); // Loop trough the offsets arrays and execute the operations ops.forEach(function (op, index) { op.forEach(function (frag, index2) { if (isNumeric(frag)) { offsets[index] += frag * (op[index2 - 1] === '-' ? -1 : 1); } }); }); return offsets; }
Parse an `offset` string to extrapolate `x` and `y` numeric offsets. @function @memberof {modifiers~offset} @private @argument {String} offset @argument {Object} popperOffsets @argument {Object} referenceOffsets @argument {String} basePlacement @returns {Array} a two cells array with x and y offsets in numbers
parseOffset
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function offset(data, _ref) { var offset = _ref.offset; var placement = data.placement, _data$offsets = data.offsets, popper = _data$offsets.popper, reference = _data$offsets.reference; var basePlacement = placement.split('-')[0]; var offsets = void 0; if (isNumeric(+offset)) { offsets = [+offset, 0]; } else { offsets = parseOffset(offset, popper, reference, basePlacement); } if (basePlacement === 'left') { popper.top += offsets[0]; popper.left -= offsets[1]; } else if (basePlacement === 'right') { popper.top += offsets[0]; popper.left += offsets[1]; } else if (basePlacement === 'top') { popper.left += offsets[0]; popper.top -= offsets[1]; } else if (basePlacement === 'bottom') { popper.left += offsets[0]; popper.top += offsets[1]; } data.popper = popper; return data; }
@function @memberof Modifiers @argument {Object} data - The data object generated by update method @argument {Object} options - Modifiers configuration and options @argument {Number|String} options.offset=0 The offset value as described in the modifier description @returns {Object} The data object, properly modified
offset
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function preventOverflow(data, options) { var boundariesElement = options.boundariesElement || getOffsetParent(data.instance.popper); // If offsetParent is the reference element, we really want to // go one step up and use the next offsetParent as reference to // avoid to make this modifier completely useless and look like broken if (data.instance.reference === boundariesElement) { boundariesElement = getOffsetParent(boundariesElement); } // NOTE: DOM access here // resets the popper's position so that the document size can be calculated excluding // the size of the popper element itself var transformProp = getSupportedPropertyName('transform'); var popperStyles = data.instance.popper.style; // assignment to help minification var top = popperStyles.top, left = popperStyles.left, transform = popperStyles[transformProp]; popperStyles.top = ''; popperStyles.left = ''; popperStyles[transformProp] = ''; var boundaries = getBoundaries(data.instance.popper, data.instance.reference, options.padding, boundariesElement, data.positionFixed); // NOTE: DOM access here // restores the original style properties after the offsets have been computed popperStyles.top = top; popperStyles.left = left; popperStyles[transformProp] = transform; options.boundaries = boundaries; var order = options.priority; var popper = data.offsets.popper; var check = { primary: function primary(placement) { var value = popper[placement]; if (popper[placement] < boundaries[placement] && !options.escapeWithReference) { value = Math.max(popper[placement], boundaries[placement]); } return defineProperty({}, placement, value); }, secondary: function secondary(placement) { var mainSide = placement === 'right' ? 'left' : 'top'; var value = popper[mainSide]; if (popper[placement] > boundaries[placement] && !options.escapeWithReference) { value = Math.min(popper[mainSide], boundaries[placement] - (placement === 'right' ? popper.width : popper.height)); } return defineProperty({}, mainSide, value); } }; order.forEach(function (placement) { var side = ['left', 'top'].indexOf(placement) !== -1 ? 'primary' : 'secondary'; popper = _extends({}, popper, check[side](placement)); }); data.offsets.popper = popper; return data; }
@function @memberof Modifiers @argument {Object} data - The data object generated by `update` method @argument {Object} options - Modifiers configuration and options @returns {Object} The data object, properly modified
preventOverflow
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function shift(data) { var placement = data.placement; var basePlacement = placement.split('-')[0]; var shiftvariation = placement.split('-')[1]; // if shift shiftvariation is specified, run the modifier if (shiftvariation) { var _data$offsets = data.offsets, reference = _data$offsets.reference, popper = _data$offsets.popper; var isVertical = ['bottom', 'top'].indexOf(basePlacement) !== -1; var side = isVertical ? 'left' : 'top'; var measurement = isVertical ? 'width' : 'height'; var shiftOffsets = { start: defineProperty({}, side, reference[side]), end: defineProperty({}, side, reference[side] + reference[measurement] - popper[measurement]) }; data.offsets.popper = _extends({}, popper, shiftOffsets[shiftvariation]); } return data; }
@function @memberof Modifiers @argument {Object} data - The data object generated by `update` method @argument {Object} options - Modifiers configuration and options @returns {Object} The data object, properly modified
shift
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function hide(data) { if (!isModifierRequired(data.instance.modifiers, 'hide', 'preventOverflow')) { return data; } var refRect = data.offsets.reference; var bound = find(data.instance.modifiers, function (modifier) { return modifier.name === 'preventOverflow'; }).boundaries; if (refRect.bottom < bound.top || refRect.left > bound.right || refRect.top > bound.bottom || refRect.right < bound.left) { // Avoid unnecessary DOM access if visibility hasn't changed if (data.hide === true) { return data; } data.hide = true; data.attributes['x-out-of-boundaries'] = ''; } else { // Avoid unnecessary DOM access if visibility hasn't changed if (data.hide === false) { return data; } data.hide = false; data.attributes['x-out-of-boundaries'] = false; } return data; }
@function @memberof Modifiers @argument {Object} data - The data object generated by update method @argument {Object} options - Modifiers configuration and options @returns {Object} The data object, properly modified
hide
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function inner(data) { var placement = data.placement; var basePlacement = placement.split('-')[0]; var _data$offsets = data.offsets, popper = _data$offsets.popper, reference = _data$offsets.reference; var isHoriz = ['left', 'right'].indexOf(basePlacement) !== -1; var subtractLength = ['top', 'left'].indexOf(basePlacement) === -1; popper[isHoriz ? 'left' : 'top'] = reference[basePlacement] - (subtractLength ? popper[isHoriz ? 'width' : 'height'] : 0); data.placement = getOppositePlacement(placement); data.offsets.popper = getClientRect(popper); return data; }
@function @memberof Modifiers @argument {Object} data - The data object generated by `update` method @argument {Object} options - Modifiers configuration and options @returns {Object} The data object, properly modified
inner
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function Popper(reference, popper) { var _this = this; var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; classCallCheck(this, Popper); this.scheduleUpdate = function () { return requestAnimationFrame(_this.update); }; // make update() debounced, so that it only runs at most once-per-tick this.update = debounce(this.update.bind(this)); // with {} we create a new object with the options inside it this.options = _extends({}, Popper.Defaults, options); // init state this.state = { isDestroyed: false, isCreated: false, scrollParents: [] }; // get reference and popper elements (allow jQuery wrappers) this.reference = reference && reference.jquery ? reference[0] : reference; this.popper = popper && popper.jquery ? popper[0] : popper; // Deep merge modifiers options this.options.modifiers = {}; Object.keys(_extends({}, Popper.Defaults.modifiers, options.modifiers)).forEach(function (name) { _this.options.modifiers[name] = _extends({}, Popper.Defaults.modifiers[name] || {}, options.modifiers ? options.modifiers[name] : {}); }); // Refactoring modifiers' list (Object => Array) this.modifiers = Object.keys(this.options.modifiers).map(function (name) { return _extends({ name: name }, _this.options.modifiers[name]); }) // sort the modifiers by order .sort(function (a, b) { return a.order - b.order; }); // modifiers have the ability to execute arbitrary code when Popper.js get inited // such code is executed in the same order of its modifier // they could add new properties to their options configuration // BE AWARE: don't add options to `options.modifiers.name` but to `modifierOptions`! this.modifiers.forEach(function (modifierOptions) { if (modifierOptions.enabled && isFunction(modifierOptions.onLoad)) { modifierOptions.onLoad(_this.reference, _this.popper, _this.options, modifierOptions, _this.state); } }); // fire the first update to position the popper in the right place this.update(); var eventsEnabled = this.options.eventsEnabled; if (eventsEnabled) { // setup event listeners, they will take care of update the position in specific situations this.enableEventListeners(); } this.state.eventsEnabled = eventsEnabled; }
Creates a new Popper.js instance. @class Popper @param {HTMLElement|referenceObject} reference - The reference element used to position the popper @param {HTMLElement} popper - The HTML element used as the popper @param {Object} options - Your custom options to override the ones defined in [Defaults](#defaults) @return {Object} instance - The generated Popper.js instance
Popper
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
transitionComplete = function transitionComplete() { if (_this3._config.focus) { _this3._element.focus(); } _this3._isTransitioning = false; $(_this3._element).trigger(shownEvent); }
`document` has 2 events `Event.FOCUSIN` and `Event.CLICK_DATA_API` Do not move `document` in `htmlElements` array It will remove `Event.CLICK_DATA_API` event that should remain
transitionComplete
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
callbackRemove = function callbackRemove() { _this8._removeBackdrop(); if (callback) { callback(); } }
`document` has 2 events `Event.FOCUSIN` and `Event.CLICK_DATA_API` Do not move `document` in `htmlElements` array It will remove `Event.CLICK_DATA_API` event that should remain
callbackRemove
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function allowedAttribute(attr, allowedAttributeList) { var attrName = attr.nodeName.toLowerCase(); if (allowedAttributeList.indexOf(attrName) !== -1) { if (uriAttrs.indexOf(attrName) !== -1) { return Boolean(attr.nodeValue.match(SAFE_URL_PATTERN) || attr.nodeValue.match(DATA_URL_PATTERN)); } return true; } var regExp = allowedAttributeList.filter(function (attrRegex) { return attrRegex instanceof RegExp; }); // Check if a regular expression validates the attribute. for (var i = 0, l = regExp.length; i < l; i++) { if (attrName.match(regExp[i])) { return true; } } return false; }
A pattern that matches safe data URLs. Only matches image, video and audio types. Shoutout to Angular 7 https://github.com/angular/angular/blob/7.2.4/packages/core/src/sanitization/url_sanitizer.ts
allowedAttribute
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
function sanitizeHtml(unsafeHtml, whiteList, sanitizeFn) { if (unsafeHtml.length === 0) { return unsafeHtml; } if (sanitizeFn && typeof sanitizeFn === 'function') { return sanitizeFn(unsafeHtml); } var domParser = new window.DOMParser(); var createdDocument = domParser.parseFromString(unsafeHtml, 'text/html'); var whitelistKeys = Object.keys(whiteList); var elements = [].slice.call(createdDocument.body.querySelectorAll('*')); var _loop = function _loop(i, len) { var el = elements[i]; var elName = el.nodeName.toLowerCase(); if (whitelistKeys.indexOf(el.nodeName.toLowerCase()) === -1) { el.parentNode.removeChild(el); return "continue"; } var attributeList = [].slice.call(el.attributes); var whitelistedAttributes = [].concat(whiteList['*'] || [], whiteList[elName] || []); attributeList.forEach(function (attr) { if (!allowedAttribute(attr, whitelistedAttributes)) { el.removeAttribute(attr.nodeName); } }); }; for (var i = 0, len = elements.length; i < len; i++) { var _ret = _loop(i, len); if (_ret === "continue") continue; } return createdDocument.body.innerHTML; }
A pattern that matches safe data URLs. Only matches image, video and audio types. Shoutout to Angular 7 https://github.com/angular/angular/blob/7.2.4/packages/core/src/sanitization/url_sanitizer.ts
sanitizeHtml
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
_loop = function _loop(i, len) { var el = elements[i]; var elName = el.nodeName.toLowerCase(); if (whitelistKeys.indexOf(el.nodeName.toLowerCase()) === -1) { el.parentNode.removeChild(el); return "continue"; } var attributeList = [].slice.call(el.attributes); var whitelistedAttributes = [].concat(whiteList['*'] || [], whiteList[elName] || []); attributeList.forEach(function (attr) { if (!allowedAttribute(attr, whitelistedAttributes)) { el.removeAttribute(attr.nodeName); } }); }
A pattern that matches safe data URLs. Only matches image, video and audio types. Shoutout to Angular 7 https://github.com/angular/angular/blob/7.2.4/packages/core/src/sanitization/url_sanitizer.ts
_loop
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
complete = function complete() { if (_this.config.animation) { _this._fixTransition(); } var prevHoverState = _this._hoverState; _this._hoverState = null; $(_this.element).trigger(_this.constructor.Event.SHOWN); if (prevHoverState === HoverState.OUT) { _this._leave(null, _this); } }
Check for Popper dependency Popper - https://popper.js.org
complete
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
complete = function complete() { if (_this2._hoverState !== HoverState.SHOW && tip.parentNode) { tip.parentNode.removeChild(tip); } _this2._cleanTipClass(); _this2.element.removeAttribute('aria-describedby'); $(_this2.element).trigger(_this2.constructor.Event.HIDDEN); if (_this2._popper !== null) { _this2._popper.destroy(); } if (callback) { callback(); } }
Check for Popper dependency Popper - https://popper.js.org
complete
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.bundle.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.bundle.js
MIT
transitionComplete = function transitionComplete() { if (_this3._config.focus) { _this3._element.focus(); } _this3._isTransitioning = false; $(_this3._element).trigger(shownEvent); }
`document` has 2 events `Event.FOCUSIN` and `Event.CLICK_DATA_API` Do not move `document` in `htmlElements` array It will remove `Event.CLICK_DATA_API` event that should remain
transitionComplete
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.js
MIT
callbackRemove = function callbackRemove() { _this8._removeBackdrop(); if (callback) { callback(); } }
`document` has 2 events `Event.FOCUSIN` and `Event.CLICK_DATA_API` Do not move `document` in `htmlElements` array It will remove `Event.CLICK_DATA_API` event that should remain
callbackRemove
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.js
MIT
function allowedAttribute(attr, allowedAttributeList) { var attrName = attr.nodeName.toLowerCase(); if (allowedAttributeList.indexOf(attrName) !== -1) { if (uriAttrs.indexOf(attrName) !== -1) { return Boolean(attr.nodeValue.match(SAFE_URL_PATTERN) || attr.nodeValue.match(DATA_URL_PATTERN)); } return true; } var regExp = allowedAttributeList.filter(function (attrRegex) { return attrRegex instanceof RegExp; }); // Check if a regular expression validates the attribute. for (var i = 0, l = regExp.length; i < l; i++) { if (attrName.match(regExp[i])) { return true; } } return false; }
A pattern that matches safe data URLs. Only matches image, video and audio types. Shoutout to Angular 7 https://github.com/angular/angular/blob/7.2.4/packages/core/src/sanitization/url_sanitizer.ts
allowedAttribute
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.js
MIT
function sanitizeHtml(unsafeHtml, whiteList, sanitizeFn) { if (unsafeHtml.length === 0) { return unsafeHtml; } if (sanitizeFn && typeof sanitizeFn === 'function') { return sanitizeFn(unsafeHtml); } var domParser = new window.DOMParser(); var createdDocument = domParser.parseFromString(unsafeHtml, 'text/html'); var whitelistKeys = Object.keys(whiteList); var elements = [].slice.call(createdDocument.body.querySelectorAll('*')); var _loop = function _loop(i, len) { var el = elements[i]; var elName = el.nodeName.toLowerCase(); if (whitelistKeys.indexOf(el.nodeName.toLowerCase()) === -1) { el.parentNode.removeChild(el); return "continue"; } var attributeList = [].slice.call(el.attributes); var whitelistedAttributes = [].concat(whiteList['*'] || [], whiteList[elName] || []); attributeList.forEach(function (attr) { if (!allowedAttribute(attr, whitelistedAttributes)) { el.removeAttribute(attr.nodeName); } }); }; for (var i = 0, len = elements.length; i < len; i++) { var _ret = _loop(i, len); if (_ret === "continue") continue; } return createdDocument.body.innerHTML; }
A pattern that matches safe data URLs. Only matches image, video and audio types. Shoutout to Angular 7 https://github.com/angular/angular/blob/7.2.4/packages/core/src/sanitization/url_sanitizer.ts
sanitizeHtml
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.js
MIT
_loop = function _loop(i, len) { var el = elements[i]; var elName = el.nodeName.toLowerCase(); if (whitelistKeys.indexOf(el.nodeName.toLowerCase()) === -1) { el.parentNode.removeChild(el); return "continue"; } var attributeList = [].slice.call(el.attributes); var whitelistedAttributes = [].concat(whiteList['*'] || [], whiteList[elName] || []); attributeList.forEach(function (attr) { if (!allowedAttribute(attr, whitelistedAttributes)) { el.removeAttribute(attr.nodeName); } }); }
A pattern that matches safe data URLs. Only matches image, video and audio types. Shoutout to Angular 7 https://github.com/angular/angular/blob/7.2.4/packages/core/src/sanitization/url_sanitizer.ts
_loop
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.js
MIT
complete = function complete() { if (_this.config.animation) { _this._fixTransition(); } var prevHoverState = _this._hoverState; _this._hoverState = null; $(_this.element).trigger(_this.constructor.Event.SHOWN); if (prevHoverState === HoverState.OUT) { _this._leave(null, _this); } }
Check for Popper dependency Popper - https://popper.js.org
complete
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.js
MIT
complete = function complete() { if (_this2._hoverState !== HoverState.SHOW && tip.parentNode) { tip.parentNode.removeChild(tip); } _this2._cleanTipClass(); _this2.element.removeAttribute('aria-describedby'); $(_this2.element).trigger(_this2.constructor.Event.HIDDEN); if (_this2._popper !== null) { _this2._popper.destroy(); } if (callback) { callback(); } }
Check for Popper dependency Popper - https://popper.js.org
complete
javascript
gxtrobot/bustag
bustag/app/static/js/bootstrap.js
https://github.com/gxtrobot/bustag/blob/master/bustag/app/static/js/bootstrap.js
MIT
function makeFailHTML(msg) { return '\n<table style="background-color: #8CE; width: 100%; height: 100%;"><tr>\n<td align="center">\n<div style="display: table-cell; vertical-align: middle;">\n<div style="">' + msg + '</div>\n</div>\n</td></tr></table>\n'; }
Creates the HTLM for a failure message @param {string} canvasContainerId id of container of th canvas. @return {string} The html.
makeFailHTML
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function setupWebGL(canvas, optAttribs, onError) { function showLink(str) { var container = canvas.parentNode; if (container) { container.innerHTML = makeFailHTML(str); } } function handleError(errorCode, msg) { if (typeof onError === 'function') { onError(errorCode); } else { showLink(msg); } } if (!window.WebGLRenderingContext) { handleError(ERROR_BROWSER_SUPPORT, GET_A_WEBGL_BROWSER); return null; } var context = create3DContext(canvas, optAttribs); if (!context) { handleError(ERROR_OTHER, OTHER_PROBLEM); } else { context.getExtension('OES_standard_derivatives'); } return context; }
Creates a webgl context. If creation fails it will change the contents of the container of the <canvas> tag to an error message with the correct links for WebGL, unless `onError` option is defined to a callback, which allows for custom error handling.. @param {Element} canvas. The canvas element to create a context from. @param {WebGLContextCreationAttributes} optAttribs Any creation attributes you want to pass in. @return {WebGLRenderingContext} The created context.
setupWebGL
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function showLink(str) { var container = canvas.parentNode; if (container) { container.innerHTML = makeFailHTML(str); } }
Creates a webgl context. If creation fails it will change the contents of the container of the <canvas> tag to an error message with the correct links for WebGL, unless `onError` option is defined to a callback, which allows for custom error handling.. @param {Element} canvas. The canvas element to create a context from. @param {WebGLContextCreationAttributes} optAttribs Any creation attributes you want to pass in. @return {WebGLRenderingContext} The created context.
showLink
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function handleError(errorCode, msg) { if (typeof onError === 'function') { onError(errorCode); } else { showLink(msg); } }
Creates a webgl context. If creation fails it will change the contents of the container of the <canvas> tag to an error message with the correct links for WebGL, unless `onError` option is defined to a callback, which allows for custom error handling.. @param {Element} canvas. The canvas element to create a context from. @param {WebGLContextCreationAttributes} optAttribs Any creation attributes you want to pass in. @return {WebGLRenderingContext} The created context.
handleError
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function create3DContext(canvas, optAttribs) { var names = ['webgl', 'experimental-webgl']; var context = null; for (var ii = 0; ii < names.length; ++ii) { try { context = canvas.getContext(names[ii], optAttribs); } catch (e) { if (context) { break; } } } return context; }
Creates a webgl context. @param {!Canvas} canvas The canvas tag to get context from. If one is not passed in one will be created. @return {!WebGLContext} The created context.
create3DContext
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function createShader(main, source, type, offset) { var gl = main.gl; var shader = gl.createShader(type); gl.shaderSource(shader, source); gl.compileShader(shader); var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS); if (!compiled) { // Something went wrong during compilation; get the error lastError = gl.getShaderInfoLog(shader); console.error('*** Error compiling shader ' + shader + ':' + lastError); main.trigger('error', { shader: shader, source: source, type: type, error: lastError, offset: offset || 0 }); gl.deleteShader(shader); return null; } return shader; }
Creates a webgl context. @param {!Canvas} canvas The canvas tag to get context from. If one is not passed in one will be created. @return {!WebGLContext} The created context.
createShader
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function createProgram(main, shaders, optAttribs, optLocations) { var gl = main.gl; var program = gl.createProgram(); for (var ii = 0; ii < shaders.length; ++ii) { gl.attachShader(program, shaders[ii]); } if (optAttribs) { for (var _ii = 0; _ii < optAttribs.length; ++_ii) { gl.bindAttribLocation(program, optLocations ? optLocations[_ii] : _ii, optAttribs[_ii]); } } gl.linkProgram(program); // Check the link status var linked = gl.getProgramParameter(program, gl.LINK_STATUS); if (!linked) { // something went wrong with the link lastError = gl.getProgramInfoLog(program); console.log('Error in program linking:' + lastError); gl.deleteProgram(program); return null; } return program; }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
createProgram
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function parseUniforms(uniforms) { var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; var parsed = []; for (var name in uniforms) { var uniform = uniforms[name]; var u = void 0; if (prefix) { name = prefix + '.' + name; } // Single float if (typeof uniform === 'number') { parsed.push({ type: 'float', method: '1f', name: name, value: uniform }); } // Array: vector, array of floats, array of textures, or array of structs else if (Array.isArray(uniform)) { // Numeric values if (typeof uniform[0] === 'number') { // float vectors (vec2, vec3, vec4) if (uniform.length === 1) { parsed.push({ type: 'float', method: '1f', name: name, value: uniform }); } // float vectors (vec2, vec3, vec4) else if (uniform.length >= 2 && uniform.length <= 4) { parsed.push({ type: 'vec' + uniform.length, method: uniform.length + 'fv', name: name, value: uniform }); } // float array else if (uniform.length > 4) { parsed.push({ type: 'float[]', method: '1fv', name: name + '[0]', value: uniform }); } // TODO: assume matrix for (typeof == Float32Array && length == 16)? } // Array of textures else if (typeof uniform[0] === 'string') { parsed.push({ type: 'sampler2D', method: '1i', name: name, value: uniform }); } // Array of arrays - but only arrays of vectors are allowed in this case else if (Array.isArray(uniform[0]) && typeof uniform[0][0] === 'number') { // float vectors (vec2, vec3, vec4) if (uniform[0].length >= 2 && uniform[0].length <= 4) { // Set each vector in the array for (u = 0; u < uniform.length; u++) { parsed.push({ type: 'vec' + uniform[0].length, method: uniform[u].length + 'fv', name: name + '[' + u + ']', value: uniform[u] }); } } // else error? } // Array of structures else if (_typeof(uniform[0]) === 'object') { for (u = 0; u < uniform.length; u++) { // Set each struct in the array parsed.push.apply(parsed, toConsumableArray(parseUniforms(uniform[u], name + '[' + u + ']'))); } } } // Boolean else if (typeof uniform === 'boolean') { parsed.push({ type: 'bool', method: '1i', name: name, value: uniform }); } // Texture else if (typeof uniform === 'string') { parsed.push({ type: 'sampler2D', method: '1i', name: name, value: uniform }); } // Structure else if ((typeof uniform === 'undefined' ? 'undefined' : _typeof(uniform)) === 'object') { // Set each field in the struct parsed.push.apply(parsed, toConsumableArray(parseUniforms(uniform, name))); } // TODO: support other non-float types? (int, etc.) } return parsed; }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
parseUniforms
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function isCanvasVisible(canvas) { return canvas.getBoundingClientRect().top + canvas.height > 0 && canvas.getBoundingClientRect().top < (window.innerHeight || document.documentElement.clientHeight); }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
isCanvasVisible
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function isPowerOf2(value) { return (value & value - 1) === 0; }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
isPowerOf2
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function isSafari() { return (/^((?!chrome|android).)*safari/i.test(navigator.userAgent) ); }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
isSafari
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function isDiff(a, b) { if (a && b) { return a.toString() !== b.toString(); } return false; }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
isDiff
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function subscribeMixin$1(target) { var listeners = new Set(); return Object.assign(target, { on: function on(type, f) { var listener = {}; listener[type] = f; listeners.add(listener); }, off: function off(type, f) { if (f) { var listener = {}; listener[type] = f; listeners.delete(listener); } else { var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = listeners[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var item = _step.value; var _iteratorNormalCompletion2 = true; var _didIteratorError2 = false; var _iteratorError2 = undefined; try { for (var _iterator2 = Object.keys(item)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { var key = _step2.value; if (key === type) { listeners.delete(item); return; } } } catch (err) { _didIteratorError2 = true; _iteratorError2 = err; } finally { try { if (!_iteratorNormalCompletion2 && _iterator2.return) { _iterator2.return(); } } finally { if (_didIteratorError2) { throw _iteratorError2; } } } } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } } }, listSubscriptions: function listSubscriptions() { var _iteratorNormalCompletion3 = true; var _didIteratorError3 = false; var _iteratorError3 = undefined; try { for (var _iterator3 = listeners[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { var item = _step3.value; console.log(item); } } catch (err) { _didIteratorError3 = true; _iteratorError3 = err; } finally { try { if (!_iteratorNormalCompletion3 && _iterator3.return) { _iterator3.return(); } } finally { if (_didIteratorError3) { throw _iteratorError3; } } } }, subscribe: function subscribe(listener) { listeners.add(listener); }, unsubscribe: function unsubscribe(listener) { listeners.delete(listener); }, unsubscribeAll: function unsubscribeAll() { listeners.clear(); }, trigger: function trigger(event) { for (var _len = arguments.length, data = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { data[_key - 1] = arguments[_key]; } var _iteratorNormalCompletion4 = true; var _didIteratorError4 = false; var _iteratorError4 = undefined; try { for (var _iterator4 = listeners[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { var listener = _step4.value; if (typeof listener[event] === 'function') { listener[event].apply(listener, toConsumableArray(data)); } } } catch (err) { _didIteratorError4 = true; _iteratorError4 = err; } finally { try { if (!_iteratorNormalCompletion4 && _iterator4.return) { _iterator4.return(); } } finally { if (_didIteratorError4) { throw _iteratorError4; } } } } }); }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
subscribeMixin$1
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function Texture(gl, name) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; classCallCheck(this, Texture); subscribeMixin$1(this); this.gl = gl; this.texture = gl.createTexture(); if (this.texture) { this.valid = true; } this.bind(); this.name = name; this.source = null; this.sourceType = null; this.loading = null; // a Promise object to track the loading state of this texture // Default to a 1-pixel black texture so we can safely render while we wait for an image to load // See: http://stackoverflow.com/questions/19722247/webgl-wait-for-texture-to-load this.setData(1, 1, new Uint8Array([0, 0, 0, 255]), { filtering: 'linear' }); this.setFiltering(options.filtering); this.load(options); }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
Texture
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function GlslCanvas(canvas, contextOptions, options) { var _this = this; classCallCheck(this, GlslCanvas); subscribeMixin$1(this); contextOptions = contextOptions || {}; options = options || {}; this.width = canvas.clientWidth; this.height = canvas.clientHeight; this.canvas = canvas; this.gl = undefined; this.program = undefined; this.textures = {}; this.buffers = {}; this.uniforms = {}; this.vbo = {}; this.isValid = false; this.BUFFER_COUNT = 0; this.TEXTURE_COUNT = 0; this.vertexString = contextOptions.vertexString || '\n#ifdef GL_ES\nprecision mediump float;\n#endif\n\nattribute vec2 a_position;\nattribute vec2 a_texcoord;\n\nvarying vec2 v_texcoord;\n\nvoid main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n v_texcoord = a_texcoord;\n}\n'; this.fragmentString = contextOptions.fragmentString || '\n#ifdef GL_ES\nprecision mediump float;\n#endif\n\nvarying vec2 v_texcoord;\n\nvoid main(){\n gl_FragColor = vec4(0.0);\n}\n'; // GL Context var gl = setupWebGL(canvas, contextOptions, options.onError); if (!gl) { return; } this.gl = gl; this.timeLoad = this.timePrev = performance.now(); this.timeDelta = 0.0; this.forceRender = true; this.paused = false; this.realToCSSPixels = window.devicePixelRatio || 1; // Allow alpha canvas.style.backgroundColor = contextOptions.backgroundColor || 'rgba(1,1,1,0)'; // Load shader if (canvas.hasAttribute('data-fragment')) { this.fragmentString = canvas.getAttribute('data-fragment'); } else if (canvas.hasAttribute('data-fragment-url')) { var source = canvas.getAttribute('data-fragment-url'); xhr.get(source, function (error, response, body) { _this.load(body, _this.vertexString); }); } // Load shader if (canvas.hasAttribute('data-vertex')) { this.vertexString = canvas.getAttribute('data-vertex'); } else if (canvas.hasAttribute('data-vertex-url')) { var _source = canvas.getAttribute('data-vertex-url'); xhr.get(_source, function (error, response, body) { _this.load(_this.fragmentString, body); }); } this.load(); if (!this.program) { return; } // Define Vertex buffer var texCoordsLoc = gl.getAttribLocation(this.program, 'a_texcoord'); this.vbo.texCoords = gl.createBuffer(); this.gl.bindBuffer(gl.ARRAY_BUFFER, this.vbo.texCoords); this.gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]), gl.STATIC_DRAW); this.gl.enableVertexAttribArray(texCoordsLoc); this.gl.vertexAttribPointer(texCoordsLoc, 2, gl.FLOAT, false, 0, 0); var verticesLoc = gl.getAttribLocation(this.program, 'a_position'); this.vbo.vertices = gl.createBuffer(); this.gl.bindBuffer(gl.ARRAY_BUFFER, this.vbo.vertices); this.gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0]), gl.STATIC_DRAW); this.gl.enableVertexAttribArray(verticesLoc); this.gl.vertexAttribPointer(verticesLoc, 2, gl.FLOAT, false, 0, 0); // load TEXTURES if (canvas.hasAttribute('data-textures')) { var imgList = canvas.getAttribute('data-textures').split(','); for (var nImg in imgList) { this.setUniform('u_tex' + nImg, imgList[nImg]); } } // ========================== EVENTS var mouse = { x: 0, y: 0 }; document.addEventListener('mousemove', function (e) { mouse.x = e.clientX || e.pageX; mouse.y = e.clientY || e.pageY; }, false); var sandbox = this; function RenderLoop() { if (sandbox.nMouse > 1) { sandbox.setMouse(mouse); } sandbox.forceRender = sandbox.resize(); sandbox.render(); window.requestAnimationFrame(RenderLoop); } // Start this.setMouse({ x: 0, y: 0 }); RenderLoop(); return this; }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
GlslCanvas
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function RenderLoop() { if (sandbox.nMouse > 1) { sandbox.setMouse(mouse); } sandbox.forceRender = sandbox.resize(); sandbox.render(); window.requestAnimationFrame(RenderLoop); }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
RenderLoop
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function finishTest() { // Revert changes... go back to normal sandbox.paused = pre_test_paused; if (fragString || vertString) { sandbox.load(pre_test_frag, pre_test_vert); } }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
finishTest
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function waitForTest() { sandbox.forceRender = true; sandbox.render(); var available = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_AVAILABLE_EXT); var disjoint = sandbox.gl.getParameter(ext.GPU_DISJOINT_EXT); if (available && !disjoint) { var ret = { wasValid: wasValid, frag: fragString || sandbox.fragmentString, vert: vertString || sandbox.vertexString, timeElapsedMs: ext.getQueryObjectEXT(query, ext.QUERY_RESULT_EXT) / 1000000.0 }; finishTest(); callback(ret); } else { window.requestAnimationFrame(waitForTest); } }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
waitForTest
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function loadAllGlslCanvas() { var list = document.getElementsByClassName('glslCanvas'); if (list.length > 0) { window.glslCanvases = []; for (var i = 0; i < list.length; i++) { var sandbox = new GlslCanvas(list[i]); if (sandbox.isValid) { window.glslCanvases.push(sandbox); } } } }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
loadAllGlslCanvas
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
isES6ClassFn = function isES6ClassFn(value) { try { var fnStr = fnToStr.call(value); var singleStripped = fnStr.replace(/\/\/.*\n/g, ''); var multiStripped = singleStripped.replace(/\/\*[.\s\S]*\*\//g, ''); var spaceStripped = multiStripped.replace(/\n/mg, ' ').replace(/ {2}/g, ' '); return constructorRegex.test(spaceStripped); } catch (e) { return false; // not a function } }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
isES6ClassFn
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
tryFunctionObject = function tryFunctionObject(value) { try { if (isES6ClassFn(value)) { return false; } fnToStr.call(value); return true; } catch (e) { return false; } }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
tryFunctionObject
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function isFunction (fn) { var string = toString.call(fn) return string === '[object Function]' || (typeof fn === 'function' && string !== '[object RegExp]') || (typeof window !== 'undefined' && // IE8 and below (fn === window.setTimeout || fn === window.alert || fn === window.confirm || fn === window.prompt)) }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
isFunction
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
isArray = function(arg) { return Object.prototype.toString.call(arg) === '[object Array]'; }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
isArray
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function trim(str){ return str.replace(/^\s*|\s*$/g, ''); }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
trim
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function forEachArray(array, iterator) { for (var i = 0; i < array.length; i++) { iterator(array[i]) } }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
forEachArray
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function isEmpty(obj){ for(var i in obj){ if(obj.hasOwnProperty(i)) return false } return true }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
isEmpty
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT