code
stringlengths
10
343k
docstring
stringlengths
36
21.9k
func_name
stringlengths
1
3.35k
language
stringclasses
1 value
repo
stringlengths
7
58
path
stringlengths
4
131
url
stringlengths
44
195
license
stringclasses
5 values
_wait(time) { return new Promise(resolve => setTimeout(resolve, time)); }
Helper function for animation delays, called with `await`. @param {number} time - Timeout, in ms.
_wait ( time )
javascript
meshery/meshery
docs/v0.6/assets/js/terminal.js
https://github.com/meshery/meshery/blob/master/docs/v0.6/assets/js/terminal.js
Apache-2.0
lineDataToElements(lineData) { return lineData.map(line => { let div = document.createElement('div'); div.innerHTML = `<span ${this._attributes(line)}>${line.value || ''}</span>`; return div.firstElementChild; }); }
Converts line data objects into line elements. @param {Object[]} lineData - Dynamically loaded lines. @param {Object} line - Line data object. @returns {Element[]} - Array of line elements.
lineDataToElements ( lineData )
javascript
meshery/meshery
docs/v0.6/assets/js/terminal.js
https://github.com/meshery/meshery/blob/master/docs/v0.6/assets/js/terminal.js
Apache-2.0
_attributes(line) { let attrs = ''; for (let prop in line) { attrs += this.pfx; if (prop === 'type') { attrs += `="${line[prop]}" ` } else if (prop !== 'value') { attrs += `-${prop}="${line[prop]}" ` } } return attrs; }
Helper function for generating attributes string. @param {Object} line - Line data object. @returns {string} - String of attributes.
_attributes ( line )
javascript
meshery/meshery
docs/v0.6/assets/js/terminal.js
https://github.com/meshery/meshery/blob/master/docs/v0.6/assets/js/terminal.js
Apache-2.0
fetch: function(count) {},
Fetch more items from the data source. This should try to fetch at least count items but may fetch more as desired. Subsequent calls to fetch should fetch items following the last successful fetch. @param {number} count The minimum number of items to fetch for display. @return {Promise(Array<Object>)} Returns a promise which will be resolved with an array of items.
fetch ( count )
javascript
GoogleChromeLabs/ui-element-samples
infinite-scroller/scripts/infinite-scroll.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/infinite-scroller/scripts/infinite-scroll.js
Apache-2.0
createTombstone: function() {},
Create a tombstone element. All tombstone elements should be identical @return {Element} A tombstone element to be displayed when item data is not yet available for the scrolled position.
createTombstone ( )
javascript
GoogleChromeLabs/ui-element-samples
infinite-scroller/scripts/infinite-scroll.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/infinite-scroller/scripts/infinite-scroll.js
Apache-2.0
render: function(item, div) {},
Render an item, re-using the provided item div if passed in. @param {Object} item The item description from the array returned by fetch. @param {?Element} element If provided, this is a previously displayed element which should be recycled for the new item to display. @return {Element} The constructed element to be displayed in the scroller.
render ( item , div )
javascript
GoogleChromeLabs/ui-element-samples
infinite-scroller/scripts/infinite-scroll.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/infinite-scroller/scripts/infinite-scroll.js
Apache-2.0
scope.InfiniteScroller = function(scroller, source) { this.anchorItem = {index: 0, offset: 0}; this.firstAttachedItem_ = 0; this.lastAttachedItem_ = 0; this.anchorScrollTop = 0; this.tombstoneSize_ = 0; this.tombstoneWidth_ = 0; this.tombstones_ = []; this.scroller_ = scroller; this.source_ = source; this.items_ = []; this.loadedItems_ = 0; this.requestInProgress_ = false; this.scroller_.addEventListener('scroll', this.onScroll_.bind(this)); window.addEventListener('resize', this.onResize_.bind(this)); // Create an element to force the scroller to allow scrolling to a certain // point. this.scrollRunway_ = document.createElement('div'); // Internet explorer seems to require some text in this div in order to // ensure that it can be scrolled to. this.scrollRunway_.textContent = ' '; this.scrollRunwayEnd_ = 0; this.scrollRunway_.style.position = 'absolute'; this.scrollRunway_.style.height = '1px'; this.scrollRunway_.style.width = '1px'; this.scrollRunway_.style.transition = 'transform 0.2s'; this.scroller_.appendChild(this.scrollRunway_); this.onResize_(); }
Construct an infinite scroller. @param {Element} scroller The scrollable element to use as the infinite scroll region. @param {InfiniteScrollerSource} source A provider of the content to be displayed in the infinite scroll region.
scope.InfiniteScroller ( scroller , source )
javascript
GoogleChromeLabs/ui-element-samples
infinite-scroller/scripts/infinite-scroll.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/infinite-scroller/scripts/infinite-scroll.js
Apache-2.0
onResize_: function() { // TODO: If we already have tombstones attached to the document, it would // probably be more efficient to use one of them rather than create a new // one to measure. var tombstone = this.source_.createTombstone(); tombstone.style.position = 'absolute'; this.scroller_.appendChild(tombstone); tombstone.classList.remove('invisible'); this.tombstoneSize_ = tombstone.offsetHeight; this.tombstoneWidth_ = tombstone.offsetWidth; this.scroller_.removeChild(tombstone); // Reset the cached size of items in the scroller as they may no longer be // correct after the item content undergoes layout. for (var i = 0; i < this.items_.length; i++) { this.items_[i].height = this.items_[i].width = 0; } this.onScroll_(); },
Called when the browser window resizes to adapt to new scroller bounds and layout sizes of items within the scroller.
onResize_ ( )
javascript
GoogleChromeLabs/ui-element-samples
infinite-scroller/scripts/infinite-scroll.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/infinite-scroller/scripts/infinite-scroll.js
Apache-2.0
onScroll_: function() { var delta = this.scroller_.scrollTop - this.anchorScrollTop; // Special case, if we get to very top, always scroll to top. if (this.scroller_.scrollTop == 0) { this.anchorItem = {index: 0, offset: 0}; } else { this.anchorItem = this.calculateAnchoredItem(this.anchorItem, delta); } this.anchorScrollTop = this.scroller_.scrollTop; var lastScreenItem = this.calculateAnchoredItem(this.anchorItem, this.scroller_.offsetHeight); if (delta < 0) this.fill(this.anchorItem.index - RUNWAY_ITEMS, lastScreenItem.index + RUNWAY_ITEMS_OPPOSITE); else this.fill(this.anchorItem.index - RUNWAY_ITEMS_OPPOSITE, lastScreenItem.index + RUNWAY_ITEMS); },
Called when the scroller scrolls. This determines the newly anchored item and offset and then updates the visible elements, requesting more items from the source if we've scrolled past the end of the currently available content.
onScroll_ ( )
javascript
GoogleChromeLabs/ui-element-samples
infinite-scroller/scripts/infinite-scroll.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/infinite-scroller/scripts/infinite-scroll.js
Apache-2.0
calculateAnchoredItem: function(initialAnchor, delta) { if (delta == 0) return initialAnchor; delta += initialAnchor.offset; var i = initialAnchor.index; var tombstones = 0; if (delta < 0) { while (delta < 0 && i > 0 && this.items_[i - 1].height) { delta += this.items_[i - 1].height; i--; } tombstones = Math.max(-i, Math.ceil(Math.min(delta, 0) / this.tombstoneSize_)); } else { while (delta > 0 && i < this.items_.length && this.items_[i].height && this.items_[i].height < delta) { delta -= this.items_[i].height; i++; } if (i >= this.items_.length || !this.items_[i].height) tombstones = Math.floor(Math.max(delta, 0) / this.tombstoneSize_); } i += tombstones; delta -= tombstones * this.tombstoneSize_; return { index: i, offset: delta, }; },
Calculates the item that should be anchored after scrolling by delta from the initial anchored item. @param {{index: number, offset: number}} initialAnchor The initial position to scroll from before calculating the new anchor position. @param {number} delta The offset from the initial item to scroll by. @return {{index: number, offset: number}} Returns the new item and offset scroll should be anchored to.
calculateAnchoredItem ( initialAnchor , delta )
javascript
GoogleChromeLabs/ui-element-samples
infinite-scroller/scripts/infinite-scroll.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/infinite-scroller/scripts/infinite-scroll.js
Apache-2.0
fill: function(start, end) { this.firstAttachedItem_ = Math.max(0, start); this.lastAttachedItem_ = end; this.attachContent(); },
Sets the range of items which should be attached and attaches those items. @param {number} start The first item which should be attached. @param {number} end One past the last item which should be attached.
fill ( start , end )
javascript
GoogleChromeLabs/ui-element-samples
infinite-scroller/scripts/infinite-scroll.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/infinite-scroller/scripts/infinite-scroll.js
Apache-2.0
getTombstone: function() { var tombstone = this.tombstones_.pop(); if (tombstone) { tombstone.classList.remove('invisible'); tombstone.style.opacity = 1; tombstone.style.transform = ''; tombstone.style.transition = ''; return tombstone; } return this.source_.createTombstone(); },
Creates or returns an existing tombstone ready to be reused. @return {Element} A tombstone element ready to be used.
getTombstone ( )
javascript
GoogleChromeLabs/ui-element-samples
infinite-scroller/scripts/infinite-scroll.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/infinite-scroller/scripts/infinite-scroll.js
Apache-2.0
attachContent: function() { // Collect nodes which will no longer be rendered for reuse. // TODO: Limit this based on the change in visible items rather than looping // over all items. var i; var unusedNodes = []; for (i = 0; i < this.items_.length; i++) { // Skip the items which should be visible. if (i == this.firstAttachedItem_) { i = this.lastAttachedItem_ - 1; continue; } if (this.items_[i].node) { if (this.items_[i].node.classList.contains('tombstone')) { this.tombstones_.push(this.items_[i].node); this.tombstones_[this.tombstones_.length - 1].classList.add('invisible'); } else { unusedNodes.push(this.items_[i].node); } } this.items_[i].node = null; } var tombstoneAnimations = {}; // Create DOM nodes. for (i = this.firstAttachedItem_; i < this.lastAttachedItem_; i++) { while (this.items_.length <= i) this.addItem_(); if (this.items_[i].node) { // if it's a tombstone but we have data, replace it. if (this.items_[i].node.classList.contains('tombstone') && this.items_[i].data) { // TODO: Probably best to move items on top of tombstones and fade them in instead. if (ANIMATION_DURATION_MS) { this.items_[i].node.style.zIndex = 1; tombstoneAnimations[i] = [this.items_[i].node, this.items_[i].top - this.anchorScrollTop]; } else { this.items_[i].node.classList.add('invisible'); this.tombstones_.push(this.items_[i].node); } this.items_[i].node = null; } else { continue; } } var node = this.items_[i].data ? this.source_.render(this.items_[i].data, unusedNodes.pop()) : this.getTombstone(); // Maybe don't do this if it's already attached? node.style.position = 'absolute'; this.items_[i].top = -1; this.scroller_.appendChild(node); this.items_[i].node = node; } // Remove all unused nodes while (unusedNodes.length) { this.scroller_.removeChild(unusedNodes.pop()); } // Get the height of all nodes which haven't been measured yet. for (i = this.firstAttachedItem_; i < this.lastAttachedItem_; i++) { // Only cache the height if we have the real contents, not a placeholder. if (this.items_[i].data && !this.items_[i].height) { this.items_[i].height = this.items_[i].node.offsetHeight; this.items_[i].width = this.items_[i].node.offsetWidth; } } // Fix scroll position in case we have realized the heights of elements // that we didn't used to know. // TODO: We should only need to do this when a height of an item becomes // known above. this.anchorScrollTop = 0; for (i = 0; i < this.anchorItem.index; i++) { this.anchorScrollTop += this.items_[i].height || this.tombstoneSize_; } this.anchorScrollTop += this.anchorItem.offset; // Position all nodes. var curPos = this.anchorScrollTop - this.anchorItem.offset; i = this.anchorItem.index; while (i > this.firstAttachedItem_) { curPos -= this.items_[i - 1].height || this.tombstoneSize_; i--; } while (i < this.firstAttachedItem_) { curPos += this.items_[i].height || this.tombstoneSize_; i++; } // Set up initial positions for animations. for (var i in tombstoneAnimations) { var anim = tombstoneAnimations[i]; this.items_[i].node.style.transform = 'translateY(' + (this.anchorScrollTop + anim[1]) + 'px) scale(' + (this.tombstoneWidth_ / this.items_[i].width) + ', ' + (this.tombstoneSize_ / this.items_[i].height) + ')'; // Call offsetTop on the nodes to be animated to force them to apply current transforms. this.items_[i].node.offsetTop; anim[0].offsetTop; this.items_[i].node.style.transition = 'transform ' + ANIMATION_DURATION_MS + 'ms'; } for (i = this.firstAttachedItem_; i < this.lastAttachedItem_; i++) { var anim = tombstoneAnimations[i]; if (anim) { anim[0].style.transition = 'transform ' + ANIMATION_DURATION_MS + 'ms, opacity ' + ANIMATION_DURATION_MS + 'ms'; anim[0].style.transform = 'translateY(' + curPos + 'px) scale(' + (this.items_[i].width / this.tombstoneWidth_) + ', ' + (this.items_[i].height / this.tombstoneSize_) + ')'; anim[0].style.opacity = 0; } if (curPos != this.items_[i].top) { if (!anim) this.items_[i].node.style.transition = ''; this.items_[i].node.style.transform = 'translateY(' + curPos + 'px)'; } this.items_[i].top = curPos; curPos += this.items_[i].height || this.tombstoneSize_; } this.scrollRunwayEnd_ = Math.max(this.scrollRunwayEnd_, curPos + SCROLL_RUNWAY) this.scrollRunway_.style.transform = 'translate(0, ' + this.scrollRunwayEnd_ + 'px)'; this.scroller_.scrollTop = this.anchorScrollTop; if (ANIMATION_DURATION_MS) { // TODO: Should probably use transition end, but there are a lot of animations we could be listening to. setTimeout(function() { for (var i in tombstoneAnimations) { var anim = tombstoneAnimations[i]; anim[0].classList.add('invisible'); this.tombstones_.push(anim[0]); // Tombstone can be recycled now. } }.bind(this), ANIMATION_DURATION_MS) } this.maybeRequestContent(); },
Attaches content to the scroller and updates the scroll position if necessary.
attachContent ( )
javascript
GoogleChromeLabs/ui-element-samples
infinite-scroller/scripts/infinite-scroll.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/infinite-scroller/scripts/infinite-scroll.js
Apache-2.0
maybeRequestContent: function() { // Don't issue another request if one is already in progress as we don't // know where to start the next request yet. if (this.requestInProgress_) return; var itemsNeeded = this.lastAttachedItem_ - this.loadedItems_; if (itemsNeeded <= 0) return; this.requestInProgress_ = true; this.source_.fetch(itemsNeeded).then(this.addContent.bind(this)); },
Requests additional content if we don't have enough currently.
maybeRequestContent ( )
javascript
GoogleChromeLabs/ui-element-samples
infinite-scroller/scripts/infinite-scroll.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/infinite-scroller/scripts/infinite-scroll.js
Apache-2.0
addContent: function(items) { this.requestInProgress_ = false; for (var i = 0; i < items.length; i++) { if (this.items_.length <= this.loadedItems_) this.addItem_(); this.items_[this.loadedItems_++].data = items[i]; } this.attachContent(); }
Adds the given array of items to the items list and then calls attachContent to update the displayed content. @param {Array<Object>} items The array of items to be added to the infinite scroller list.
addContent ( items )
javascript
GoogleChromeLabs/ui-element-samples
infinite-scroller/scripts/infinite-scroll.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/infinite-scroller/scripts/infinite-scroll.js
Apache-2.0
(function(scope) { // Number of items to instantiate beyond current view in the scroll direction. var RUNWAY_ITEMS = 50; // Number of items to instantiate beyond current view in the opposite direction. var RUNWAY_ITEMS_OPPOSITE = 10; // The number of pixels of additional length to allow scrolling to. var SCROLL_RUNWAY = 2000; // The animation interval (in ms) for fading in content from tombstones. var ANIMATION_DURATION_MS = 200; scope.InfiniteScrollerSource = function() { } scope.InfiniteScrollerSource.prototype = { /** * Fetch more items from the data source. This should try to fetch at least * count items but may fetch more as desired. Subsequent calls to fetch should * fetch items following the last successful fetch. * @param {number} count The minimum number of items to fetch for display. * @return {Promise(Array<Object>)} Returns a promise which will be resolved * with an array of items. */ fetch: function(count) {}, /** * Create a tombstone element. All tombstone elements should be identical * @return {Element} A tombstone element to be displayed when item data is not * yet available for the scrolled position. */ createTombstone: function() {}, /** * Render an item, re-using the provided item div if passed in. * @param {Object} item The item description from the array returned by fetch. * @param {?Element} element If provided, this is a previously displayed * element which should be recycled for the new item to display. * @return {Element} The constructed element to be displayed in the scroller. */ render: function(item, div) {}, }; /** * Construct an infinite scroller. * @param {Element} scroller The scrollable element to use as the infinite * scroll region. * @param {InfiniteScrollerSource} source A provider of the content to be * displayed in the infinite scroll region. */ scope.InfiniteScroller = function(scroller, source) { this.anchorItem = {index: 0, offset: 0}; this.firstAttachedItem_ = 0; this.lastAttachedItem_ = 0; this.anchorScrollTop = 0; this.tombstoneSize_ = 0; this.tombstoneWidth_ = 0; this.tombstones_ = []; this.scroller_ = scroller; this.source_ = source; this.items_ = []; this.loadedItems_ = 0; this.requestInProgress_ = false; this.scroller_.addEventListener('scroll', this.onScroll_.bind(this)); window.addEventListener('resize', this.onResize_.bind(this)); // Create an element to force the scroller to allow scrolling to a certain // point. this.scrollRunway_ = document.createElement('div'); // Internet explorer seems to require some text in this div in order to // ensure that it can be scrolled to. this.scrollRunway_.textContent = ' '; this.scrollRunwayEnd_ = 0; this.scrollRunway_.style.position = 'absolute'; this.scrollRunway_.style.height = '1px'; this.scrollRunway_.style.width = '1px'; this.scrollRunway_.style.transition = 'transform 0.2s'; this.scroller_.appendChild(this.scrollRunway_); this.onResize_(); } scope.InfiniteScroller.prototype = { /** * Called when the browser window resizes to adapt to new scroller bounds and * layout sizes of items within the scroller. */ onResize_: function() { // TODO: If we already have tombstones attached to the document, it would // probably be more efficient to use one of them rather than create a new // one to measure. var tombstone = this.source_.createTombstone(); tombstone.style.position = 'absolute'; this.scroller_.appendChild(tombstone); tombstone.classList.remove('invisible'); this.tombstoneSize_ = tombstone.offsetHeight; this.tombstoneWidth_ = tombstone.offsetWidth; this.scroller_.removeChild(tombstone); // Reset the cached size of items in the scroller as they may no longer be // correct after the item content undergoes layout. for (var i = 0; i < this.items_.length; i++) { this.items_[i].height = this.items_[i].width = 0; } this.onScroll_(); }, /** * Called when the scroller scrolls. This determines the newly anchored item * and offset and then updates the visible elements, requesting more items * from the source if we've scrolled past the end of the currently available * content. */ onScroll_: function() { var delta = this.scroller_.scrollTop - this.anchorScrollTop; // Special case, if we get to very top, always scroll to top. if (this.scroller_.scrollTop == 0) { this.anchorItem = {index: 0, offset: 0}; } else { this.anchorItem = this.calculateAnchoredItem(this.anchorItem, delta); } this.anchorScrollTop = this.scroller_.scrollTop; var lastScreenItem = this.calculateAnchoredItem(this.anchorItem, this.scroller_.offsetHeight); if (delta < 0) this.fill(this.anchorItem.index - RUNWAY_ITEMS, lastScreenItem.index + RUNWAY_ITEMS_OPPOSITE); else this.fill(this.anchorItem.index - RUNWAY_ITEMS_OPPOSITE, lastScreenItem.index + RUNWAY_ITEMS); }, /** * Calculates the item that should be anchored after scrolling by delta from * the initial anchored item. * @param {{index: number, offset: number}} initialAnchor The initial position * to scroll from before calculating the new anchor position. * @param {number} delta The offset from the initial item to scroll by. * @return {{index: number, offset: number}} Returns the new item and offset * scroll should be anchored to. */ calculateAnchoredItem: function(initialAnchor, delta) { if (delta == 0) return initialAnchor; delta += initialAnchor.offset; var i = initialAnchor.index; var tombstones = 0; if (delta < 0) { while (delta < 0 && i > 0 && this.items_[i - 1].height) { delta += this.items_[i - 1].height; i--; } tombstones = Math.max(-i, Math.ceil(Math.min(delta, 0) / this.tombstoneSize_)); } else { while (delta > 0 && i < this.items_.length && this.items_[i].height && this.items_[i].height < delta) { delta -= this.items_[i].height; i++; } if (i >= this.items_.length || !this.items_[i].height) tombstones = Math.floor(Math.max(delta, 0) / this.tombstoneSize_); } i += tombstones; delta -= tombstones * this.tombstoneSize_; return { index: i, offset: delta, }; }, /** * Sets the range of items which should be attached and attaches those items. * @param {number} start The first item which should be attached. * @param {number} end One past the last item which should be attached. */ fill: function(start, end) { this.firstAttachedItem_ = Math.max(0, start); this.lastAttachedItem_ = end; this.attachContent(); }, /** * Creates or returns an existing tombstone ready to be reused. * @return {Element} A tombstone element ready to be used. */ getTombstone: function() { var tombstone = this.tombstones_.pop(); if (tombstone) { tombstone.classList.remove('invisible'); tombstone.style.opacity = 1; tombstone.style.transform = ''; tombstone.style.transition = ''; return tombstone; } return this.source_.createTombstone(); }, /** * Attaches content to the scroller and updates the scroll position if * necessary. */ attachContent: function() { // Collect nodes which will no longer be rendered for reuse. // TODO: Limit this based on the change in visible items rather than looping // over all items. var i; var unusedNodes = []; for (i = 0; i < this.items_.length; i++) { // Skip the items which should be visible. if (i == this.firstAttachedItem_) { i = this.lastAttachedItem_ - 1; continue; } if (this.items_[i].node) { if (this.items_[i].node.classList.contains('tombstone')) { this.tombstones_.push(this.items_[i].node); this.tombstones_[this.tombstones_.length - 1].classList.add('invisible'); } else { unusedNodes.push(this.items_[i].node); } } this.items_[i].node = null; } var tombstoneAnimations = {}; // Create DOM nodes. for (i = this.firstAttachedItem_; i < this.lastAttachedItem_; i++) { while (this.items_.length <= i) this.addItem_(); if (this.items_[i].node) { // if it's a tombstone but we have data, replace it. if (this.items_[i].node.classList.contains('tombstone') && this.items_[i].data) { // TODO: Probably best to move items on top of tombstones and fade them in instead. if (ANIMATION_DURATION_MS) { this.items_[i].node.style.zIndex = 1; tombstoneAnimations[i] = [this.items_[i].node, this.items_[i].top - this.anchorScrollTop]; } else { this.items_[i].node.classList.add('invisible'); this.tombstones_.push(this.items_[i].node); } this.items_[i].node = null; } else { continue; } } var node = this.items_[i].data ? this.source_.render(this.items_[i].data, unusedNodes.pop()) : this.getTombstone(); // Maybe don't do this if it's already attached? node.style.position = 'absolute'; this.items_[i].top = -1; this.scroller_.appendChild(node); this.items_[i].node = node; } // Remove all unused nodes while (unusedNodes.length) { this.scroller_.removeChild(unusedNodes.pop()); } // Get the height of all nodes which haven't been measured yet. for (i = this.firstAttachedItem_; i < this.lastAttachedItem_; i++) { // Only cache the height if we have the real contents, not a placeholder. if (this.items_[i].data && !this.items_[i].height) { this.items_[i].height = this.items_[i].node.offsetHeight; this.items_[i].width = this.items_[i].node.offsetWidth; } } // Fix scroll position in case we have realized the heights of elements // that we didn't used to know. // TODO: We should only need to do this when a height of an item becomes // known above. this.anchorScrollTop = 0; for (i = 0; i < this.anchorItem.index; i++) { this.anchorScrollTop += this.items_[i].height || this.tombstoneSize_; } this.anchorScrollTop += this.anchorItem.offset; // Position all nodes. var curPos = this.anchorScrollTop - this.anchorItem.offset; i = this.anchorItem.index; while (i > this.firstAttachedItem_) { curPos -= this.items_[i - 1].height || this.tombstoneSize_; i--; } while (i < this.firstAttachedItem_) { curPos += this.items_[i].height || this.tombstoneSize_; i++; } // Set up initial positions for animations. for (var i in tombstoneAnimations) { var anim = tombstoneAnimations[i]; this.items_[i].node.style.transform = 'translateY(' + (this.anchorScrollTop + anim[1]) + 'px) scale(' + (this.tombstoneWidth_ / this.items_[i].width) + ', ' + (this.tombstoneSize_ / this.items_[i].height) + ')'; // Call offsetTop on the nodes to be animated to force them to apply current transforms. this.items_[i].node.offsetTop; anim[0].offsetTop; this.items_[i].node.style.transition = 'transform ' + ANIMATION_DURATION_MS + 'ms'; } for (i = this.firstAttachedItem_; i < this.lastAttachedItem_; i++) { var anim = tombstoneAnimations[i]; if (anim) { anim[0].style.transition = 'transform ' + ANIMATION_DURATION_MS + 'ms, opacity ' + ANIMATION_DURATION_MS + 'ms'; anim[0].style.transform = 'translateY(' + curPos + 'px) scale(' + (this.items_[i].width / this.tombstoneWidth_) + ', ' + (this.items_[i].height / this.tombstoneSize_) + ')'; anim[0].style.opacity = 0; } if (curPos != this.items_[i].top) { if (!anim) this.items_[i].node.style.transition = ''; this.items_[i].node.style.transform = 'translateY(' + curPos + 'px)'; } this.items_[i].top = curPos; curPos += this.items_[i].height || this.tombstoneSize_; } this.scrollRunwayEnd_ = Math.max(this.scrollRunwayEnd_, curPos + SCROLL_RUNWAY) this.scrollRunway_.style.transform = 'translate(0, ' + this.scrollRunwayEnd_ + 'px)'; this.scroller_.scrollTop = this.anchorScrollTop; if (ANIMATION_DURATION_MS) { // TODO: Should probably use transition end, but there are a lot of animations we could be listening to. setTimeout(function() { for (var i in tombstoneAnimations) { var anim = tombstoneAnimations[i]; anim[0].classList.add('invisible'); this.tombstones_.push(anim[0]); // Tombstone can be recycled now. } }.bind(this), ANIMATION_DURATION_MS) } this.maybeRequestContent(); }, /** * Requests additional content if we don't have enough currently. */ maybeRequestContent: function() { // Don't issue another request if one is already in progress as we don't // know where to start the next request yet. if (this.requestInProgress_) return; var itemsNeeded = this.lastAttachedItem_ - this.loadedItems_; if (itemsNeeded <= 0) return; this.requestInProgress_ = true; this.source_.fetch(itemsNeeded).then(this.addContent.bind(this)); }, /** * Adds an item to the items list. */ addItem_: function() { this.items_.push({ 'data': null, 'node': null, 'height': 0, 'width': 0, 'top': 0, }) }, /** * Adds the given array of items to the items list and then calls * attachContent to update the displayed content. * @param {Array<Object>} items The array of items to be added to the infinite * scroller list. */ addContent: function(items) { this.requestInProgress_ = false; for (var i = 0; i < items.length; i++) { if (this.items_.length <= this.loadedItems_) this.addItem_(); this.items_[this.loadedItems_++].data = items[i]; } this.attachContent(); } } })(self);
Copyright 2015 Google Inc. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
(anonymous) ( scope )
javascript
GoogleChromeLabs/ui-element-samples
infinite-scroller/scripts/infinite-scroll.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/infinite-scroller/scripts/infinite-scroll.js
Apache-2.0
addEventListener('message', (d) => { const imageData = d.data; const w = imageData.width; const h = imageData.height; const data = imageData.data; // Iterate pixel rows and columns to change red color of each. for (let x = 0; x < w; x++) { for (let y = 0; y < h; y++) { let index = (x + (y * w)) * 4; data[index] = data[index] * 1.2; } } postMessage(imageData, [imageData.data.buffer]) });
Handles incoming messages in the web worker. In this case: increases each pixel's red color by 20%. @param {!Object} d Incoming data.
(anonymous)
javascript
GoogleChromeLabs/ui-element-samples
web-workers/worker.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/web-workers/worker.js
Apache-2.0
function initializeParallax(clip) { var parallax = clip.querySelectorAll('*[parallax]'); var parallaxDetails = []; var sticky = false; // Edge requires a transform on the document body and a fixed position element // in order for it to properly render the parallax effect as you scroll. // See https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/5084491/ if (getComputedStyle(document.body).transform == 'none') document.body.style.transform = 'translateZ(0)'; var fixedPos = document.createElement('div'); fixedPos.style.position = 'fixed'; fixedPos.style.top = '0'; fixedPos.style.width = '1px'; fixedPos.style.height = '1px'; fixedPos.style.zIndex = 1; document.body.insertBefore(fixedPos, document.body.firstChild); for (var i = 0; i < parallax.length; i++) { var elem = parallax[i]; var container = elem.parentNode; if (getComputedStyle(container).overflow != 'visible') { console.error('Need non-scrollable container to apply perspective for', elem); continue; } if (clip && container.parentNode != clip) { console.warn('Currently we only track a single overflow clip, but elements from multiple clips found.', elem); } var clip = container.parentNode; if (getComputedStyle(clip).overflow == 'visible') { console.error('Parent of sticky container should be scrollable element', elem); } // TODO(flackr): optimize to not redo this for the same clip/container. var perspectiveElement; if (sticky || getComputedStyle(clip).webkitOverflowScrolling) { sticky = true; perspectiveElement = container; } else { perspectiveElement = clip; container.style.transformStyle = 'preserve-3d'; } perspectiveElement.style.perspectiveOrigin = 'bottom right'; perspectiveElement.style.perspective = '1px'; if (sticky) elem.style.position = '-webkit-sticky'; if (sticky) elem.style.top = '0'; elem.style.transformOrigin = 'bottom right'; // Find the previous and next elements to parallax between. var previousCover = parallax[i].previousElementSibling; while (previousCover && previousCover.hasAttribute('parallax')) previousCover = previousCover.previousElementSibling; var nextCover = parallax[i].nextElementSibling; while (nextCover && !nextCover.hasAttribute('parallax-cover')) nextCover = nextCover.nextElementSibling; parallaxDetails.push({'node': parallax[i], 'top': parallax[i].offsetTop, 'sticky': !!sticky, 'nextCover': nextCover, 'previousCover': previousCover}); } // Add a scroll listener to hide perspective elements when they should no // longer be visible. clip.addEventListener('scroll', function() { for (var i = 0; i < parallaxDetails.length; i++) { var container = parallaxDetails[i].node.parentNode; var previousCover = parallaxDetails[i].previousCover; var nextCover = parallaxDetails[i].nextCover; var parallaxStart = previousCover ? (previousCover.offsetTop + previousCover.offsetHeight) : 0; var parallaxEnd = nextCover ? nextCover.offsetTop : container.offsetHeight; var threshold = 200; var visible = parallaxStart - threshold - clip.clientHeight < clip.scrollTop && parallaxEnd + threshold > clip.scrollTop; // FIXME: Repainting the images while scrolling can cause jank. // For now, keep them all. // var display = visible ? 'block' : 'none' var display = 'block'; if (parallaxDetails[i].node.style.display != display) parallaxDetails[i].node.style.display = display; } }); window.addEventListener('resize', onResize.bind(null, parallaxDetails)); onResize(parallaxDetails); for (var i = 0; i < parallax.length; i++) { parallax[i].parentNode.insertBefore(parallax[i], parallax[i].parentNode.firstChild); } }
Copyright 2016 Google Inc. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
initializeParallax ( clip )
javascript
GoogleChromeLabs/ui-element-samples
parallax/scripts/parallax.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/parallax/scripts/parallax.js
Apache-2.0
constructor(rootElement, inertManager) { /** @type {InertManager} */ this._inertManager = inertManager; /** @type {Element} */ this._rootElement = rootElement; /** * @type {Set<Node>} * All managed focusable nodes in this InertRoot's subtree. */ this._managedNodes = new Set([]); // Make the subtree hidden from assistive technology this._rootElement.setAttribute('aria-hidden', 'true'); // Make all focusable elements in the subtree unfocusable and add them to _managedNodes this._makeSubtreeUnfocusable(this._rootElement); // Watch for: // - any additions in the subtree: make them unfocusable too // - any removals from the subtree: remove them from this inert root's managed nodes // - attribute changes: if `tabindex` is added, or removed from an intrinsically focusable element, // make that node a managed node. this._observer = new MutationObserver(this._onMutation.bind(this)); this._observer.observe(this._rootElement, { attributes: true, childList: true, subtree: true }); }
@param {Element} rootElement The Element at the root of the inert subtree. @param {InertManager} inertManager The global singleton InertManager object.
constructor ( rootElement , inertManager )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
destructor() { this._observer.disconnect(); this._observer = null; if (this._rootElement) this._rootElement.removeAttribute('aria-hidden'); this._rootElement = null; for (let inertNode of this._managedNodes) this._unmanageNode(inertNode.node); this._managedNodes = null; this._inertManager = null; }
Call this whenever this object is about to become obsolete. This unwinds all of the state stored in this object and updates the state of all of the managed nodes.
destructor ( )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
get managedNodes() { return new Set(this._managedNodes); }
@return {Set<InertNode>} A copy of this InertRoot's managed nodes set.
managedNodes ( )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
_manageNode(node) { const inertNode = this._inertManager.register(node, this); this._managedNodes.add(inertNode); }
Register the given node with this InertRoot and with InertManager. @param {Node} node
_manageNode ( node )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
_unmanageNode(node) { const inertNode = this._inertManager.deregister(node, this); if (inertNode) this._managedNodes.delete(inertNode); }
Unregister the given node with this InertRoot and with InertManager. @param {Node} node
_unmanageNode ( node )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
_unmanageSubtree(startNode) { composedTreeWalk(startNode, (node) => { this._unmanageNode(node); }); }
Unregister the entire subtree starting at `startNode`. @param {Node} startNode
_unmanageSubtree ( startNode )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
_adoptInertRoot(node) { let inertSubroot = this._inertManager.getInertRoot(node); // During initialisation this inert root may not have been registered yet, // so register it now if need be. if (!inertSubroot) { this._inertManager.setInert(node, true); inertSubroot = this._inertManager.getInertRoot(node); } for (let savedInertNode of inertSubroot.managedNodes) this._manageNode(savedInertNode.node); }
If a descendant node is found with an `inert` attribute, adopt its managed nodes. @param {Node} node
_adoptInertRoot ( node )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
_onMutation(records, self) { for (let record of records) { const target = record.target; if (record.type === 'childList') { // Manage added nodes for (let node of Array.from(record.addedNodes)) this._makeSubtreeUnfocusable(node); // Un-manage removed nodes for (let node of Array.from(record.removedNodes)) this._unmanageSubtree(node); } else if (record.type === 'attributes') { if (record.attributeName === 'tabindex') { // Re-initialise inert node if tabindex changes this._manageNode(target); } else if (target !== this._rootElement && record.attributeName === 'inert' && target.hasAttribute('inert')) { // If a new inert root is added, adopt its managed nodes and make sure it knows about the // already managed nodes from this inert subroot. this._adoptInertRoot(target); const inertSubroot = this._inertManager.getInertRoot(target); for (let managedNode of this._managedNodes) { if (target.contains(managedNode.node)) inertSubroot._manageNode(managedNode.node); } } } } }
Callback used when mutation observer detects subtree additions, removals, or attribute changes. @param {MutationRecord} records @param {MutationObserver} self
_onMutation ( records , self )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
constructor(node, inertRoot) { /** @type {Node} */ this._node = node; /** @type {boolean} */ this._overrodeFocusMethod = false; /** * @type {Set<InertRoot>} The set of descendant inert roots. * If and only if this set becomes empty, this node is no longer inert. */ this._inertRoots = new Set([inertRoot]); /** @type {boolean} */ this._destroyed = false; // Save any prior tabindex info and make this node untabbable this.ensureUntabbable(); }
@param {Node} node A focusable element to be made inert. @param {InertRoot} inertRoot The inert root element associated with this inert node.
constructor ( node , inertRoot )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
destructor() { this._throwIfDestroyed(); if (this._node) { if (this.hasSavedTabIndex) this._node.setAttribute('tabindex', this.savedTabIndex); else this._node.removeAttribute('tabindex'); // Use `delete` to restore native focus method. if (this._overrodeFocusMethod) delete this._node.focus; } this._node = null; this._inertRoots = null; this._destroyed = true; }
Call this whenever this object is about to become obsolete. This makes the managed node focusable again and deletes all of the previously stored state.
destructor ( )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
get destroyed() { return this._destroyed; }
@type {boolean} Whether this object is obsolete because the managed node is no longer inert. If the object has been destroyed, any attempt to access it will cause an exception.
destroyed ( )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
addInertRoot(inertRoot) { this._throwIfDestroyed(); this._inertRoots.add(inertRoot); }
Add another inert root to this inert node's set of managing inert roots. @param {InertRoot} inertRoot
addInertRoot ( inertRoot )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
removeInertRoot(inertRoot) { this._throwIfDestroyed(); this._inertRoots.delete(inertRoot); if (this._inertRoots.size === 0) this.destructor(); }
Remove the given inert root from this inert node's set of managing inert roots. If the set of managing inert roots becomes empty, this node is no longer inert, so the object should be destroyed. @param {InertRoot} inertRoot
removeInertRoot ( inertRoot )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
setInert(root, inert) { if (inert) { if (this._inertRoots.has(root)) // element is already inert return; const inertRoot = new InertRoot(root, this); root.setAttribute('inert', ''); this._inertRoots.set(root, inertRoot); // If not contained in the document, it must be in a shadowRoot. // Ensure inert styles are added there. if (!this._document.body.contains(root)) { let parent = root.parentNode; while (parent) { if (parent.nodeType === 11) { addInertStyle(parent); } parent = parent.parentNode; } } } else { if (!this._inertRoots.has(root)) // element is already non-inert return; const inertRoot = this._inertRoots.get(root); inertRoot.destructor(); this._inertRoots.delete(root); root.removeAttribute('inert'); } }
Set whether the given element should be an inert root or not. @param {Element} root @param {boolean} inert
setInert ( root , inert )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
getInertRoot(element) { return this._inertRoots.get(element); }
Get the InertRoot object corresponding to the given inert root element, if any. @param {Element} element @return {InertRoot?}
getInertRoot ( element )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
register(node, inertRoot) { let inertNode = this._managedNodes.get(node); if (inertNode !== undefined) { // node was already in an inert subtree inertNode.addInertRoot(inertRoot); // Update saved tabindex value if necessary inertNode.ensureUntabbable(); } else { inertNode = new InertNode(node, inertRoot); } this._managedNodes.set(node, inertNode); return inertNode; }
Register the given InertRoot as managing the given node. In the case where the node has a previously existing inert root, this inert root will be added to its set of inert roots. @param {Node} node @param {InertRoot} inertRoot @return {InertNode} inertNode
register ( node , inertRoot )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
deregister(node, inertRoot) { const inertNode = this._managedNodes.get(node); if (!inertNode) return null; inertNode.removeInertRoot(inertRoot); if (inertNode.destroyed) this._managedNodes.delete(node); return inertNode; }
De-register the given InertRoot as managing the given inert node. Removes the inert root from the InertNode's set of managing inert roots, and remove the inert node from the InertManager's set of managed nodes if it is destroyed. If the node is not currently managed, this is essentially a no-op. @param {Node} node @param {InertRoot} inertRoot @return {InertNode?} The potentially destroyed InertNode associated with this node, if any.
deregister ( node , inertRoot )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
_onDocumentLoaded() { // Find all inert roots in document and make them actually inert. const inertElements = Array.from(this._document.querySelectorAll('[inert]')); for (let inertElement of inertElements) this.setInert(inertElement, true); // Comment this out to use programmatic API only. this._observer.observe(this._document.body, { attributes: true, subtree: true, childList: true }); }
Callback used when document has finished loading.
_onDocumentLoaded ( )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
_watchForInert(records, self) { for (let record of records) { switch (record.type) { case 'childList': for (let node of Array.from(record.addedNodes)) { if (node.nodeType !== Node.ELEMENT_NODE) continue; const inertElements = Array.from(node.querySelectorAll('[inert]')); if (node.matches('[inert]')) inertElements.unshift(node); for (let inertElement of inertElements) this.setInert(inertElement, true); } break; case 'attributes': if (record.attributeName !== 'inert') continue; const target = record.target; const inert = target.hasAttribute('inert'); this.setInert(target, inert); break; } } } }
Callback used when mutation observer detects attribute changes. @param {MutationRecord} records @param {MutationObserver} self
_watchForInert ( records , self )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
function composedTreeWalk(node, callback, shadowRootAncestor) { if (node.nodeType == Node.ELEMENT_NODE) { const element = /** @type {Element} */ (node); if (callback) callback(element) // Descend into node: // If it has a ShadowRoot, ignore all child elements - these will be picked // up by the <content> or <shadow> elements. Descend straight into the // ShadowRoot. const shadowRoot = element.shadowRoot || element.webkitShadowRoot; if (shadowRoot) { composedTreeWalk(shadowRoot, callback, shadowRoot); return; } // If it is a <content> element, descend into distributed elements - these // are elements from outside the shadow root which are rendered inside the // shadow DOM. if (element.localName == 'content') { const content = /** @type {HTMLContentElement} */ (element); // Verifies if ShadowDom v0 is supported. const distributedNodes = content.getDistributedNodes ? content.getDistributedNodes() : []; for (let i = 0; i < distributedNodes.length; i++) { composedTreeWalk(distributedNodes[i], callback, shadowRootAncestor); } return; } // If it is a <slot> element, descend into assigned nodes - these // are elements from outside the shadow root which are rendered inside the // shadow DOM. if (element.localName == 'slot') { const slot = /** @type {HTMLSlotElement} */ (element); // Verify if ShadowDom v1 is supported. const distributedNodes = slot.assignedNodes ? slot.assignedNodes({ flatten: true }) : []; for (let i = 0; i < distributedNodes.length; i++) { composedTreeWalk(distributedNodes[i], callback, shadowRootAncestor); } return; } } // If it is neither the parent of a ShadowRoot, a <content> element, a <slot> // element, nor a <shadow> element recurse normally. let child = node.firstChild; while (child != null) { composedTreeWalk(child, callback, shadowRootAncestor); child = child.nextSibling; } }
Recursively walk the composed tree from |node|. @param {Node} node @param {(function (Element))=} callback Callback to be called for each element traversed, before descending into child nodes. @param {ShadowRoot=} shadowRootAncestor The nearest ShadowRoot ancestor, if any.
composedTreeWalk ( node , callback , shadowRootAncestor )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
function addInertStyle(node) { if (node.querySelector('style#inert-style')) { return; } const style = document.createElement('style'); style.setAttribute('id', 'inert-style'); style.textContent = "\n"+ "[inert] {\n" + " pointer-events: none;\n" + " cursor: default;\n" + "}\n" + "\n" + "[inert], [inert] * {\n" + " user-select: none;\n" + " -webkit-user-select: none;\n" + " -moz-user-select: none;\n" + " -ms-user-select: none;\n" + "}\n"; node.appendChild(style); }
Adds a style element to the node containing the inert specific styles @param {Node} node
addInertStyle ( node )
javascript
GoogleChromeLabs/ui-element-samples
3d-card-flip/inert.js
https://github.com/GoogleChromeLabs/ui-element-samples/blob/master/3d-card-flip/inert.js
Apache-2.0
jasmine.bindOriginal_ = function(base, name) { var original = base[name]; if (original.apply) { return function() { return original.apply(base, arguments); }; } else { // IE support return jasmine.getGlobal()[name]; } };
Allows for bound functions to be compared. Internal use only. @ignore @private @param base {Object} bound 'this' for the function @param name {Function} function to find
jasmine.bindOriginal_ ( base , name )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.getEnv = function() { var env = jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env(); return env; };
Getter for the Jasmine environment. Ensures one gets created
jasmine.getEnv ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.isArray_ = function(value) { return jasmine.isA_("Array", value); };
@ignore @private @param value @returns {Boolean}
jasmine.isArray_ ( value )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.isA_ = function(typeName, value) { return Object.prototype.toString.apply(value) === '[object ' + typeName + ']'; };
@ignore @private @param {String} typeName @param value @returns {Boolean}
jasmine.isA_ ( typeName , value )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.pp = function(value) { var stringPrettyPrinter = new jasmine.StringPrettyPrinter(); stringPrettyPrinter.format(value); return stringPrettyPrinter.string; };
Pretty printer for expecations. Takes any object and turns it into a human-readable string. @param value {Object} an object to be outputted @returns {String}
jasmine.pp ( value )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.isDomNode = function(obj) { return obj.nodeType > 0; };
Returns true if the object is a DOM Node. @param {Object} obj object to check @returns {Boolean}
jasmine.isDomNode ( obj )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.any = function(clazz) { return new jasmine.Matchers.Any(clazz); };
Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter. @example // don't care about which function is passed in, as long as it's a function expect(mySpy).toHaveBeenCalledWith(jasmine.any(Function)); @param {Class} clazz @returns matchable object of the type clazz
jasmine.any ( clazz )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.objectContaining = function (sample) { return new jasmine.Matchers.ObjectContaining(sample); };
Returns a matchable subset of a JSON object. For use in expectations when you don't care about all of the attributes on the object. @example // don't care about any other attributes than foo. expect(mySpy).toHaveBeenCalledWith(jasmine.objectContaining({foo: "bar"}); @param sample {Object} sample @returns matchable object for the sample
jasmine.objectContaining ( sample )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Spy.prototype.andCallThrough = function() { this.plan = this.originalValue; return this; };
Tells a spy to call through to the actual implemenatation. @example var foo = { bar: function() { // do some stuff } } // defining a spy on an existing property: foo.bar spyOn(foo, 'bar').andCallThrough();
jasmine.Spy.prototype.andCallThrough ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Spy.prototype.andReturn = function(value) { this.plan = function() { return value; }; return this; };
For setting the return value of a spy. @example // defining a spy from scratch: foo() returns 'baz' var foo = jasmine.createSpy('spy on foo').andReturn('baz'); // defining a spy on an existing property: foo.bar() returns 'baz' spyOn(foo, 'bar').andReturn('baz'); @param {Object} value
jasmine.Spy.prototype.andReturn ( value )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Spy.prototype.andThrow = function(exceptionMsg) { this.plan = function() { throw exceptionMsg; }; return this; };
For throwing an exception when a spy is called. @example // defining a spy from scratch: foo() throws an exception w/ message 'ouch' var foo = jasmine.createSpy('spy on foo').andThrow('baz'); // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch' spyOn(foo, 'bar').andThrow('baz'); @param {String} exceptionMsg
jasmine.Spy.prototype.andThrow ( exceptionMsg )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Spy.prototype.andCallFake = function(fakeFunc) { this.plan = fakeFunc; return this; };
Calls an alternate implementation when a spy is called. @example var baz = function() { // do some stuff, return something } // defining a spy from scratch: foo() calls the function baz var foo = jasmine.createSpy('spy on foo').andCall(baz); // defining a spy on an existing property: foo.bar() calls an anonymnous function spyOn(foo, 'bar').andCall(function() { return 'baz';} ); @param {Function} fakeFunc
jasmine.Spy.prototype.andCallFake ( fakeFunc )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Spy.prototype.reset = function() { this.wasCalled = false; this.callCount = 0; this.argsForCall = []; this.calls = []; this.mostRecentCall = {}; };
Resets all of a spy's the tracking variables so that it can be used again. @example spyOn(foo, 'bar'); foo.bar(); expect(foo.bar.callCount).toEqual(1); foo.bar.reset(); expect(foo.bar.callCount).toEqual(0);
jasmine.Spy.prototype.reset ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.isSpy = function(putativeSpy) { return putativeSpy && putativeSpy.isSpy; };
Determines whether an object is a spy. @param {jasmine.Spy|Object} putativeSpy @returns {Boolean}
jasmine.isSpy ( putativeSpy )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.createSpyObj = function(baseName, methodNames) { if (!jasmine.isArray_(methodNames) || methodNames.length === 0) { throw new Error('createSpyObj requires a non-empty array of method names to create spies for'); } var obj = {}; for (var i = 0; i < methodNames.length; i++) { obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); } return obj; };
Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something large in one call. @param {String} baseName name of spy class @param {Array} methodNames array of names of methods to make spies
jasmine.createSpyObj ( baseName , methodNames )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.log = function() { var spec = jasmine.getEnv().currentSpec; spec.log.apply(spec, arguments); };
All parameters are pretty-printed and concatenated together, then written to the current spec's output. Be careful not to leave calls to <code>jasmine.log</code> in production code.
jasmine.log ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
var spyOn = function(obj, methodName) { return jasmine.getEnv().currentSpec.spyOn(obj, methodName); };
Function that installs a spy on an existing object's method name. Used within a Spec to create a spy. @example // spy example var foo = { not: function(bool) { return !bool; } } spyOn(foo, 'not'); // actual foo.not will not be called, execution stops @see jasmine.createSpy @param obj @param methodName @returns a Jasmine spy that can be chained with all spy methods
spyOn ( obj , methodName )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
var it = function(desc, func) { return jasmine.getEnv().it(desc, func); };
Creates a Jasmine spec that will be added to the current suite. // TODO: pending tests @example it('should be true', function() { expect(true).toEqual(true); }); @param {String} desc description of this specification @param {Function} func defines the preconditions and expectations of the spec
it ( desc , func )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
var xit = function(desc, func) { return jasmine.getEnv().xit(desc, func); };
Creates a <em>disabled</em> Jasmine spec. A convenience method that allows existing specs to be disabled temporarily during development. @param {String} desc description of this specification @param {Function} func defines the preconditions and expectations of the spec
xit ( desc , func )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
var expect = function(actual) { return jasmine.getEnv().currentSpec.expect(actual); };
Starts a chain for a Jasmine expectation. It is passed an Object that is the actual value and should chain to one of the many jasmine.Matchers functions. @param {Object} actual Actual value to test against and expected value
expect ( actual )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
var runs = function(func) { jasmine.getEnv().currentSpec.runs(func); };
Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs. @param {Function} func Function that defines part of a jasmine spec.
runs ( func )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
var waits = function(timeout) { jasmine.getEnv().currentSpec.waits(timeout); };
Waits a fixed time period before moving to the next block. @deprecated Use waitsFor() instead @param {Number} timeout milliseconds to wait
waits ( timeout )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) { jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments); };
Waits for the latchFunction to return true before proceeding to the next block. @param {Function} latchFunction @param {String} optional_timeoutMessage @param {Number} optional_timeout
waitsFor ( latchFunction , optional_timeoutMessage , optional_timeout )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
var beforeEach = function(beforeEachFunction) { jasmine.getEnv().beforeEach(beforeEachFunction); };
A function that is called before each spec in a suite. Used for spec setup, including validating assumptions. @param {Function} beforeEachFunction
beforeEach ( beforeEachFunction )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
var afterEach = function(afterEachFunction) { jasmine.getEnv().afterEach(afterEachFunction); };
A function that is called after each spec in a suite. Used for restoring any state that is hijacked during spec execution. @param {Function} afterEachFunction
afterEach ( afterEachFunction )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
var describe = function(description, specDefinitions) { return jasmine.getEnv().describe(description, specDefinitions); };
Defines a suite of specifications. Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization of setup in some tests. @example // TODO: a simple suite // TODO: a simple suite with a nested describe block @param {String} description A string, usually the class under test. @param {Function} specDefinitions function that defines several specs.
describe ( description , specDefinitions )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
var xdescribe = function(description, specDefinitions) { return jasmine.getEnv().xdescribe(description, specDefinitions); };
Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development. @param {String} description A string, usually the class under test. @param {Function} specDefinitions function that defines several specs.
xdescribe ( description , specDefinitions )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.util.inherit = function(childClass, parentClass) { /** * @private */ var subclass = function() { }; subclass.prototype = parentClass.prototype; childClass.prototype = new subclass(); };
Declare that a child class inherit it's prototype from the parent class. @private @param {Function} childClass @param {Function} parentClass
jasmine.util.inherit ( childClass , parentClass )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Env = function() { this.currentSpec = null; this.currentSuite = null; this.currentRunner_ = new jasmine.Runner(this); this.reporter = new jasmine.MultiReporter(); this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL; this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL; this.lastUpdate = 0; this.specFilter = function() { return true; }; this.nextSpecId_ = 0; this.nextSuiteId_ = 0; this.equalityTesters_ = []; // wrap matchers this.matchersClass = function() { jasmine.Matchers.apply(this, arguments); }; jasmine.util.inherit(this.matchersClass, jasmine.Matchers); jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass); };
Environment for Jasmine @constructor
jasmine.Env ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Env.prototype.version = function () { if (jasmine.version_) { return jasmine.version_; } else { throw new Error('Version not set'); } };
@returns an object containing jasmine version build info, if set.
jasmine.Env.prototype.version ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Env.prototype.versionString = function() { if (!jasmine.version_) { return "version unknown"; } var version = this.version(); var versionString = version.major + "." + version.minor + "." + version.build; if (version.release_candidate) { versionString += ".rc" + version.release_candidate; } versionString += " revision " + version.revision; return versionString; };
@returns string containing jasmine version build info, if set.
jasmine.Env.prototype.versionString ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Env.prototype.nextSpecId = function () { return this.nextSpecId_++; };
@returns a sequential integer starting at 0
jasmine.Env.prototype.nextSpecId ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Env.prototype.addReporter = function(reporter) { this.reporter.addReporter(reporter); };
Register a reporter to receive status updates from Jasmine. @param {jasmine.Reporter} reporter An object which will receive status updates.
jasmine.Env.prototype.addReporter ( reporter )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Reporter = function() { };
No-op base class for Jasmine reporters. @constructor
jasmine.Reporter ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Block = function(env, func, spec) { this.env = env; this.func = func; this.spec = spec; };
Blocks are functions with executable code that make up a spec. @constructor @param {jasmine.Env} env @param {Function} func @param {jasmine.Spec} spec
jasmine.Block ( env , func , spec )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.JsApiReporter = function() { this.started = false; this.finished = false; this.suites_ = []; this.results_ = {}; };
JavaScript API reporter. @constructor
jasmine.JsApiReporter ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers = function(env, actual, spec, opt_isNot) { this.env = env; this.actual = actual; this.spec = spec; this.isNot = opt_isNot || false; this.reportWasCalled_ = false; };
@constructor @param {jasmine.Env} env @param actual @param {jasmine.Spec} spec
jasmine.Matchers ( env , actual , spec , opt_isNot )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.toBe = function(expected) { return this.actual === expected; };
toBe: compares the actual to the expected using === @param expected
jasmine.Matchers.prototype.toBe ( expected )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.toNotBe = function(expected) { return this.actual !== expected; };
toNotBe: compares the actual to the expected using !== @param expected @deprecated as of 1.0. Use not.toBe() instead.
jasmine.Matchers.prototype.toNotBe ( expected )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.toEqual = function(expected) { return this.env.equals_(this.actual, expected); };
toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. @param expected
jasmine.Matchers.prototype.toEqual ( expected )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.toNotEqual = function(expected) { return !this.env.equals_(this.actual, expected); };
toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual @param expected @deprecated as of 1.0. Use not.toEqual() instead.
jasmine.Matchers.prototype.toNotEqual ( expected )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.toMatch = function(expected) { return new RegExp(expected).test(this.actual); };
Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes a pattern or a String. @param expected
jasmine.Matchers.prototype.toMatch ( expected )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.toNotMatch = function(expected) { return !(new RegExp(expected).test(this.actual)); };
Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch @param expected @deprecated as of 1.0. Use not.toMatch() instead.
jasmine.Matchers.prototype.toNotMatch ( expected )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.toBeDefined = function() { return (this.actual !== jasmine.undefined); };
Matcher that compares the actual to jasmine.undefined.
jasmine.Matchers.prototype.toBeDefined ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.toBeNull = function() { return (this.actual === null); };
Matcher that compares the actual to null.
jasmine.Matchers.prototype.toBeNull ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.toBeTruthy = function() { return !!this.actual; };
Matcher that boolean not-nots the actual.
jasmine.Matchers.prototype.toBeTruthy ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.toBeFalsy = function() { return !this.actual; };
Matcher that boolean nots the actual.
jasmine.Matchers.prototype.toBeFalsy ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.toHaveBeenCalled = function() { if (arguments.length > 0) { throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith'); } if (!jasmine.isSpy(this.actual)) { throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); } this.message = function() { return [ "Expected spy " + this.actual.identity + " to have been called.", "Expected spy " + this.actual.identity + " not to have been called." ]; }; return this.actual.wasCalled; };
Matcher that checks to see if the actual, a Jasmine spy, was called.
jasmine.Matchers.prototype.toHaveBeenCalled ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.wasNotCalled = function() { if (arguments.length > 0) { throw new Error('wasNotCalled does not take arguments'); } if (!jasmine.isSpy(this.actual)) { throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); } this.message = function() { return [ "Expected spy " + this.actual.identity + " to not have been called.", "Expected spy " + this.actual.identity + " to have been called." ]; }; return !this.actual.wasCalled; };
Matcher that checks to see if the actual, a Jasmine spy, was not called. @deprecated Use expect(xxx).not.toHaveBeenCalled() instead
jasmine.Matchers.prototype.wasNotCalled ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.toHaveBeenCalledWith = function() { var expectedArgs = jasmine.util.argsToArray(arguments); if (!jasmine.isSpy(this.actual)) { throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); } this.message = function() { if (this.actual.callCount === 0) { // todo: what should the failure message for .not.toHaveBeenCalledWith() be? is this right? test better. [xw] return [ "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.", "Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but it was." ]; } else { return [ "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall), "Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall) ]; } }; return this.env.contains_(this.actual.argsForCall, expectedArgs); };
Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters. @example
jasmine.Matchers.prototype.toHaveBeenCalledWith ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.toContain = function(expected) { return this.env.contains_(this.actual, expected); };
Matcher that checks that the expected item is an element in the actual Array. @param {Object} expected
jasmine.Matchers.prototype.toContain ( expected )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.toNotContain = function(expected) { return !this.env.contains_(this.actual, expected); };
Matcher that checks that the expected item is NOT an element in the actual Array. @param {Object} expected @deprecated as of 1.0. Use not.toContain() instead.
jasmine.Matchers.prototype.toNotContain ( expected )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) { if (!(precision === 0)) { precision = precision || 2; } var multiplier = Math.pow(10, precision); var actual = Math.round(this.actual * multiplier); expected = Math.round(expected * multiplier); return expected == actual; };
Matcher that checks that the expected item is equal to the actual item up to a given level of decimal precision (default 2). @param {Number} expected @param {Number} precision
jasmine.Matchers.prototype.toBeCloseTo ( expected , precision )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.Matchers.prototype.toThrow = function(expected) { var result = false; var exception; if (typeof this.actual != 'function') { throw new Error('Actual is not a function'); } try { this.actual(); } catch (e) { exception = e; } if (exception) { result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected)); } var not = this.isNot ? "not " : ""; this.message = function() { if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' '); } else { return "Expected function to throw an exception."; } }; return result; };
Matcher that checks that the expected exception was thrown by the actual. @param {String} expected
jasmine.Matchers.prototype.toThrow ( expected )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.NestedResults = function() { /** * The total count of results */ this.totalCount = 0; /** * Number of passed results */ this.passedCount = 0; /** * Number of failed results */ this.failedCount = 0; /** * Was this suite/spec skipped? */ this.skipped = false; /** * @ignore */ this.items_ = []; };
Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults @constructor
jasmine.NestedResults ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.NestedResults.prototype.rollupCounts = function(result) { this.totalCount += result.totalCount; this.passedCount += result.passedCount; this.failedCount += result.failedCount; };
Roll up the result counts. @param result
jasmine.NestedResults.prototype.rollupCounts ( result )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.NestedResults.prototype.log = function(values) { this.items_.push(new jasmine.MessageResult(values)); };
Adds a log message. @param values Array of message parts which will be concatenated later.
jasmine.NestedResults.prototype.log ( values )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.NestedResults.prototype.getItems = function() { return this.items_; };
Getter for the results: message & results.
jasmine.NestedResults.prototype.getItems ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.NestedResults.prototype.addResult = function(result) { if (result.type != 'log') { if (result.items_) { this.rollupCounts(result); } else { this.totalCount++; if (result.passed()) { this.passedCount++; } else { this.failedCount++; } } } this.items_.push(result); };
Adds a result, tracking counts (total, passed, & failed) @param {jasmine.ExpectationResult|jasmine.NestedResults} result
jasmine.NestedResults.prototype.addResult ( result )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.NestedResults.prototype.passed = function() { return this.passedCount === this.totalCount; };
@returns {Boolean} True if <b>everything</b> below passed
jasmine.NestedResults.prototype.passed ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0
jasmine.PrettyPrinter = function() { this.ppNestLevel_ = 0; };
Base class for pretty printing for expectation results.
jasmine.PrettyPrinter ( )
javascript
phonegap/phonegap-start
www/spec/lib/jasmine-1.2.0/jasmine.js
https://github.com/phonegap/phonegap-start/blob/master/www/spec/lib/jasmine-1.2.0/jasmine.js
Apache-2.0