id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
6,700 | golden-layout/golden-layout | src/js/items/RowOrColumn.js | function( contentItem, index, _$suspendResize ) {
var newItemSize, itemSize, i, splitterElement;
contentItem = this.layoutManager._$normalizeContentItem( contentItem, this );
if( index === undefined ) {
index = this.contentItems.length;
}
if( this.contentItems.length > 0 ) {
splitterElement = this._createSplitter( Math.max( 0, index - 1 ) ).element;
if( index > 0 ) {
this.contentItems[ index - 1 ].element.after( splitterElement );
splitterElement.after( contentItem.element );
if ( this._isDocked( index - 1 ) ) {
this._splitter[ index - 1 ].element.hide();
this._splitter[ index ].element.show();
}
} else {
this.contentItems[ 0 ].element.before( splitterElement );
splitterElement.before( contentItem.element );
}
} else {
this.childElementContainer.append( contentItem.element );
}
lm.items.AbstractContentItem.prototype.addChild.call( this, contentItem, index );
newItemSize = ( 1 / this.contentItems.length ) * 100;
if( _$suspendResize === true ) {
this.emitBubblingEvent( 'stateChanged' );
return;
}
for( i = 0; i < this.contentItems.length; i++ ) {
if( this.contentItems[ i ] === contentItem ) {
contentItem.config[ this._dimension ] = newItemSize;
} else {
itemSize = this.contentItems[ i ].config[ this._dimension ] *= ( 100 - newItemSize ) / 100;
this.contentItems[ i ].config[ this._dimension ] = itemSize;
}
}
this.callDownwards( 'setSize' );
this.emitBubblingEvent( 'stateChanged' );
this._validateDocking();
} | javascript | function( contentItem, index, _$suspendResize ) {
var newItemSize, itemSize, i, splitterElement;
contentItem = this.layoutManager._$normalizeContentItem( contentItem, this );
if( index === undefined ) {
index = this.contentItems.length;
}
if( this.contentItems.length > 0 ) {
splitterElement = this._createSplitter( Math.max( 0, index - 1 ) ).element;
if( index > 0 ) {
this.contentItems[ index - 1 ].element.after( splitterElement );
splitterElement.after( contentItem.element );
if ( this._isDocked( index - 1 ) ) {
this._splitter[ index - 1 ].element.hide();
this._splitter[ index ].element.show();
}
} else {
this.contentItems[ 0 ].element.before( splitterElement );
splitterElement.before( contentItem.element );
}
} else {
this.childElementContainer.append( contentItem.element );
}
lm.items.AbstractContentItem.prototype.addChild.call( this, contentItem, index );
newItemSize = ( 1 / this.contentItems.length ) * 100;
if( _$suspendResize === true ) {
this.emitBubblingEvent( 'stateChanged' );
return;
}
for( i = 0; i < this.contentItems.length; i++ ) {
if( this.contentItems[ i ] === contentItem ) {
contentItem.config[ this._dimension ] = newItemSize;
} else {
itemSize = this.contentItems[ i ].config[ this._dimension ] *= ( 100 - newItemSize ) / 100;
this.contentItems[ i ].config[ this._dimension ] = itemSize;
}
}
this.callDownwards( 'setSize' );
this.emitBubblingEvent( 'stateChanged' );
this._validateDocking();
} | [
"function",
"(",
"contentItem",
",",
"index",
",",
"_$suspendResize",
")",
"{",
"var",
"newItemSize",
",",
"itemSize",
",",
"i",
",",
"splitterElement",
";",
"contentItem",
"=",
"this",
".",
"layoutManager",
".",
"_$normalizeContentItem",
"(",
"contentItem",
",",
"this",
")",
";",
"if",
"(",
"index",
"===",
"undefined",
")",
"{",
"index",
"=",
"this",
".",
"contentItems",
".",
"length",
";",
"}",
"if",
"(",
"this",
".",
"contentItems",
".",
"length",
">",
"0",
")",
"{",
"splitterElement",
"=",
"this",
".",
"_createSplitter",
"(",
"Math",
".",
"max",
"(",
"0",
",",
"index",
"-",
"1",
")",
")",
".",
"element",
";",
"if",
"(",
"index",
">",
"0",
")",
"{",
"this",
".",
"contentItems",
"[",
"index",
"-",
"1",
"]",
".",
"element",
".",
"after",
"(",
"splitterElement",
")",
";",
"splitterElement",
".",
"after",
"(",
"contentItem",
".",
"element",
")",
";",
"if",
"(",
"this",
".",
"_isDocked",
"(",
"index",
"-",
"1",
")",
")",
"{",
"this",
".",
"_splitter",
"[",
"index",
"-",
"1",
"]",
".",
"element",
".",
"hide",
"(",
")",
";",
"this",
".",
"_splitter",
"[",
"index",
"]",
".",
"element",
".",
"show",
"(",
")",
";",
"}",
"}",
"else",
"{",
"this",
".",
"contentItems",
"[",
"0",
"]",
".",
"element",
".",
"before",
"(",
"splitterElement",
")",
";",
"splitterElement",
".",
"before",
"(",
"contentItem",
".",
"element",
")",
";",
"}",
"}",
"else",
"{",
"this",
".",
"childElementContainer",
".",
"append",
"(",
"contentItem",
".",
"element",
")",
";",
"}",
"lm",
".",
"items",
".",
"AbstractContentItem",
".",
"prototype",
".",
"addChild",
".",
"call",
"(",
"this",
",",
"contentItem",
",",
"index",
")",
";",
"newItemSize",
"=",
"(",
"1",
"/",
"this",
".",
"contentItems",
".",
"length",
")",
"*",
"100",
";",
"if",
"(",
"_$suspendResize",
"===",
"true",
")",
"{",
"this",
".",
"emitBubblingEvent",
"(",
"'stateChanged'",
")",
";",
"return",
";",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"contentItems",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"this",
".",
"contentItems",
"[",
"i",
"]",
"===",
"contentItem",
")",
"{",
"contentItem",
".",
"config",
"[",
"this",
".",
"_dimension",
"]",
"=",
"newItemSize",
";",
"}",
"else",
"{",
"itemSize",
"=",
"this",
".",
"contentItems",
"[",
"i",
"]",
".",
"config",
"[",
"this",
".",
"_dimension",
"]",
"*=",
"(",
"100",
"-",
"newItemSize",
")",
"/",
"100",
";",
"this",
".",
"contentItems",
"[",
"i",
"]",
".",
"config",
"[",
"this",
".",
"_dimension",
"]",
"=",
"itemSize",
";",
"}",
"}",
"this",
".",
"callDownwards",
"(",
"'setSize'",
")",
";",
"this",
".",
"emitBubblingEvent",
"(",
"'stateChanged'",
")",
";",
"this",
".",
"_validateDocking",
"(",
")",
";",
"}"
] | Add a new contentItem to the Row or Column
@param {lm.item.AbstractContentItem} contentItem
@param {[int]} index The position of the new item within the Row or Column.
If no index is provided the item will be added to the end
@param {[bool]} _$suspendResize If true the items won't be resized. This will leave the item in
an inconsistent state and is only intended to be used if multiple
children need to be added in one go and resize is called afterwards
@returns {void} | [
"Add",
"a",
"new",
"contentItem",
"to",
"the",
"Row",
"or",
"Column"
] | 41ffb9f693b810132760d7b1218237820e5f9612 | https://github.com/golden-layout/golden-layout/blob/41ffb9f693b810132760d7b1218237820e5f9612/src/js/items/RowOrColumn.js#L35-L84 |
|
6,701 | golden-layout/golden-layout | src/js/items/RowOrColumn.js | function() {
if( this.isInitialised === true ) return;
var i;
lm.items.AbstractContentItem.prototype._$init.call( this );
for( i = 0; i < this.contentItems.length - 1; i++ ) {
this.contentItems[ i ].element.after( this._createSplitter( i ).element );
}
for( i = 0; i < this.contentItems.length; i++ ) {
if( this.contentItems[ i ]._header && this.contentItems[ i ]._header.docked )
this.dock( this.contentItems[ i ], true, true );
}
} | javascript | function() {
if( this.isInitialised === true ) return;
var i;
lm.items.AbstractContentItem.prototype._$init.call( this );
for( i = 0; i < this.contentItems.length - 1; i++ ) {
this.contentItems[ i ].element.after( this._createSplitter( i ).element );
}
for( i = 0; i < this.contentItems.length; i++ ) {
if( this.contentItems[ i ]._header && this.contentItems[ i ]._header.docked )
this.dock( this.contentItems[ i ], true, true );
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"isInitialised",
"===",
"true",
")",
"return",
";",
"var",
"i",
";",
"lm",
".",
"items",
".",
"AbstractContentItem",
".",
"prototype",
".",
"_$init",
".",
"call",
"(",
"this",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"contentItems",
".",
"length",
"-",
"1",
";",
"i",
"++",
")",
"{",
"this",
".",
"contentItems",
"[",
"i",
"]",
".",
"element",
".",
"after",
"(",
"this",
".",
"_createSplitter",
"(",
"i",
")",
".",
"element",
")",
";",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"contentItems",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"this",
".",
"contentItems",
"[",
"i",
"]",
".",
"_header",
"&&",
"this",
".",
"contentItems",
"[",
"i",
"]",
".",
"_header",
".",
"docked",
")",
"this",
".",
"dock",
"(",
"this",
".",
"contentItems",
"[",
"i",
"]",
",",
"true",
",",
"true",
")",
";",
"}",
"}"
] | Invoked recursively by the layout manager. AbstractContentItem.init appends
the contentItem's DOM elements to the container, RowOrColumn init adds splitters
in between them
@package private
@override AbstractContentItem._$init
@returns {void} | [
"Invoked",
"recursively",
"by",
"the",
"layout",
"manager",
".",
"AbstractContentItem",
".",
"init",
"appends",
"the",
"contentItem",
"s",
"DOM",
"elements",
"to",
"the",
"container",
"RowOrColumn",
"init",
"adds",
"splitters",
"in",
"between",
"them"
] | 41ffb9f693b810132760d7b1218237820e5f9612 | https://github.com/golden-layout/golden-layout/blob/41ffb9f693b810132760d7b1218237820e5f9612/src/js/items/RowOrColumn.js#L252-L266 |
|
6,702 | golden-layout/golden-layout | src/js/items/RowOrColumn.js | function() {
var i,
totalSplitterSize = (this.contentItems.length - 1) * this._splitterSize,
headerSize = this.layoutManager.config.dimensions.headerHeight,
totalWidth = this.element.width(),
totalHeight = this.element.height(),
totalAssigned = 0,
additionalPixel,
itemSize,
itemSizes = [];
if( this._isColumn ) {
totalHeight -= totalSplitterSize;
} else {
totalWidth -= totalSplitterSize;
}
for( i = 0; i < this.contentItems.length; i++ ) {
if( this._isDocked( i ) )
if( this._isColumn ) {
totalHeight -= headerSize - this._splitterSize;
} else {
totalWidth -= headerSize - this._splitterSize;
}
}
for( i = 0; i < this.contentItems.length; i++ ) {
if( this._isColumn ) {
itemSize = Math.floor( totalHeight * ( this.contentItems[ i ].config.height / 100 ) );
} else {
itemSize = Math.floor( totalWidth * (this.contentItems[ i ].config.width / 100) );
}
if( this._isDocked( i ) )
itemSize = headerSize;
totalAssigned += itemSize;
itemSizes.push( itemSize );
}
additionalPixel = Math.floor( (this._isColumn ? totalHeight : totalWidth) - totalAssigned );
return {
itemSizes: itemSizes,
additionalPixel: additionalPixel,
totalWidth: totalWidth,
totalHeight: totalHeight
};
} | javascript | function() {
var i,
totalSplitterSize = (this.contentItems.length - 1) * this._splitterSize,
headerSize = this.layoutManager.config.dimensions.headerHeight,
totalWidth = this.element.width(),
totalHeight = this.element.height(),
totalAssigned = 0,
additionalPixel,
itemSize,
itemSizes = [];
if( this._isColumn ) {
totalHeight -= totalSplitterSize;
} else {
totalWidth -= totalSplitterSize;
}
for( i = 0; i < this.contentItems.length; i++ ) {
if( this._isDocked( i ) )
if( this._isColumn ) {
totalHeight -= headerSize - this._splitterSize;
} else {
totalWidth -= headerSize - this._splitterSize;
}
}
for( i = 0; i < this.contentItems.length; i++ ) {
if( this._isColumn ) {
itemSize = Math.floor( totalHeight * ( this.contentItems[ i ].config.height / 100 ) );
} else {
itemSize = Math.floor( totalWidth * (this.contentItems[ i ].config.width / 100) );
}
if( this._isDocked( i ) )
itemSize = headerSize;
totalAssigned += itemSize;
itemSizes.push( itemSize );
}
additionalPixel = Math.floor( (this._isColumn ? totalHeight : totalWidth) - totalAssigned );
return {
itemSizes: itemSizes,
additionalPixel: additionalPixel,
totalWidth: totalWidth,
totalHeight: totalHeight
};
} | [
"function",
"(",
")",
"{",
"var",
"i",
",",
"totalSplitterSize",
"=",
"(",
"this",
".",
"contentItems",
".",
"length",
"-",
"1",
")",
"*",
"this",
".",
"_splitterSize",
",",
"headerSize",
"=",
"this",
".",
"layoutManager",
".",
"config",
".",
"dimensions",
".",
"headerHeight",
",",
"totalWidth",
"=",
"this",
".",
"element",
".",
"width",
"(",
")",
",",
"totalHeight",
"=",
"this",
".",
"element",
".",
"height",
"(",
")",
",",
"totalAssigned",
"=",
"0",
",",
"additionalPixel",
",",
"itemSize",
",",
"itemSizes",
"=",
"[",
"]",
";",
"if",
"(",
"this",
".",
"_isColumn",
")",
"{",
"totalHeight",
"-=",
"totalSplitterSize",
";",
"}",
"else",
"{",
"totalWidth",
"-=",
"totalSplitterSize",
";",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"contentItems",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"this",
".",
"_isDocked",
"(",
"i",
")",
")",
"if",
"(",
"this",
".",
"_isColumn",
")",
"{",
"totalHeight",
"-=",
"headerSize",
"-",
"this",
".",
"_splitterSize",
";",
"}",
"else",
"{",
"totalWidth",
"-=",
"headerSize",
"-",
"this",
".",
"_splitterSize",
";",
"}",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"contentItems",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"this",
".",
"_isColumn",
")",
"{",
"itemSize",
"=",
"Math",
".",
"floor",
"(",
"totalHeight",
"*",
"(",
"this",
".",
"contentItems",
"[",
"i",
"]",
".",
"config",
".",
"height",
"/",
"100",
")",
")",
";",
"}",
"else",
"{",
"itemSize",
"=",
"Math",
".",
"floor",
"(",
"totalWidth",
"*",
"(",
"this",
".",
"contentItems",
"[",
"i",
"]",
".",
"config",
".",
"width",
"/",
"100",
")",
")",
";",
"}",
"if",
"(",
"this",
".",
"_isDocked",
"(",
"i",
")",
")",
"itemSize",
"=",
"headerSize",
";",
"totalAssigned",
"+=",
"itemSize",
";",
"itemSizes",
".",
"push",
"(",
"itemSize",
")",
";",
"}",
"additionalPixel",
"=",
"Math",
".",
"floor",
"(",
"(",
"this",
".",
"_isColumn",
"?",
"totalHeight",
":",
"totalWidth",
")",
"-",
"totalAssigned",
")",
";",
"return",
"{",
"itemSizes",
":",
"itemSizes",
",",
"additionalPixel",
":",
"additionalPixel",
",",
"totalWidth",
":",
"totalWidth",
",",
"totalHeight",
":",
"totalHeight",
"}",
";",
"}"
] | Calculates the absolute sizes of all of the children of this Item.
@returns {object} - Set with absolute sizes and additional pixels. | [
"Calculates",
"the",
"absolute",
"sizes",
"of",
"all",
"of",
"the",
"children",
"of",
"this",
"Item",
"."
] | 41ffb9f693b810132760d7b1218237820e5f9612 | https://github.com/golden-layout/golden-layout/blob/41ffb9f693b810132760d7b1218237820e5f9612/src/js/items/RowOrColumn.js#L300-L346 |
|
6,703 | golden-layout/golden-layout | src/js/items/RowOrColumn.js | function() {
var minItemWidth = this.layoutManager.config.dimensions ? (this.layoutManager.config.dimensions.minItemWidth || 0) : 0,
sizeData = null,
entriesOverMin = [],
totalOverMin = 0,
totalUnderMin = 0,
remainingWidth = 0,
itemSize = 0,
contentItem = null,
reducePercent,
reducedWidth,
allEntries = [],
entry;
if( this._isColumn || !minItemWidth || this.contentItems.length <= 1 ) {
return;
}
sizeData = this._calculateAbsoluteSizes();
/**
* Figure out how much we are under the min item size total and how much room we have to use.
*/
for( var i = 0; i < this.contentItems.length; i++ ) {
contentItem = this.contentItems[ i ];
itemSize = sizeData.itemSizes[ i ];
if( itemSize < minItemWidth ) {
totalUnderMin += minItemWidth - itemSize;
entry = { width: minItemWidth };
}
else {
totalOverMin += itemSize - minItemWidth;
entry = { width: itemSize };
entriesOverMin.push( entry );
}
allEntries.push( entry );
}
/**
* If there is nothing under min, or there is not enough over to make up the difference, do nothing.
*/
if( totalUnderMin === 0 || totalUnderMin > totalOverMin ) {
return;
}
/**
* Evenly reduce all columns that are over the min item width to make up the difference.
*/
reducePercent = totalUnderMin / totalOverMin;
remainingWidth = totalUnderMin;
for( i = 0; i < entriesOverMin.length; i++ ) {
entry = entriesOverMin[ i ];
reducedWidth = Math.round( ( entry.width - minItemWidth ) * reducePercent );
remainingWidth -= reducedWidth;
entry.width -= reducedWidth;
}
/**
* Take anything remaining from the last item.
*/
if( remainingWidth !== 0 ) {
allEntries[ allEntries.length - 1 ].width -= remainingWidth;
}
/**
* Set every items size relative to 100 relative to its size to total
*/
for( i = 0; i < this.contentItems.length; i++ ) {
this.contentItems[ i ].config.width = (allEntries[ i ].width / sizeData.totalWidth) * 100;
}
} | javascript | function() {
var minItemWidth = this.layoutManager.config.dimensions ? (this.layoutManager.config.dimensions.minItemWidth || 0) : 0,
sizeData = null,
entriesOverMin = [],
totalOverMin = 0,
totalUnderMin = 0,
remainingWidth = 0,
itemSize = 0,
contentItem = null,
reducePercent,
reducedWidth,
allEntries = [],
entry;
if( this._isColumn || !minItemWidth || this.contentItems.length <= 1 ) {
return;
}
sizeData = this._calculateAbsoluteSizes();
/**
* Figure out how much we are under the min item size total and how much room we have to use.
*/
for( var i = 0; i < this.contentItems.length; i++ ) {
contentItem = this.contentItems[ i ];
itemSize = sizeData.itemSizes[ i ];
if( itemSize < minItemWidth ) {
totalUnderMin += minItemWidth - itemSize;
entry = { width: minItemWidth };
}
else {
totalOverMin += itemSize - minItemWidth;
entry = { width: itemSize };
entriesOverMin.push( entry );
}
allEntries.push( entry );
}
/**
* If there is nothing under min, or there is not enough over to make up the difference, do nothing.
*/
if( totalUnderMin === 0 || totalUnderMin > totalOverMin ) {
return;
}
/**
* Evenly reduce all columns that are over the min item width to make up the difference.
*/
reducePercent = totalUnderMin / totalOverMin;
remainingWidth = totalUnderMin;
for( i = 0; i < entriesOverMin.length; i++ ) {
entry = entriesOverMin[ i ];
reducedWidth = Math.round( ( entry.width - minItemWidth ) * reducePercent );
remainingWidth -= reducedWidth;
entry.width -= reducedWidth;
}
/**
* Take anything remaining from the last item.
*/
if( remainingWidth !== 0 ) {
allEntries[ allEntries.length - 1 ].width -= remainingWidth;
}
/**
* Set every items size relative to 100 relative to its size to total
*/
for( i = 0; i < this.contentItems.length; i++ ) {
this.contentItems[ i ].config.width = (allEntries[ i ].width / sizeData.totalWidth) * 100;
}
} | [
"function",
"(",
")",
"{",
"var",
"minItemWidth",
"=",
"this",
".",
"layoutManager",
".",
"config",
".",
"dimensions",
"?",
"(",
"this",
".",
"layoutManager",
".",
"config",
".",
"dimensions",
".",
"minItemWidth",
"||",
"0",
")",
":",
"0",
",",
"sizeData",
"=",
"null",
",",
"entriesOverMin",
"=",
"[",
"]",
",",
"totalOverMin",
"=",
"0",
",",
"totalUnderMin",
"=",
"0",
",",
"remainingWidth",
"=",
"0",
",",
"itemSize",
"=",
"0",
",",
"contentItem",
"=",
"null",
",",
"reducePercent",
",",
"reducedWidth",
",",
"allEntries",
"=",
"[",
"]",
",",
"entry",
";",
"if",
"(",
"this",
".",
"_isColumn",
"||",
"!",
"minItemWidth",
"||",
"this",
".",
"contentItems",
".",
"length",
"<=",
"1",
")",
"{",
"return",
";",
"}",
"sizeData",
"=",
"this",
".",
"_calculateAbsoluteSizes",
"(",
")",
";",
"/**\n\t\t * Figure out how much we are under the min item size total and how much room we have to use.\n\t\t */",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"contentItems",
".",
"length",
";",
"i",
"++",
")",
"{",
"contentItem",
"=",
"this",
".",
"contentItems",
"[",
"i",
"]",
";",
"itemSize",
"=",
"sizeData",
".",
"itemSizes",
"[",
"i",
"]",
";",
"if",
"(",
"itemSize",
"<",
"minItemWidth",
")",
"{",
"totalUnderMin",
"+=",
"minItemWidth",
"-",
"itemSize",
";",
"entry",
"=",
"{",
"width",
":",
"minItemWidth",
"}",
";",
"}",
"else",
"{",
"totalOverMin",
"+=",
"itemSize",
"-",
"minItemWidth",
";",
"entry",
"=",
"{",
"width",
":",
"itemSize",
"}",
";",
"entriesOverMin",
".",
"push",
"(",
"entry",
")",
";",
"}",
"allEntries",
".",
"push",
"(",
"entry",
")",
";",
"}",
"/**\n\t\t * If there is nothing under min, or there is not enough over to make up the difference, do nothing.\n\t\t */",
"if",
"(",
"totalUnderMin",
"===",
"0",
"||",
"totalUnderMin",
">",
"totalOverMin",
")",
"{",
"return",
";",
"}",
"/**\n\t\t * Evenly reduce all columns that are over the min item width to make up the difference.\n\t\t */",
"reducePercent",
"=",
"totalUnderMin",
"/",
"totalOverMin",
";",
"remainingWidth",
"=",
"totalUnderMin",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"entriesOverMin",
".",
"length",
";",
"i",
"++",
")",
"{",
"entry",
"=",
"entriesOverMin",
"[",
"i",
"]",
";",
"reducedWidth",
"=",
"Math",
".",
"round",
"(",
"(",
"entry",
".",
"width",
"-",
"minItemWidth",
")",
"*",
"reducePercent",
")",
";",
"remainingWidth",
"-=",
"reducedWidth",
";",
"entry",
".",
"width",
"-=",
"reducedWidth",
";",
"}",
"/**\n\t\t * Take anything remaining from the last item.\n\t\t */",
"if",
"(",
"remainingWidth",
"!==",
"0",
")",
"{",
"allEntries",
"[",
"allEntries",
".",
"length",
"-",
"1",
"]",
".",
"width",
"-=",
"remainingWidth",
";",
"}",
"/**\n\t\t * Set every items size relative to 100 relative to its size to total\n\t\t */",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"contentItems",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"contentItems",
"[",
"i",
"]",
".",
"config",
".",
"width",
"=",
"(",
"allEntries",
"[",
"i",
"]",
".",
"width",
"/",
"sizeData",
".",
"totalWidth",
")",
"*",
"100",
";",
"}",
"}"
] | Adjusts the column widths to respect the dimensions minItemWidth if set.
@returns {} | [
"Adjusts",
"the",
"column",
"widths",
"to",
"respect",
"the",
"dimensions",
"minItemWidth",
"if",
"set",
"."
] | 41ffb9f693b810132760d7b1218237820e5f9612 | https://github.com/golden-layout/golden-layout/blob/41ffb9f693b810132760d7b1218237820e5f9612/src/js/items/RowOrColumn.js#L430-L504 |
|
6,704 | golden-layout/golden-layout | src/js/items/RowOrColumn.js | function( index ) {
var splitter;
splitter = new lm.controls.Splitter( this._isColumn, this._splitterSize, this._splitterGrabSize );
splitter.on( 'drag', lm.utils.fnBind( this._onSplitterDrag, this, [ splitter ] ), this );
splitter.on( 'dragStop', lm.utils.fnBind( this._onSplitterDragStop, this, [ splitter ] ), this );
splitter.on( 'dragStart', lm.utils.fnBind( this._onSplitterDragStart, this, [ splitter ] ), this );
this._splitter.splice( index, 0, splitter );
return splitter;
} | javascript | function( index ) {
var splitter;
splitter = new lm.controls.Splitter( this._isColumn, this._splitterSize, this._splitterGrabSize );
splitter.on( 'drag', lm.utils.fnBind( this._onSplitterDrag, this, [ splitter ] ), this );
splitter.on( 'dragStop', lm.utils.fnBind( this._onSplitterDragStop, this, [ splitter ] ), this );
splitter.on( 'dragStart', lm.utils.fnBind( this._onSplitterDragStart, this, [ splitter ] ), this );
this._splitter.splice( index, 0, splitter );
return splitter;
} | [
"function",
"(",
"index",
")",
"{",
"var",
"splitter",
";",
"splitter",
"=",
"new",
"lm",
".",
"controls",
".",
"Splitter",
"(",
"this",
".",
"_isColumn",
",",
"this",
".",
"_splitterSize",
",",
"this",
".",
"_splitterGrabSize",
")",
";",
"splitter",
".",
"on",
"(",
"'drag'",
",",
"lm",
".",
"utils",
".",
"fnBind",
"(",
"this",
".",
"_onSplitterDrag",
",",
"this",
",",
"[",
"splitter",
"]",
")",
",",
"this",
")",
";",
"splitter",
".",
"on",
"(",
"'dragStop'",
",",
"lm",
".",
"utils",
".",
"fnBind",
"(",
"this",
".",
"_onSplitterDragStop",
",",
"this",
",",
"[",
"splitter",
"]",
")",
",",
"this",
")",
";",
"splitter",
".",
"on",
"(",
"'dragStart'",
",",
"lm",
".",
"utils",
".",
"fnBind",
"(",
"this",
".",
"_onSplitterDragStart",
",",
"this",
",",
"[",
"splitter",
"]",
")",
",",
"this",
")",
";",
"this",
".",
"_splitter",
".",
"splice",
"(",
"index",
",",
"0",
",",
"splitter",
")",
";",
"return",
"splitter",
";",
"}"
] | Instantiates a new lm.controls.Splitter, binds events to it and adds
it to the array of splitters at the position specified as the index argument
What it doesn't do though is append the splitter to the DOM
@param {Int} index The position of the splitter
@returns {lm.controls.Splitter} | [
"Instantiates",
"a",
"new",
"lm",
".",
"controls",
".",
"Splitter",
"binds",
"events",
"to",
"it",
"and",
"adds",
"it",
"to",
"the",
"array",
"of",
"splitters",
"at",
"the",
"position",
"specified",
"as",
"the",
"index",
"argument"
] | 41ffb9f693b810132760d7b1218237820e5f9612 | https://github.com/golden-layout/golden-layout/blob/41ffb9f693b810132760d7b1218237820e5f9612/src/js/items/RowOrColumn.js#L516-L524 |
|
6,705 | golden-layout/golden-layout | src/js/items/RowOrColumn.js | function ( index ) {
if ( typeof index == 'undefined' ) {
var count = 0;
for (var i = 0; i < this.contentItems.length; ++i)
if ( this._isDocked( i ) )
count++;
return count;
}
if ( index < this.contentItems.length )
return this.contentItems[ index ]._docker && this.contentItems[ index ]._docker.docked;
} | javascript | function ( index ) {
if ( typeof index == 'undefined' ) {
var count = 0;
for (var i = 0; i < this.contentItems.length; ++i)
if ( this._isDocked( i ) )
count++;
return count;
}
if ( index < this.contentItems.length )
return this.contentItems[ index ]._docker && this.contentItems[ index ]._docker.docked;
} | [
"function",
"(",
"index",
")",
"{",
"if",
"(",
"typeof",
"index",
"==",
"'undefined'",
")",
"{",
"var",
"count",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"contentItems",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"this",
".",
"_isDocked",
"(",
"i",
")",
")",
"count",
"++",
";",
"return",
"count",
";",
"}",
"if",
"(",
"index",
"<",
"this",
".",
"contentItems",
".",
"length",
")",
"return",
"this",
".",
"contentItems",
"[",
"index",
"]",
".",
"_docker",
"&&",
"this",
".",
"contentItems",
"[",
"index",
"]",
".",
"_docker",
".",
"docked",
";",
"}"
] | Gets docking information
@private | [
"Gets",
"docking",
"information"
] | 41ffb9f693b810132760d7b1218237820e5f9612 | https://github.com/golden-layout/golden-layout/blob/41ffb9f693b810132760d7b1218237820e5f9612/src/js/items/RowOrColumn.js#L549-L559 |
|
6,706 | golden-layout/golden-layout | src/js/items/RowOrColumn.js | function ( that ) {
that = that || this;
var can = that.contentItems.length - that._isDocked() > 1;
for (var i = 0; i < that.contentItems.length; ++i )
if ( that.contentItems[ i ] instanceof lm.items.Stack ) {
that.contentItems[ i ].header._setDockable( that._isDocked( i ) || can );
that.contentItems[ i ].header._$setClosable( can );
}
} | javascript | function ( that ) {
that = that || this;
var can = that.contentItems.length - that._isDocked() > 1;
for (var i = 0; i < that.contentItems.length; ++i )
if ( that.contentItems[ i ] instanceof lm.items.Stack ) {
that.contentItems[ i ].header._setDockable( that._isDocked( i ) || can );
that.contentItems[ i ].header._$setClosable( can );
}
} | [
"function",
"(",
"that",
")",
"{",
"that",
"=",
"that",
"||",
"this",
";",
"var",
"can",
"=",
"that",
".",
"contentItems",
".",
"length",
"-",
"that",
".",
"_isDocked",
"(",
")",
">",
"1",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"that",
".",
"contentItems",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"that",
".",
"contentItems",
"[",
"i",
"]",
"instanceof",
"lm",
".",
"items",
".",
"Stack",
")",
"{",
"that",
".",
"contentItems",
"[",
"i",
"]",
".",
"header",
".",
"_setDockable",
"(",
"that",
".",
"_isDocked",
"(",
"i",
")",
"||",
"can",
")",
";",
"that",
".",
"contentItems",
"[",
"i",
"]",
".",
"header",
".",
"_$setClosable",
"(",
"can",
")",
";",
"}",
"}"
] | Validate if row or column has ability to dock
@private | [
"Validate",
"if",
"row",
"or",
"column",
"has",
"ability",
"to",
"dock"
] | 41ffb9f693b810132760d7b1218237820e5f9612 | https://github.com/golden-layout/golden-layout/blob/41ffb9f693b810132760d7b1218237820e5f9612/src/js/items/RowOrColumn.js#L565-L573 |
|
6,707 | golden-layout/golden-layout | src/js/items/RowOrColumn.js | function( arr ) {
var minWidth = 0, minHeight = 0;
for( var i = 0; i < arr.length; ++i ) {
minWidth = Math.max( arr[ i ].minWidth || 0, minWidth );
minHeight = Math.max( arr[ i ].minHeight || 0, minHeight );
}
return { horizontal: minWidth, vertical: minHeight };
} | javascript | function( arr ) {
var minWidth = 0, minHeight = 0;
for( var i = 0; i < arr.length; ++i ) {
minWidth = Math.max( arr[ i ].minWidth || 0, minWidth );
minHeight = Math.max( arr[ i ].minHeight || 0, minHeight );
}
return { horizontal: minWidth, vertical: minHeight };
} | [
"function",
"(",
"arr",
")",
"{",
"var",
"minWidth",
"=",
"0",
",",
"minHeight",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"arr",
".",
"length",
";",
"++",
"i",
")",
"{",
"minWidth",
"=",
"Math",
".",
"max",
"(",
"arr",
"[",
"i",
"]",
".",
"minWidth",
"||",
"0",
",",
"minWidth",
")",
";",
"minHeight",
"=",
"Math",
".",
"max",
"(",
"arr",
"[",
"i",
"]",
".",
"minHeight",
"||",
"0",
",",
"minHeight",
")",
";",
"}",
"return",
"{",
"horizontal",
":",
"minWidth",
",",
"vertical",
":",
"minHeight",
"}",
";",
"}"
] | Gets the minimum dimensions for the given item configuration array
@param item
@private | [
"Gets",
"the",
"minimum",
"dimensions",
"for",
"the",
"given",
"item",
"configuration",
"array"
] | 41ffb9f693b810132760d7b1218237820e5f9612 | https://github.com/golden-layout/golden-layout/blob/41ffb9f693b810132760d7b1218237820e5f9612/src/js/items/RowOrColumn.js#L580-L589 |
|
6,708 | golden-layout/golden-layout | src/js/controls/Tab.js | function() {
this.element.off( 'mousedown touchstart', this._onTabClickFn );
this.closeElement.off( 'click touchstart', this._onCloseClickFn );
if( this._dragListener ) {
this.contentItem.off( 'destroy', this._dragListener.destroy, this._dragListener );
this._dragListener.off( 'dragStart', this._onDragStart );
this._dragListener = null;
}
this.element.remove();
} | javascript | function() {
this.element.off( 'mousedown touchstart', this._onTabClickFn );
this.closeElement.off( 'click touchstart', this._onCloseClickFn );
if( this._dragListener ) {
this.contentItem.off( 'destroy', this._dragListener.destroy, this._dragListener );
this._dragListener.off( 'dragStart', this._onDragStart );
this._dragListener = null;
}
this.element.remove();
} | [
"function",
"(",
")",
"{",
"this",
".",
"element",
".",
"off",
"(",
"'mousedown touchstart'",
",",
"this",
".",
"_onTabClickFn",
")",
";",
"this",
".",
"closeElement",
".",
"off",
"(",
"'click touchstart'",
",",
"this",
".",
"_onCloseClickFn",
")",
";",
"if",
"(",
"this",
".",
"_dragListener",
")",
"{",
"this",
".",
"contentItem",
".",
"off",
"(",
"'destroy'",
",",
"this",
".",
"_dragListener",
".",
"destroy",
",",
"this",
".",
"_dragListener",
")",
";",
"this",
".",
"_dragListener",
".",
"off",
"(",
"'dragStart'",
",",
"this",
".",
"_onDragStart",
")",
";",
"this",
".",
"_dragListener",
"=",
"null",
";",
"}",
"this",
".",
"element",
".",
"remove",
"(",
")",
";",
"}"
] | Destroys the tab
@private
@returns {void} | [
"Destroys",
"the",
"tab"
] | 41ffb9f693b810132760d7b1218237820e5f9612 | https://github.com/golden-layout/golden-layout/blob/41ffb9f693b810132760d7b1218237820e5f9612/src/js/controls/Tab.js#L104-L113 |
|
6,709 | golden-layout/golden-layout | src/js/controls/Tab.js | function( x, y ) {
if( !this.header._canDestroy )
return null;
if( this.contentItem.parent.isMaximised === true ) {
this.contentItem.parent.toggleMaximise();
}
new lm.controls.DragProxy(
x,
y,
this._dragListener,
this._layoutManager,
this.contentItem,
this.header.parent
);
} | javascript | function( x, y ) {
if( !this.header._canDestroy )
return null;
if( this.contentItem.parent.isMaximised === true ) {
this.contentItem.parent.toggleMaximise();
}
new lm.controls.DragProxy(
x,
y,
this._dragListener,
this._layoutManager,
this.contentItem,
this.header.parent
);
} | [
"function",
"(",
"x",
",",
"y",
")",
"{",
"if",
"(",
"!",
"this",
".",
"header",
".",
"_canDestroy",
")",
"return",
"null",
";",
"if",
"(",
"this",
".",
"contentItem",
".",
"parent",
".",
"isMaximised",
"===",
"true",
")",
"{",
"this",
".",
"contentItem",
".",
"parent",
".",
"toggleMaximise",
"(",
")",
";",
"}",
"new",
"lm",
".",
"controls",
".",
"DragProxy",
"(",
"x",
",",
"y",
",",
"this",
".",
"_dragListener",
",",
"this",
".",
"_layoutManager",
",",
"this",
".",
"contentItem",
",",
"this",
".",
"header",
".",
"parent",
")",
";",
"}"
] | Callback for the DragListener
@param {Number} x The tabs absolute x position
@param {Number} y The tabs absolute y position
@private
@returns {void} | [
"Callback",
"for",
"the",
"DragListener"
] | 41ffb9f693b810132760d7b1218237820e5f9612 | https://github.com/golden-layout/golden-layout/blob/41ffb9f693b810132760d7b1218237820e5f9612/src/js/controls/Tab.js#L124-L138 |
|
6,710 | golden-layout/golden-layout | src/js/controls/Tab.js | function( event ) {
// left mouse button or tap
if( event.button === 0 || event.type === 'touchstart' ) {
this.header.parent.setActiveContentItem( this.contentItem );
// middle mouse button
} else if( event.button === 1 && this.contentItem.config.isClosable ) {
this._onCloseClick( event );
}
} | javascript | function( event ) {
// left mouse button or tap
if( event.button === 0 || event.type === 'touchstart' ) {
this.header.parent.setActiveContentItem( this.contentItem );
// middle mouse button
} else if( event.button === 1 && this.contentItem.config.isClosable ) {
this._onCloseClick( event );
}
} | [
"function",
"(",
"event",
")",
"{",
"// left mouse button or tap",
"if",
"(",
"event",
".",
"button",
"===",
"0",
"||",
"event",
".",
"type",
"===",
"'touchstart'",
")",
"{",
"this",
".",
"header",
".",
"parent",
".",
"setActiveContentItem",
"(",
"this",
".",
"contentItem",
")",
";",
"// middle mouse button",
"}",
"else",
"if",
"(",
"event",
".",
"button",
"===",
"1",
"&&",
"this",
".",
"contentItem",
".",
"config",
".",
"isClosable",
")",
"{",
"this",
".",
"_onCloseClick",
"(",
"event",
")",
";",
"}",
"}"
] | Callback when the tab is clicked
@param {jQuery DOM event} event
@private
@returns {void} | [
"Callback",
"when",
"the",
"tab",
"is",
"clicked"
] | 41ffb9f693b810132760d7b1218237820e5f9612 | https://github.com/golden-layout/golden-layout/blob/41ffb9f693b810132760d7b1218237820e5f9612/src/js/controls/Tab.js#L148-L157 |
|
6,711 | russellgoldenberg/scrollama | src/init.js | updateStepAboveIO | function updateStepAboveIO() {
io.stepAbove = stepEl.map((el, i) => {
const marginTop = -offsetMargin + stepOffsetHeight[i];
const marginBottom = offsetMargin - viewH;
const rootMargin = `${marginTop}px 0px ${marginBottom}px 0px`;
const options = { rootMargin };
// console.log(options);
const obs = new IntersectionObserver(intersectStepAbove, options);
obs.observe(el);
return obs;
});
} | javascript | function updateStepAboveIO() {
io.stepAbove = stepEl.map((el, i) => {
const marginTop = -offsetMargin + stepOffsetHeight[i];
const marginBottom = offsetMargin - viewH;
const rootMargin = `${marginTop}px 0px ${marginBottom}px 0px`;
const options = { rootMargin };
// console.log(options);
const obs = new IntersectionObserver(intersectStepAbove, options);
obs.observe(el);
return obs;
});
} | [
"function",
"updateStepAboveIO",
"(",
")",
"{",
"io",
".",
"stepAbove",
"=",
"stepEl",
".",
"map",
"(",
"(",
"el",
",",
"i",
")",
"=>",
"{",
"const",
"marginTop",
"=",
"-",
"offsetMargin",
"+",
"stepOffsetHeight",
"[",
"i",
"]",
";",
"const",
"marginBottom",
"=",
"offsetMargin",
"-",
"viewH",
";",
"const",
"rootMargin",
"=",
"`",
"${",
"marginTop",
"}",
"${",
"marginBottom",
"}",
"`",
";",
"const",
"options",
"=",
"{",
"rootMargin",
"}",
";",
"// console.log(options);",
"const",
"obs",
"=",
"new",
"IntersectionObserver",
"(",
"intersectStepAbove",
",",
"options",
")",
";",
"obs",
".",
"observe",
"(",
"el",
")",
";",
"return",
"obs",
";",
"}",
")",
";",
"}"
] | look above for intersection | [
"look",
"above",
"for",
"intersection"
] | 486c14807c43d284eaaf2118e52b116798e618b9 | https://github.com/russellgoldenberg/scrollama/blob/486c14807c43d284eaaf2118e52b116798e618b9/src/init.js#L363-L374 |
6,712 | russellgoldenberg/scrollama | src/init.js | updateStepProgressIO | function updateStepProgressIO() {
io.stepProgress = stepEl.map((el, i) => {
const marginTop = stepOffsetHeight[i] - offsetMargin;
const marginBottom = -viewH + offsetMargin;
const rootMargin = `${marginTop}px 0px ${marginBottom}px 0px`;
const threshold = createThreshold(stepOffsetHeight[i]);
const options = { rootMargin, threshold };
// console.log(options);
const obs = new IntersectionObserver(intersectStepProgress, options);
obs.observe(el);
return obs;
});
} | javascript | function updateStepProgressIO() {
io.stepProgress = stepEl.map((el, i) => {
const marginTop = stepOffsetHeight[i] - offsetMargin;
const marginBottom = -viewH + offsetMargin;
const rootMargin = `${marginTop}px 0px ${marginBottom}px 0px`;
const threshold = createThreshold(stepOffsetHeight[i]);
const options = { rootMargin, threshold };
// console.log(options);
const obs = new IntersectionObserver(intersectStepProgress, options);
obs.observe(el);
return obs;
});
} | [
"function",
"updateStepProgressIO",
"(",
")",
"{",
"io",
".",
"stepProgress",
"=",
"stepEl",
".",
"map",
"(",
"(",
"el",
",",
"i",
")",
"=>",
"{",
"const",
"marginTop",
"=",
"stepOffsetHeight",
"[",
"i",
"]",
"-",
"offsetMargin",
";",
"const",
"marginBottom",
"=",
"-",
"viewH",
"+",
"offsetMargin",
";",
"const",
"rootMargin",
"=",
"`",
"${",
"marginTop",
"}",
"${",
"marginBottom",
"}",
"`",
";",
"const",
"threshold",
"=",
"createThreshold",
"(",
"stepOffsetHeight",
"[",
"i",
"]",
")",
";",
"const",
"options",
"=",
"{",
"rootMargin",
",",
"threshold",
"}",
";",
"// console.log(options);",
"const",
"obs",
"=",
"new",
"IntersectionObserver",
"(",
"intersectStepProgress",
",",
"options",
")",
";",
"obs",
".",
"observe",
"(",
"el",
")",
";",
"return",
"obs",
";",
"}",
")",
";",
"}"
] | progress progress tracker | [
"progress",
"progress",
"tracker"
] | 486c14807c43d284eaaf2118e52b116798e618b9 | https://github.com/russellgoldenberg/scrollama/blob/486c14807c43d284eaaf2118e52b116798e618b9/src/init.js#L391-L403 |
6,713 | jashkenas/backbone | examples/backbone.localStorage.js | function(model) {
this.localStorage().setItem(this.name+"-"+model.id, JSON.stringify(model));
if (!_.include(this.records, model.id.toString()))
this.records.push(model.id.toString()); this.save();
return this.find(model);
} | javascript | function(model) {
this.localStorage().setItem(this.name+"-"+model.id, JSON.stringify(model));
if (!_.include(this.records, model.id.toString()))
this.records.push(model.id.toString()); this.save();
return this.find(model);
} | [
"function",
"(",
"model",
")",
"{",
"this",
".",
"localStorage",
"(",
")",
".",
"setItem",
"(",
"this",
".",
"name",
"+",
"\"-\"",
"+",
"model",
".",
"id",
",",
"JSON",
".",
"stringify",
"(",
"model",
")",
")",
";",
"if",
"(",
"!",
"_",
".",
"include",
"(",
"this",
".",
"records",
",",
"model",
".",
"id",
".",
"toString",
"(",
")",
")",
")",
"this",
".",
"records",
".",
"push",
"(",
"model",
".",
"id",
".",
"toString",
"(",
")",
")",
";",
"this",
".",
"save",
"(",
")",
";",
"return",
"this",
".",
"find",
"(",
"model",
")",
";",
"}"
] | Update a model by replacing its copy in `this.data`. | [
"Update",
"a",
"model",
"by",
"replacing",
"its",
"copy",
"in",
"this",
".",
"data",
"."
] | 75e6d0ce6394bd2b809823c7f7dc014ddb6ae287 | https://github.com/jashkenas/backbone/blob/75e6d0ce6394bd2b809823c7f7dc014ddb6ae287/examples/backbone.localStorage.js#L66-L71 |
|
6,714 | jashkenas/backbone | examples/backbone.localStorage.js | function() {
return _(this.records).chain()
.map(function(id){
return this.jsonData(this.localStorage().getItem(this.name+"-"+id));
}, this)
.compact()
.value();
} | javascript | function() {
return _(this.records).chain()
.map(function(id){
return this.jsonData(this.localStorage().getItem(this.name+"-"+id));
}, this)
.compact()
.value();
} | [
"function",
"(",
")",
"{",
"return",
"_",
"(",
"this",
".",
"records",
")",
".",
"chain",
"(",
")",
".",
"map",
"(",
"function",
"(",
"id",
")",
"{",
"return",
"this",
".",
"jsonData",
"(",
"this",
".",
"localStorage",
"(",
")",
".",
"getItem",
"(",
"this",
".",
"name",
"+",
"\"-\"",
"+",
"id",
")",
")",
";",
"}",
",",
"this",
")",
".",
"compact",
"(",
")",
".",
"value",
"(",
")",
";",
"}"
] | Return the array of all models currently in storage. | [
"Return",
"the",
"array",
"of",
"all",
"models",
"currently",
"in",
"storage",
"."
] | 75e6d0ce6394bd2b809823c7f7dc014ddb6ae287 | https://github.com/jashkenas/backbone/blob/75e6d0ce6394bd2b809823c7f7dc014ddb6ae287/examples/backbone.localStorage.js#L79-L86 |
|
6,715 | jashkenas/backbone | examples/backbone.localStorage.js | function(model) {
if (model.isNew())
return false
this.localStorage().removeItem(this.name+"-"+model.id);
this.records = _.reject(this.records, function(id){
return id === model.id.toString();
});
this.save();
return model;
} | javascript | function(model) {
if (model.isNew())
return false
this.localStorage().removeItem(this.name+"-"+model.id);
this.records = _.reject(this.records, function(id){
return id === model.id.toString();
});
this.save();
return model;
} | [
"function",
"(",
"model",
")",
"{",
"if",
"(",
"model",
".",
"isNew",
"(",
")",
")",
"return",
"false",
"this",
".",
"localStorage",
"(",
")",
".",
"removeItem",
"(",
"this",
".",
"name",
"+",
"\"-\"",
"+",
"model",
".",
"id",
")",
";",
"this",
".",
"records",
"=",
"_",
".",
"reject",
"(",
"this",
".",
"records",
",",
"function",
"(",
"id",
")",
"{",
"return",
"id",
"===",
"model",
".",
"id",
".",
"toString",
"(",
")",
";",
"}",
")",
";",
"this",
".",
"save",
"(",
")",
";",
"return",
"model",
";",
"}"
] | Delete a model from `this.data`, returning it. | [
"Delete",
"a",
"model",
"from",
"this",
".",
"data",
"returning",
"it",
"."
] | 75e6d0ce6394bd2b809823c7f7dc014ddb6ae287 | https://github.com/jashkenas/backbone/blob/75e6d0ce6394bd2b809823c7f7dc014ddb6ae287/examples/backbone.localStorage.js#L89-L98 |
|
6,716 | mozilla/nunjucks | docs/bower_components/bootstrap/assets/js/jszip.js | function (name, data, o) {
// be sure sub folders exist
var parent = parentFolder(name), dataType = JSZip.utils.getTypeOf(data);
if (parent) {
folderAdd.call(this, parent);
}
o = prepareFileAttrs(o);
if (o.dir || data === null || typeof data === "undefined") {
o.base64 = false;
o.binary = false;
data = null;
} else if (dataType === "string") {
if (o.binary && !o.base64) {
// optimizedBinaryString == true means that the file has already been filtered with a 0xFF mask
if (o.optimizedBinaryString !== true) {
// this is a string, not in a base64 format.
// Be sure that this is a correct "binary string"
data = JSZip.utils.string2binary(data);
}
}
} else { // arraybuffer, uint8array, ...
o.base64 = false;
o.binary = true;
if (!dataType && !(data instanceof JSZip.CompressedObject)) {
throw new Error("The data of '" + name + "' is in an unsupported format !");
}
// special case : it's way easier to work with Uint8Array than with ArrayBuffer
if (dataType === "arraybuffer") {
data = JSZip.utils.transformTo("uint8array", data);
}
}
return this.files[name] = new ZipObject(name, data, o);
} | javascript | function (name, data, o) {
// be sure sub folders exist
var parent = parentFolder(name), dataType = JSZip.utils.getTypeOf(data);
if (parent) {
folderAdd.call(this, parent);
}
o = prepareFileAttrs(o);
if (o.dir || data === null || typeof data === "undefined") {
o.base64 = false;
o.binary = false;
data = null;
} else if (dataType === "string") {
if (o.binary && !o.base64) {
// optimizedBinaryString == true means that the file has already been filtered with a 0xFF mask
if (o.optimizedBinaryString !== true) {
// this is a string, not in a base64 format.
// Be sure that this is a correct "binary string"
data = JSZip.utils.string2binary(data);
}
}
} else { // arraybuffer, uint8array, ...
o.base64 = false;
o.binary = true;
if (!dataType && !(data instanceof JSZip.CompressedObject)) {
throw new Error("The data of '" + name + "' is in an unsupported format !");
}
// special case : it's way easier to work with Uint8Array than with ArrayBuffer
if (dataType === "arraybuffer") {
data = JSZip.utils.transformTo("uint8array", data);
}
}
return this.files[name] = new ZipObject(name, data, o);
} | [
"function",
"(",
"name",
",",
"data",
",",
"o",
")",
"{",
"// be sure sub folders exist",
"var",
"parent",
"=",
"parentFolder",
"(",
"name",
")",
",",
"dataType",
"=",
"JSZip",
".",
"utils",
".",
"getTypeOf",
"(",
"data",
")",
";",
"if",
"(",
"parent",
")",
"{",
"folderAdd",
".",
"call",
"(",
"this",
",",
"parent",
")",
";",
"}",
"o",
"=",
"prepareFileAttrs",
"(",
"o",
")",
";",
"if",
"(",
"o",
".",
"dir",
"||",
"data",
"===",
"null",
"||",
"typeof",
"data",
"===",
"\"undefined\"",
")",
"{",
"o",
".",
"base64",
"=",
"false",
";",
"o",
".",
"binary",
"=",
"false",
";",
"data",
"=",
"null",
";",
"}",
"else",
"if",
"(",
"dataType",
"===",
"\"string\"",
")",
"{",
"if",
"(",
"o",
".",
"binary",
"&&",
"!",
"o",
".",
"base64",
")",
"{",
"// optimizedBinaryString == true means that the file has already been filtered with a 0xFF mask",
"if",
"(",
"o",
".",
"optimizedBinaryString",
"!==",
"true",
")",
"{",
"// this is a string, not in a base64 format.",
"// Be sure that this is a correct \"binary string\"",
"data",
"=",
"JSZip",
".",
"utils",
".",
"string2binary",
"(",
"data",
")",
";",
"}",
"}",
"}",
"else",
"{",
"// arraybuffer, uint8array, ...",
"o",
".",
"base64",
"=",
"false",
";",
"o",
".",
"binary",
"=",
"true",
";",
"if",
"(",
"!",
"dataType",
"&&",
"!",
"(",
"data",
"instanceof",
"JSZip",
".",
"CompressedObject",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"The data of '\"",
"+",
"name",
"+",
"\"' is in an unsupported format !\"",
")",
";",
"}",
"// special case : it's way easier to work with Uint8Array than with ArrayBuffer",
"if",
"(",
"dataType",
"===",
"\"arraybuffer\"",
")",
"{",
"data",
"=",
"JSZip",
".",
"utils",
".",
"transformTo",
"(",
"\"uint8array\"",
",",
"data",
")",
";",
"}",
"}",
"return",
"this",
".",
"files",
"[",
"name",
"]",
"=",
"new",
"ZipObject",
"(",
"name",
",",
"data",
",",
"o",
")",
";",
"}"
] | Add a file in the current folder.
@private
@param {string} name the name of the file
@param {String|ArrayBuffer|Uint8Array|Buffer} data the data of the file
@param {Object} o the options of the file
@return {Object} the new file. | [
"Add",
"a",
"file",
"in",
"the",
"current",
"folder",
"."
] | 224645791298db835df0acff3dc596d3a9ed2c4d | https://github.com/mozilla/nunjucks/blob/224645791298db835df0acff3dc596d3a9ed2c4d/docs/bower_components/bootstrap/assets/js/jszip.js#L254-L291 |
|
6,717 | mozilla/nunjucks | docs/bower_components/bootstrap/assets/js/jszip.js | function (file, compression) {
var result = new JSZip.CompressedObject(), content;
// the data has not been decompressed, we might reuse things !
if (file._data instanceof JSZip.CompressedObject) {
result.uncompressedSize = file._data.uncompressedSize;
result.crc32 = file._data.crc32;
if (result.uncompressedSize === 0 || file.options.dir) {
compression = JSZip.compressions['STORE'];
result.compressedContent = "";
result.crc32 = 0;
} else if (file._data.compressionMethod === compression.magic) {
result.compressedContent = file._data.getCompressedContent();
} else {
content = file._data.getContent()
// need to decompress / recompress
result.compressedContent = compression.compress(JSZip.utils.transformTo(compression.compressInputType, content));
}
} else {
// have uncompressed data
content = getBinaryData(file);
if (!content || content.length === 0 || file.options.dir) {
compression = JSZip.compressions['STORE'];
content = "";
}
result.uncompressedSize = content.length;
result.crc32 = this.crc32(content);
result.compressedContent = compression.compress(JSZip.utils.transformTo(compression.compressInputType, content));
}
result.compressedSize = result.compressedContent.length;
result.compressionMethod = compression.magic;
return result;
} | javascript | function (file, compression) {
var result = new JSZip.CompressedObject(), content;
// the data has not been decompressed, we might reuse things !
if (file._data instanceof JSZip.CompressedObject) {
result.uncompressedSize = file._data.uncompressedSize;
result.crc32 = file._data.crc32;
if (result.uncompressedSize === 0 || file.options.dir) {
compression = JSZip.compressions['STORE'];
result.compressedContent = "";
result.crc32 = 0;
} else if (file._data.compressionMethod === compression.magic) {
result.compressedContent = file._data.getCompressedContent();
} else {
content = file._data.getContent()
// need to decompress / recompress
result.compressedContent = compression.compress(JSZip.utils.transformTo(compression.compressInputType, content));
}
} else {
// have uncompressed data
content = getBinaryData(file);
if (!content || content.length === 0 || file.options.dir) {
compression = JSZip.compressions['STORE'];
content = "";
}
result.uncompressedSize = content.length;
result.crc32 = this.crc32(content);
result.compressedContent = compression.compress(JSZip.utils.transformTo(compression.compressInputType, content));
}
result.compressedSize = result.compressedContent.length;
result.compressionMethod = compression.magic;
return result;
} | [
"function",
"(",
"file",
",",
"compression",
")",
"{",
"var",
"result",
"=",
"new",
"JSZip",
".",
"CompressedObject",
"(",
")",
",",
"content",
";",
"// the data has not been decompressed, we might reuse things !",
"if",
"(",
"file",
".",
"_data",
"instanceof",
"JSZip",
".",
"CompressedObject",
")",
"{",
"result",
".",
"uncompressedSize",
"=",
"file",
".",
"_data",
".",
"uncompressedSize",
";",
"result",
".",
"crc32",
"=",
"file",
".",
"_data",
".",
"crc32",
";",
"if",
"(",
"result",
".",
"uncompressedSize",
"===",
"0",
"||",
"file",
".",
"options",
".",
"dir",
")",
"{",
"compression",
"=",
"JSZip",
".",
"compressions",
"[",
"'STORE'",
"]",
";",
"result",
".",
"compressedContent",
"=",
"\"\"",
";",
"result",
".",
"crc32",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"file",
".",
"_data",
".",
"compressionMethod",
"===",
"compression",
".",
"magic",
")",
"{",
"result",
".",
"compressedContent",
"=",
"file",
".",
"_data",
".",
"getCompressedContent",
"(",
")",
";",
"}",
"else",
"{",
"content",
"=",
"file",
".",
"_data",
".",
"getContent",
"(",
")",
"// need to decompress / recompress",
"result",
".",
"compressedContent",
"=",
"compression",
".",
"compress",
"(",
"JSZip",
".",
"utils",
".",
"transformTo",
"(",
"compression",
".",
"compressInputType",
",",
"content",
")",
")",
";",
"}",
"}",
"else",
"{",
"// have uncompressed data",
"content",
"=",
"getBinaryData",
"(",
"file",
")",
";",
"if",
"(",
"!",
"content",
"||",
"content",
".",
"length",
"===",
"0",
"||",
"file",
".",
"options",
".",
"dir",
")",
"{",
"compression",
"=",
"JSZip",
".",
"compressions",
"[",
"'STORE'",
"]",
";",
"content",
"=",
"\"\"",
";",
"}",
"result",
".",
"uncompressedSize",
"=",
"content",
".",
"length",
";",
"result",
".",
"crc32",
"=",
"this",
".",
"crc32",
"(",
"content",
")",
";",
"result",
".",
"compressedContent",
"=",
"compression",
".",
"compress",
"(",
"JSZip",
".",
"utils",
".",
"transformTo",
"(",
"compression",
".",
"compressInputType",
",",
"content",
")",
")",
";",
"}",
"result",
".",
"compressedSize",
"=",
"result",
".",
"compressedContent",
".",
"length",
";",
"result",
".",
"compressionMethod",
"=",
"compression",
".",
"magic",
";",
"return",
"result",
";",
"}"
] | Generate a JSZip.CompressedObject for a given zipOject.
@param {ZipObject} file the object to read.
@param {JSZip.compression} compression the compression to use.
@return {JSZip.CompressedObject} the compressed result. | [
"Generate",
"a",
"JSZip",
".",
"CompressedObject",
"for",
"a",
"given",
"zipOject",
"."
] | 224645791298db835df0acff3dc596d3a9ed2c4d | https://github.com/mozilla/nunjucks/blob/224645791298db835df0acff3dc596d3a9ed2c4d/docs/bower_components/bootstrap/assets/js/jszip.js#L333-L368 |
|
6,718 | mozilla/nunjucks | docs/bower_components/bootstrap/assets/js/jszip.js | function(name, file, compressedObject, offset) {
var data = compressedObject.compressedContent,
utfEncodedFileName = this.utf8encode(file.name),
useUTF8 = utfEncodedFileName !== file.name,
o = file.options,
dosTime,
dosDate;
// date
// @see http://www.delorie.com/djgpp/doc/rbinter/it/52/13.html
// @see http://www.delorie.com/djgpp/doc/rbinter/it/65/16.html
// @see http://www.delorie.com/djgpp/doc/rbinter/it/66/16.html
dosTime = o.date.getHours();
dosTime = dosTime << 6;
dosTime = dosTime | o.date.getMinutes();
dosTime = dosTime << 5;
dosTime = dosTime | o.date.getSeconds() / 2;
dosDate = o.date.getFullYear() - 1980;
dosDate = dosDate << 4;
dosDate = dosDate | (o.date.getMonth() + 1);
dosDate = dosDate << 5;
dosDate = dosDate | o.date.getDate();
var header = "";
// version needed to extract
header += "\x0A\x00";
// general purpose bit flag
// set bit 11 if utf8
header += useUTF8 ? "\x00\x08" : "\x00\x00";
// compression method
header += compressedObject.compressionMethod;
// last mod file time
header += decToHex(dosTime, 2);
// last mod file date
header += decToHex(dosDate, 2);
// crc-32
header += decToHex(compressedObject.crc32, 4);
// compressed size
header += decToHex(compressedObject.compressedSize, 4);
// uncompressed size
header += decToHex(compressedObject.uncompressedSize, 4);
// file name length
header += decToHex(utfEncodedFileName.length, 2);
// extra field length
header += "\x00\x00";
var fileRecord = JSZip.signature.LOCAL_FILE_HEADER + header + utfEncodedFileName;
var dirRecord = JSZip.signature.CENTRAL_FILE_HEADER +
// version made by (00: DOS)
"\x14\x00" +
// file header (common to file and central directory)
header +
// file comment length
"\x00\x00" +
// disk number start
"\x00\x00" +
// internal file attributes TODO
"\x00\x00" +
// external file attributes
(file.options.dir===true?"\x10\x00\x00\x00":"\x00\x00\x00\x00")+
// relative offset of local header
decToHex(offset, 4) +
// file name
utfEncodedFileName;
return {
fileRecord : fileRecord,
dirRecord : dirRecord,
compressedObject : compressedObject
};
} | javascript | function(name, file, compressedObject, offset) {
var data = compressedObject.compressedContent,
utfEncodedFileName = this.utf8encode(file.name),
useUTF8 = utfEncodedFileName !== file.name,
o = file.options,
dosTime,
dosDate;
// date
// @see http://www.delorie.com/djgpp/doc/rbinter/it/52/13.html
// @see http://www.delorie.com/djgpp/doc/rbinter/it/65/16.html
// @see http://www.delorie.com/djgpp/doc/rbinter/it/66/16.html
dosTime = o.date.getHours();
dosTime = dosTime << 6;
dosTime = dosTime | o.date.getMinutes();
dosTime = dosTime << 5;
dosTime = dosTime | o.date.getSeconds() / 2;
dosDate = o.date.getFullYear() - 1980;
dosDate = dosDate << 4;
dosDate = dosDate | (o.date.getMonth() + 1);
dosDate = dosDate << 5;
dosDate = dosDate | o.date.getDate();
var header = "";
// version needed to extract
header += "\x0A\x00";
// general purpose bit flag
// set bit 11 if utf8
header += useUTF8 ? "\x00\x08" : "\x00\x00";
// compression method
header += compressedObject.compressionMethod;
// last mod file time
header += decToHex(dosTime, 2);
// last mod file date
header += decToHex(dosDate, 2);
// crc-32
header += decToHex(compressedObject.crc32, 4);
// compressed size
header += decToHex(compressedObject.compressedSize, 4);
// uncompressed size
header += decToHex(compressedObject.uncompressedSize, 4);
// file name length
header += decToHex(utfEncodedFileName.length, 2);
// extra field length
header += "\x00\x00";
var fileRecord = JSZip.signature.LOCAL_FILE_HEADER + header + utfEncodedFileName;
var dirRecord = JSZip.signature.CENTRAL_FILE_HEADER +
// version made by (00: DOS)
"\x14\x00" +
// file header (common to file and central directory)
header +
// file comment length
"\x00\x00" +
// disk number start
"\x00\x00" +
// internal file attributes TODO
"\x00\x00" +
// external file attributes
(file.options.dir===true?"\x10\x00\x00\x00":"\x00\x00\x00\x00")+
// relative offset of local header
decToHex(offset, 4) +
// file name
utfEncodedFileName;
return {
fileRecord : fileRecord,
dirRecord : dirRecord,
compressedObject : compressedObject
};
} | [
"function",
"(",
"name",
",",
"file",
",",
"compressedObject",
",",
"offset",
")",
"{",
"var",
"data",
"=",
"compressedObject",
".",
"compressedContent",
",",
"utfEncodedFileName",
"=",
"this",
".",
"utf8encode",
"(",
"file",
".",
"name",
")",
",",
"useUTF8",
"=",
"utfEncodedFileName",
"!==",
"file",
".",
"name",
",",
"o",
"=",
"file",
".",
"options",
",",
"dosTime",
",",
"dosDate",
";",
"// date",
"// @see http://www.delorie.com/djgpp/doc/rbinter/it/52/13.html",
"// @see http://www.delorie.com/djgpp/doc/rbinter/it/65/16.html",
"// @see http://www.delorie.com/djgpp/doc/rbinter/it/66/16.html",
"dosTime",
"=",
"o",
".",
"date",
".",
"getHours",
"(",
")",
";",
"dosTime",
"=",
"dosTime",
"<<",
"6",
";",
"dosTime",
"=",
"dosTime",
"|",
"o",
".",
"date",
".",
"getMinutes",
"(",
")",
";",
"dosTime",
"=",
"dosTime",
"<<",
"5",
";",
"dosTime",
"=",
"dosTime",
"|",
"o",
".",
"date",
".",
"getSeconds",
"(",
")",
"/",
"2",
";",
"dosDate",
"=",
"o",
".",
"date",
".",
"getFullYear",
"(",
")",
"-",
"1980",
";",
"dosDate",
"=",
"dosDate",
"<<",
"4",
";",
"dosDate",
"=",
"dosDate",
"|",
"(",
"o",
".",
"date",
".",
"getMonth",
"(",
")",
"+",
"1",
")",
";",
"dosDate",
"=",
"dosDate",
"<<",
"5",
";",
"dosDate",
"=",
"dosDate",
"|",
"o",
".",
"date",
".",
"getDate",
"(",
")",
";",
"var",
"header",
"=",
"\"\"",
";",
"// version needed to extract",
"header",
"+=",
"\"\\x0A\\x00\"",
";",
"// general purpose bit flag",
"// set bit 11 if utf8",
"header",
"+=",
"useUTF8",
"?",
"\"\\x00\\x08\"",
":",
"\"\\x00\\x00\"",
";",
"// compression method",
"header",
"+=",
"compressedObject",
".",
"compressionMethod",
";",
"// last mod file time",
"header",
"+=",
"decToHex",
"(",
"dosTime",
",",
"2",
")",
";",
"// last mod file date",
"header",
"+=",
"decToHex",
"(",
"dosDate",
",",
"2",
")",
";",
"// crc-32",
"header",
"+=",
"decToHex",
"(",
"compressedObject",
".",
"crc32",
",",
"4",
")",
";",
"// compressed size",
"header",
"+=",
"decToHex",
"(",
"compressedObject",
".",
"compressedSize",
",",
"4",
")",
";",
"// uncompressed size",
"header",
"+=",
"decToHex",
"(",
"compressedObject",
".",
"uncompressedSize",
",",
"4",
")",
";",
"// file name length",
"header",
"+=",
"decToHex",
"(",
"utfEncodedFileName",
".",
"length",
",",
"2",
")",
";",
"// extra field length",
"header",
"+=",
"\"\\x00\\x00\"",
";",
"var",
"fileRecord",
"=",
"JSZip",
".",
"signature",
".",
"LOCAL_FILE_HEADER",
"+",
"header",
"+",
"utfEncodedFileName",
";",
"var",
"dirRecord",
"=",
"JSZip",
".",
"signature",
".",
"CENTRAL_FILE_HEADER",
"+",
"// version made by (00: DOS)",
"\"\\x14\\x00\"",
"+",
"// file header (common to file and central directory)",
"header",
"+",
"// file comment length",
"\"\\x00\\x00\"",
"+",
"// disk number start",
"\"\\x00\\x00\"",
"+",
"// internal file attributes TODO",
"\"\\x00\\x00\"",
"+",
"// external file attributes",
"(",
"file",
".",
"options",
".",
"dir",
"===",
"true",
"?",
"\"\\x10\\x00\\x00\\x00\"",
":",
"\"\\x00\\x00\\x00\\x00\"",
")",
"+",
"// relative offset of local header",
"decToHex",
"(",
"offset",
",",
"4",
")",
"+",
"// file name",
"utfEncodedFileName",
";",
"return",
"{",
"fileRecord",
":",
"fileRecord",
",",
"dirRecord",
":",
"dirRecord",
",",
"compressedObject",
":",
"compressedObject",
"}",
";",
"}"
] | Generate the various parts used in the construction of the final zip file.
@param {string} name the file name.
@param {ZipObject} file the file content.
@param {JSZip.CompressedObject} compressedObject the compressed object.
@param {number} offset the current offset from the start of the zip file.
@return {object} the zip parts. | [
"Generate",
"the",
"various",
"parts",
"used",
"in",
"the",
"construction",
"of",
"the",
"final",
"zip",
"file",
"."
] | 224645791298db835df0acff3dc596d3a9ed2c4d | https://github.com/mozilla/nunjucks/blob/224645791298db835df0acff3dc596d3a9ed2c4d/docs/bower_components/bootstrap/assets/js/jszip.js#L378-L455 |
|
6,719 | mozilla/nunjucks | docs/bower_components/bootstrap/assets/js/jszip.js | function(arg) {
if (!arg) {
return this;
}
if (arg instanceof RegExp) {
return this.filter(function(relativePath, file) {
return file.options.dir && arg.test(relativePath);
});
}
// else, name is a new folder
var name = this.root + arg;
var newFolder = folderAdd.call(this, name);
// Allow chaining by returning a new object with this folder as the root
var ret = this.clone();
ret.root = newFolder.name;
return ret;
} | javascript | function(arg) {
if (!arg) {
return this;
}
if (arg instanceof RegExp) {
return this.filter(function(relativePath, file) {
return file.options.dir && arg.test(relativePath);
});
}
// else, name is a new folder
var name = this.root + arg;
var newFolder = folderAdd.call(this, name);
// Allow chaining by returning a new object with this folder as the root
var ret = this.clone();
ret.root = newFolder.name;
return ret;
} | [
"function",
"(",
"arg",
")",
"{",
"if",
"(",
"!",
"arg",
")",
"{",
"return",
"this",
";",
"}",
"if",
"(",
"arg",
"instanceof",
"RegExp",
")",
"{",
"return",
"this",
".",
"filter",
"(",
"function",
"(",
"relativePath",
",",
"file",
")",
"{",
"return",
"file",
".",
"options",
".",
"dir",
"&&",
"arg",
".",
"test",
"(",
"relativePath",
")",
";",
"}",
")",
";",
"}",
"// else, name is a new folder",
"var",
"name",
"=",
"this",
".",
"root",
"+",
"arg",
";",
"var",
"newFolder",
"=",
"folderAdd",
".",
"call",
"(",
"this",
",",
"name",
")",
";",
"// Allow chaining by returning a new object with this folder as the root",
"var",
"ret",
"=",
"this",
".",
"clone",
"(",
")",
";",
"ret",
".",
"root",
"=",
"newFolder",
".",
"name",
";",
"return",
"ret",
";",
"}"
] | Add a directory to the zip file, or search.
@param {String|RegExp} arg The name of the directory to add, or a regex to search folders.
@return {JSZip} an object with the new directory as the root, or an array containing matching folders. | [
"Add",
"a",
"directory",
"to",
"the",
"zip",
"file",
"or",
"search",
"."
] | 224645791298db835df0acff3dc596d3a9ed2c4d | https://github.com/mozilla/nunjucks/blob/224645791298db835df0acff3dc596d3a9ed2c4d/docs/bower_components/bootstrap/assets/js/jszip.js#L582-L601 |
|
6,720 | mozilla/nunjucks | docs/bower_components/bootstrap/assets/js/jszip.js | function (buffer) {
JSZip.utils.checkSupport("blob");
try {
// Blob constructor
return new Blob([buffer], { type: "application/zip" });
}
catch(e) {}
try {
// deprecated, browser only, old way
var builder = new (window.BlobBuilder || window.WebKitBlobBuilder ||
window.MozBlobBuilder || window.MSBlobBuilder)();
builder.append(buffer);
return builder.getBlob('application/zip');
}
catch(e) {}
// well, fuck ?!
throw new Error("Bug : can't construct the Blob.");
} | javascript | function (buffer) {
JSZip.utils.checkSupport("blob");
try {
// Blob constructor
return new Blob([buffer], { type: "application/zip" });
}
catch(e) {}
try {
// deprecated, browser only, old way
var builder = new (window.BlobBuilder || window.WebKitBlobBuilder ||
window.MozBlobBuilder || window.MSBlobBuilder)();
builder.append(buffer);
return builder.getBlob('application/zip');
}
catch(e) {}
// well, fuck ?!
throw new Error("Bug : can't construct the Blob.");
} | [
"function",
"(",
"buffer",
")",
"{",
"JSZip",
".",
"utils",
".",
"checkSupport",
"(",
"\"blob\"",
")",
";",
"try",
"{",
"// Blob constructor",
"return",
"new",
"Blob",
"(",
"[",
"buffer",
"]",
",",
"{",
"type",
":",
"\"application/zip\"",
"}",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"try",
"{",
"// deprecated, browser only, old way",
"var",
"builder",
"=",
"new",
"(",
"window",
".",
"BlobBuilder",
"||",
"window",
".",
"WebKitBlobBuilder",
"||",
"window",
".",
"MozBlobBuilder",
"||",
"window",
".",
"MSBlobBuilder",
")",
"(",
")",
";",
"builder",
".",
"append",
"(",
"buffer",
")",
";",
"return",
"builder",
".",
"getBlob",
"(",
"'application/zip'",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"// well, fuck ?!",
"throw",
"new",
"Error",
"(",
"\"Bug : can't construct the Blob.\"",
")",
";",
"}"
] | Create a blob from the given ArrayBuffer.
@param {ArrayBuffer} buffer the buffer to transform.
@return {Blob} the result.
@throws {Error} an Error if the browser doesn't support the requested feature. | [
"Create",
"a",
"blob",
"from",
"the",
"given",
"ArrayBuffer",
"."
] | 224645791298db835df0acff3dc596d3a9ed2c4d | https://github.com/mozilla/nunjucks/blob/224645791298db835df0acff3dc596d3a9ed2c4d/docs/bower_components/bootstrap/assets/js/jszip.js#L1050-L1070 |
|
6,721 | mozilla/nunjucks | docs/bower_components/bootstrap/assets/js/jszip.js | function (str) {
var buffer = JSZip.utils.transformTo("arraybuffer", str);
return JSZip.utils.arrayBuffer2Blob(buffer);
} | javascript | function (str) {
var buffer = JSZip.utils.transformTo("arraybuffer", str);
return JSZip.utils.arrayBuffer2Blob(buffer);
} | [
"function",
"(",
"str",
")",
"{",
"var",
"buffer",
"=",
"JSZip",
".",
"utils",
".",
"transformTo",
"(",
"\"arraybuffer\"",
",",
"str",
")",
";",
"return",
"JSZip",
".",
"utils",
".",
"arrayBuffer2Blob",
"(",
"buffer",
")",
";",
"}"
] | Create a blob from the given string.
@param {string} str the string to transform.
@return {Blob} the result.
@throws {Error} an Error if the browser doesn't support the requested feature. | [
"Create",
"a",
"blob",
"from",
"the",
"given",
"string",
"."
] | 224645791298db835df0acff3dc596d3a9ed2c4d | https://github.com/mozilla/nunjucks/blob/224645791298db835df0acff3dc596d3a9ed2c4d/docs/bower_components/bootstrap/assets/js/jszip.js#L1077-L1080 |
|
6,722 | mozilla/nunjucks | nunjucks/src/filters.js | dictsort | function dictsort(val, caseSensitive, by) {
if (!lib.isObject(val)) {
throw new lib.TemplateError('dictsort filter: val must be an object');
}
let array = [];
// deliberately include properties from the object's prototype
for (let k in val) { // eslint-disable-line guard-for-in, no-restricted-syntax
array.push([k, val[k]]);
}
let si;
if (by === undefined || by === 'key') {
si = 0;
} else if (by === 'value') {
si = 1;
} else {
throw new lib.TemplateError(
'dictsort filter: You can only sort by either key or value');
}
array.sort((t1, t2) => {
var a = t1[si];
var b = t2[si];
if (!caseSensitive) {
if (lib.isString(a)) {
a = a.toUpperCase();
}
if (lib.isString(b)) {
b = b.toUpperCase();
}
}
return a > b ? 1 : (a === b ? 0 : -1); // eslint-disable-line no-nested-ternary
});
return array;
} | javascript | function dictsort(val, caseSensitive, by) {
if (!lib.isObject(val)) {
throw new lib.TemplateError('dictsort filter: val must be an object');
}
let array = [];
// deliberately include properties from the object's prototype
for (let k in val) { // eslint-disable-line guard-for-in, no-restricted-syntax
array.push([k, val[k]]);
}
let si;
if (by === undefined || by === 'key') {
si = 0;
} else if (by === 'value') {
si = 1;
} else {
throw new lib.TemplateError(
'dictsort filter: You can only sort by either key or value');
}
array.sort((t1, t2) => {
var a = t1[si];
var b = t2[si];
if (!caseSensitive) {
if (lib.isString(a)) {
a = a.toUpperCase();
}
if (lib.isString(b)) {
b = b.toUpperCase();
}
}
return a > b ? 1 : (a === b ? 0 : -1); // eslint-disable-line no-nested-ternary
});
return array;
} | [
"function",
"dictsort",
"(",
"val",
",",
"caseSensitive",
",",
"by",
")",
"{",
"if",
"(",
"!",
"lib",
".",
"isObject",
"(",
"val",
")",
")",
"{",
"throw",
"new",
"lib",
".",
"TemplateError",
"(",
"'dictsort filter: val must be an object'",
")",
";",
"}",
"let",
"array",
"=",
"[",
"]",
";",
"// deliberately include properties from the object's prototype",
"for",
"(",
"let",
"k",
"in",
"val",
")",
"{",
"// eslint-disable-line guard-for-in, no-restricted-syntax",
"array",
".",
"push",
"(",
"[",
"k",
",",
"val",
"[",
"k",
"]",
"]",
")",
";",
"}",
"let",
"si",
";",
"if",
"(",
"by",
"===",
"undefined",
"||",
"by",
"===",
"'key'",
")",
"{",
"si",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"by",
"===",
"'value'",
")",
"{",
"si",
"=",
"1",
";",
"}",
"else",
"{",
"throw",
"new",
"lib",
".",
"TemplateError",
"(",
"'dictsort filter: You can only sort by either key or value'",
")",
";",
"}",
"array",
".",
"sort",
"(",
"(",
"t1",
",",
"t2",
")",
"=>",
"{",
"var",
"a",
"=",
"t1",
"[",
"si",
"]",
";",
"var",
"b",
"=",
"t2",
"[",
"si",
"]",
";",
"if",
"(",
"!",
"caseSensitive",
")",
"{",
"if",
"(",
"lib",
".",
"isString",
"(",
"a",
")",
")",
"{",
"a",
"=",
"a",
".",
"toUpperCase",
"(",
")",
";",
"}",
"if",
"(",
"lib",
".",
"isString",
"(",
"b",
")",
")",
"{",
"b",
"=",
"b",
".",
"toUpperCase",
"(",
")",
";",
"}",
"}",
"return",
"a",
">",
"b",
"?",
"1",
":",
"(",
"a",
"===",
"b",
"?",
"0",
":",
"-",
"1",
")",
";",
"// eslint-disable-line no-nested-ternary",
"}",
")",
";",
"return",
"array",
";",
"}"
] | eslint-disable-line dot-notation | [
"eslint",
"-",
"disable",
"-",
"line",
"dot",
"-",
"notation"
] | 224645791298db835df0acff3dc596d3a9ed2c4d | https://github.com/mozilla/nunjucks/blob/224645791298db835df0acff3dc596d3a9ed2c4d/nunjucks/src/filters.js#L85-L123 |
6,723 | drichard/mindmaps | src/js/ApplicationController.js | doNewDocument | function doNewDocument() {
// close old document first
var doc = mindmapModel.getDocument();
doCloseDocument();
var presenter = new mindmaps.NewDocumentPresenter(eventBus,
mindmapModel, new mindmaps.NewDocumentView());
presenter.go();
} | javascript | function doNewDocument() {
// close old document first
var doc = mindmapModel.getDocument();
doCloseDocument();
var presenter = new mindmaps.NewDocumentPresenter(eventBus,
mindmapModel, new mindmaps.NewDocumentView());
presenter.go();
} | [
"function",
"doNewDocument",
"(",
")",
"{",
"// close old document first",
"var",
"doc",
"=",
"mindmapModel",
".",
"getDocument",
"(",
")",
";",
"doCloseDocument",
"(",
")",
";",
"var",
"presenter",
"=",
"new",
"mindmaps",
".",
"NewDocumentPresenter",
"(",
"eventBus",
",",
"mindmapModel",
",",
"new",
"mindmaps",
".",
"NewDocumentView",
"(",
")",
")",
";",
"presenter",
".",
"go",
"(",
")",
";",
"}"
] | Handles the new document command. | [
"Handles",
"the",
"new",
"document",
"command",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/ApplicationController.js#L23-L31 |
6,724 | drichard/mindmaps | src/js/ApplicationController.js | doSaveDocument | function doSaveDocument() {
var presenter = new mindmaps.SaveDocumentPresenter(eventBus,
mindmapModel, new mindmaps.SaveDocumentView(), autosaveController, filePicker);
presenter.go();
} | javascript | function doSaveDocument() {
var presenter = new mindmaps.SaveDocumentPresenter(eventBus,
mindmapModel, new mindmaps.SaveDocumentView(), autosaveController, filePicker);
presenter.go();
} | [
"function",
"doSaveDocument",
"(",
")",
"{",
"var",
"presenter",
"=",
"new",
"mindmaps",
".",
"SaveDocumentPresenter",
"(",
"eventBus",
",",
"mindmapModel",
",",
"new",
"mindmaps",
".",
"SaveDocumentView",
"(",
")",
",",
"autosaveController",
",",
"filePicker",
")",
";",
"presenter",
".",
"go",
"(",
")",
";",
"}"
] | Handles the save document command. | [
"Handles",
"the",
"save",
"document",
"command",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/ApplicationController.js#L36-L40 |
6,725 | drichard/mindmaps | src/js/ApplicationController.js | doOpenDocument | function doOpenDocument() {
var presenter = new mindmaps.OpenDocumentPresenter(eventBus,
mindmapModel, new mindmaps.OpenDocumentView(), filePicker);
presenter.go();
} | javascript | function doOpenDocument() {
var presenter = new mindmaps.OpenDocumentPresenter(eventBus,
mindmapModel, new mindmaps.OpenDocumentView(), filePicker);
presenter.go();
} | [
"function",
"doOpenDocument",
"(",
")",
"{",
"var",
"presenter",
"=",
"new",
"mindmaps",
".",
"OpenDocumentPresenter",
"(",
"eventBus",
",",
"mindmapModel",
",",
"new",
"mindmaps",
".",
"OpenDocumentView",
"(",
")",
",",
"filePicker",
")",
";",
"presenter",
".",
"go",
"(",
")",
";",
"}"
] | Handles the open document command. | [
"Handles",
"the",
"open",
"document",
"command",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/ApplicationController.js#L57-L61 |
6,726 | drichard/mindmaps | src/js/Inspector.js | updateView | function updateView(node) {
var font = node.text.font;
view.setBoldCheckboxState(font.weight === "bold");
view.setItalicCheckboxState(font.style === "italic");
view.setUnderlineCheckboxState(font.decoration === "underline");
view.setLinethroughCheckboxState(font.decoration === "line-through");
view.setFontColorPickerColor(font.color);
view.setBranchColorPickerColor(node.branchColor);
} | javascript | function updateView(node) {
var font = node.text.font;
view.setBoldCheckboxState(font.weight === "bold");
view.setItalicCheckboxState(font.style === "italic");
view.setUnderlineCheckboxState(font.decoration === "underline");
view.setLinethroughCheckboxState(font.decoration === "line-through");
view.setFontColorPickerColor(font.color);
view.setBranchColorPickerColor(node.branchColor);
} | [
"function",
"updateView",
"(",
"node",
")",
"{",
"var",
"font",
"=",
"node",
".",
"text",
".",
"font",
";",
"view",
".",
"setBoldCheckboxState",
"(",
"font",
".",
"weight",
"===",
"\"bold\"",
")",
";",
"view",
".",
"setItalicCheckboxState",
"(",
"font",
".",
"style",
"===",
"\"italic\"",
")",
";",
"view",
".",
"setUnderlineCheckboxState",
"(",
"font",
".",
"decoration",
"===",
"\"underline\"",
")",
";",
"view",
".",
"setLinethroughCheckboxState",
"(",
"font",
".",
"decoration",
"===",
"\"line-through\"",
")",
";",
"view",
".",
"setFontColorPickerColor",
"(",
"font",
".",
"color",
")",
";",
"view",
".",
"setBranchColorPickerColor",
"(",
"node",
".",
"branchColor",
")",
";",
"}"
] | Sets the view params to match the node's attributes.
@param {mindmaps.Node} node | [
"Sets",
"the",
"view",
"params",
"to",
"match",
"the",
"node",
"s",
"attributes",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/Inspector.js#L320-L328 |
6,727 | drichard/mindmaps | src/js/Navigator.js | calculateDraggerSize | function calculateDraggerSize() {
var cw = $container.width() / scale;
var ch = $container.height() / scale;
// doc.x / container.x = canvas.x / dragger.x
var width = (cw * canvasSize.x) / docSize.x;
var height = (ch * canvasSize.y) / docSize.y;
// limit size to bounds of canvas
if (width > canvasSize.x) {
width = canvasSize.x;
}
if (height > canvasSize.y) {
height = canvasSize.y;
}
view.setDraggerSize(width, height);
} | javascript | function calculateDraggerSize() {
var cw = $container.width() / scale;
var ch = $container.height() / scale;
// doc.x / container.x = canvas.x / dragger.x
var width = (cw * canvasSize.x) / docSize.x;
var height = (ch * canvasSize.y) / docSize.y;
// limit size to bounds of canvas
if (width > canvasSize.x) {
width = canvasSize.x;
}
if (height > canvasSize.y) {
height = canvasSize.y;
}
view.setDraggerSize(width, height);
} | [
"function",
"calculateDraggerSize",
"(",
")",
"{",
"var",
"cw",
"=",
"$container",
".",
"width",
"(",
")",
"/",
"scale",
";",
"var",
"ch",
"=",
"$container",
".",
"height",
"(",
")",
"/",
"scale",
";",
"// doc.x / container.x = canvas.x / dragger.x\r",
"var",
"width",
"=",
"(",
"cw",
"*",
"canvasSize",
".",
"x",
")",
"/",
"docSize",
".",
"x",
";",
"var",
"height",
"=",
"(",
"ch",
"*",
"canvasSize",
".",
"y",
")",
"/",
"docSize",
".",
"y",
";",
"// limit size to bounds of canvas\r",
"if",
"(",
"width",
">",
"canvasSize",
".",
"x",
")",
"{",
"width",
"=",
"canvasSize",
".",
"x",
";",
"}",
"if",
"(",
"height",
">",
"canvasSize",
".",
"y",
")",
"{",
"height",
"=",
"canvasSize",
".",
"y",
";",
"}",
"view",
".",
"setDraggerSize",
"(",
"width",
",",
"height",
")",
";",
"}"
] | Calculates and sets the size of the dragger element. | [
"Calculates",
"and",
"sets",
"the",
"size",
"of",
"the",
"dragger",
"element",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/Navigator.js#L252-L269 |
6,728 | drichard/mindmaps | src/js/Navigator.js | calculateCanvasSize | function calculateCanvasSize() {
var width = view.getCanvasWidth();
var _scale = docSize.x / width;
var height = docSize.y / _scale;
view.setCanvasHeight(height);
canvasSize.x = width;
canvasSize.y = height;
} | javascript | function calculateCanvasSize() {
var width = view.getCanvasWidth();
var _scale = docSize.x / width;
var height = docSize.y / _scale;
view.setCanvasHeight(height);
canvasSize.x = width;
canvasSize.y = height;
} | [
"function",
"calculateCanvasSize",
"(",
")",
"{",
"var",
"width",
"=",
"view",
".",
"getCanvasWidth",
"(",
")",
";",
"var",
"_scale",
"=",
"docSize",
".",
"x",
"/",
"width",
";",
"var",
"height",
"=",
"docSize",
".",
"y",
"/",
"_scale",
";",
"view",
".",
"setCanvasHeight",
"(",
"height",
")",
";",
"canvasSize",
".",
"x",
"=",
"width",
";",
"canvasSize",
".",
"y",
"=",
"height",
";",
"}"
] | Calculates and sets the size of the mini canvas. | [
"Calculates",
"and",
"sets",
"the",
"size",
"of",
"the",
"mini",
"canvas",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/Navigator.js#L274-L283 |
6,729 | drichard/mindmaps | src/js/Navigator.js | calculateDraggerPosition | function calculateDraggerPosition() {
var sl = $container.scrollLeft() / scale;
var st = $container.scrollTop() / scale;
// sl / dox = dl / cw
// dl = sl * cw / dox
var left = sl * canvasSize.x / docSize.x;
var top = st * canvasSize.y / docSize.y;
view.setDraggerPosition(left, top);
} | javascript | function calculateDraggerPosition() {
var sl = $container.scrollLeft() / scale;
var st = $container.scrollTop() / scale;
// sl / dox = dl / cw
// dl = sl * cw / dox
var left = sl * canvasSize.x / docSize.x;
var top = st * canvasSize.y / docSize.y;
view.setDraggerPosition(left, top);
} | [
"function",
"calculateDraggerPosition",
"(",
")",
"{",
"var",
"sl",
"=",
"$container",
".",
"scrollLeft",
"(",
")",
"/",
"scale",
";",
"var",
"st",
"=",
"$container",
".",
"scrollTop",
"(",
")",
"/",
"scale",
";",
"// sl / dox = dl / cw\r",
"// dl = sl * cw / dox\r",
"var",
"left",
"=",
"sl",
"*",
"canvasSize",
".",
"x",
"/",
"docSize",
".",
"x",
";",
"var",
"top",
"=",
"st",
"*",
"canvasSize",
".",
"y",
"/",
"docSize",
".",
"y",
";",
"view",
".",
"setDraggerPosition",
"(",
"left",
",",
"top",
")",
";",
"}"
] | Calculates and sets the possition of the dragger element. | [
"Calculates",
"and",
"sets",
"the",
"possition",
"of",
"the",
"dragger",
"element",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/Navigator.js#L288-L297 |
6,730 | drichard/mindmaps | src/js/Navigator.js | documentOpened | function documentOpened(doc) {
docSize = doc.dimensions;
mindmap = doc.mindmap;
calculateCanvasSize();
calculateDraggerPosition();
calculateDraggerSize();
calculateZoomLevel();
calculateSliderValue();
renderView();
view.showActiveContent();
// move dragger when container was scrolled
$container.bind("scroll.navigator-view", function() {
if (!viewDragging) {
calculateDraggerPosition();
}
});
} | javascript | function documentOpened(doc) {
docSize = doc.dimensions;
mindmap = doc.mindmap;
calculateCanvasSize();
calculateDraggerPosition();
calculateDraggerSize();
calculateZoomLevel();
calculateSliderValue();
renderView();
view.showActiveContent();
// move dragger when container was scrolled
$container.bind("scroll.navigator-view", function() {
if (!viewDragging) {
calculateDraggerPosition();
}
});
} | [
"function",
"documentOpened",
"(",
"doc",
")",
"{",
"docSize",
"=",
"doc",
".",
"dimensions",
";",
"mindmap",
"=",
"doc",
".",
"mindmap",
";",
"calculateCanvasSize",
"(",
")",
";",
"calculateDraggerPosition",
"(",
")",
";",
"calculateDraggerSize",
"(",
")",
";",
"calculateZoomLevel",
"(",
")",
";",
"calculateSliderValue",
"(",
")",
";",
"renderView",
"(",
")",
";",
"view",
".",
"showActiveContent",
"(",
")",
";",
"// move dragger when container was scrolled\r",
"$container",
".",
"bind",
"(",
"\"scroll.navigator-view\"",
",",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"viewDragging",
")",
"{",
"calculateDraggerPosition",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Initialize view when a document was opened. | [
"Initialize",
"view",
"when",
"a",
"document",
"was",
"opened",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/Navigator.js#L318-L337 |
6,731 | drichard/mindmaps | src/js/Navigator.js | renderView | function renderView() {
// draw canvas
var scale = docSize.x / canvasSize.x;
view.draw(mindmap, scale);
} | javascript | function renderView() {
// draw canvas
var scale = docSize.x / canvasSize.x;
view.draw(mindmap, scale);
} | [
"function",
"renderView",
"(",
")",
"{",
"// draw canvas\r",
"var",
"scale",
"=",
"docSize",
".",
"x",
"/",
"canvasSize",
".",
"x",
";",
"view",
".",
"draw",
"(",
"mindmap",
",",
"scale",
")",
";",
"}"
] | Update the canvas of the view component. | [
"Update",
"the",
"canvas",
"of",
"the",
"view",
"component",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/Navigator.js#L342-L346 |
6,732 | drichard/mindmaps | Jakefile.js | extractScriptNames | function extractScriptNames() {
console.log("Extracting script file names from index.html");
var regexScriptName = /<script src="(.*?)"><\/script>/g;
var scriptSection = regexScriptSection.exec(indexFile)[1];
// extract script names
var names = [];
var match;
while ((match = regexScriptName.exec(scriptSection)) != null) {
var script = match[1];
names.push(script);
}
return names;
} | javascript | function extractScriptNames() {
console.log("Extracting script file names from index.html");
var regexScriptName = /<script src="(.*?)"><\/script>/g;
var scriptSection = regexScriptSection.exec(indexFile)[1];
// extract script names
var names = [];
var match;
while ((match = regexScriptName.exec(scriptSection)) != null) {
var script = match[1];
names.push(script);
}
return names;
} | [
"function",
"extractScriptNames",
"(",
")",
"{",
"console",
".",
"log",
"(",
"\"Extracting script file names from index.html\"",
")",
";",
"var",
"regexScriptName",
"=",
"/",
"<script src=\"(.*?)\"><\\/script>",
"/",
"g",
";",
"var",
"scriptSection",
"=",
"regexScriptSection",
".",
"exec",
"(",
"indexFile",
")",
"[",
"1",
"]",
";",
"// extract script names",
"var",
"names",
"=",
"[",
"]",
";",
"var",
"match",
";",
"while",
"(",
"(",
"match",
"=",
"regexScriptName",
".",
"exec",
"(",
"scriptSection",
")",
")",
"!=",
"null",
")",
"{",
"var",
"script",
"=",
"match",
"[",
"1",
"]",
";",
"names",
".",
"push",
"(",
"script",
")",
";",
"}",
"return",
"names",
";",
"}"
] | find the scripts in index.html | [
"find",
"the",
"scripts",
"in",
"index",
".",
"html"
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/Jakefile.js#L14-L29 |
6,733 | drichard/mindmaps | Jakefile.js | minifyScripts | function minifyScripts(scriptNames) {
console.log("Minifying and concatting scripts.");
var UglifyJS = require("uglify-js");
var regexMinifed = /min.js$/;
var regexCopyright = /^\/\*![\s\S]*?\*\//m;
var buffer = [];
scriptNames.forEach(function(script) {
var scriptFile = fs.readFileSync(srcDir + script, "utf8");
var copyright = regexCopyright.exec(scriptFile);
if (copyright) {
buffer.push(copyright);
}
// check if file is already minified
if (!regexMinifed.test(script)) {
var result = UglifyJS.minify(scriptFile);
if (result.error) {
throw new Error(error);
}
scriptFile = result.code;
} else {
console.log("> Skipping: " + script + " is already minified.");
}
buffer.push(scriptFile + ";");
});
var combined = buffer.join("\n");
fs.writeFileSync(publishDir + scriptDir + scriptFilename, combined);
console.log("Combined all scripts into " + scriptFilename);
} | javascript | function minifyScripts(scriptNames) {
console.log("Minifying and concatting scripts.");
var UglifyJS = require("uglify-js");
var regexMinifed = /min.js$/;
var regexCopyright = /^\/\*![\s\S]*?\*\//m;
var buffer = [];
scriptNames.forEach(function(script) {
var scriptFile = fs.readFileSync(srcDir + script, "utf8");
var copyright = regexCopyright.exec(scriptFile);
if (copyright) {
buffer.push(copyright);
}
// check if file is already minified
if (!regexMinifed.test(script)) {
var result = UglifyJS.minify(scriptFile);
if (result.error) {
throw new Error(error);
}
scriptFile = result.code;
} else {
console.log("> Skipping: " + script + " is already minified.");
}
buffer.push(scriptFile + ";");
});
var combined = buffer.join("\n");
fs.writeFileSync(publishDir + scriptDir + scriptFilename, combined);
console.log("Combined all scripts into " + scriptFilename);
} | [
"function",
"minifyScripts",
"(",
"scriptNames",
")",
"{",
"console",
".",
"log",
"(",
"\"Minifying and concatting scripts.\"",
")",
";",
"var",
"UglifyJS",
"=",
"require",
"(",
"\"uglify-js\"",
")",
";",
"var",
"regexMinifed",
"=",
"/",
"min.js$",
"/",
";",
"var",
"regexCopyright",
"=",
"/",
"^\\/\\*![\\s\\S]*?\\*\\/",
"/",
"m",
";",
"var",
"buffer",
"=",
"[",
"]",
";",
"scriptNames",
".",
"forEach",
"(",
"function",
"(",
"script",
")",
"{",
"var",
"scriptFile",
"=",
"fs",
".",
"readFileSync",
"(",
"srcDir",
"+",
"script",
",",
"\"utf8\"",
")",
";",
"var",
"copyright",
"=",
"regexCopyright",
".",
"exec",
"(",
"scriptFile",
")",
";",
"if",
"(",
"copyright",
")",
"{",
"buffer",
".",
"push",
"(",
"copyright",
")",
";",
"}",
"// check if file is already minified",
"if",
"(",
"!",
"regexMinifed",
".",
"test",
"(",
"script",
")",
")",
"{",
"var",
"result",
"=",
"UglifyJS",
".",
"minify",
"(",
"scriptFile",
")",
";",
"if",
"(",
"result",
".",
"error",
")",
"{",
"throw",
"new",
"Error",
"(",
"error",
")",
";",
"}",
"scriptFile",
"=",
"result",
".",
"code",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"\"> Skipping: \"",
"+",
"script",
"+",
"\" is already minified.\"",
")",
";",
"}",
"buffer",
".",
"push",
"(",
"scriptFile",
"+",
"\";\"",
")",
";",
"}",
")",
";",
"var",
"combined",
"=",
"buffer",
".",
"join",
"(",
"\"\\n\"",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"publishDir",
"+",
"scriptDir",
"+",
"scriptFilename",
",",
"combined",
")",
";",
"console",
".",
"log",
"(",
"\"Combined all scripts into \"",
"+",
"scriptFilename",
")",
";",
"}"
] | run all scripts through uglifyJS and write to new dest | [
"run",
"all",
"scripts",
"through",
"uglifyJS",
"and",
"write",
"to",
"new",
"dest"
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/Jakefile.js#L32-L64 |
6,734 | drichard/mindmaps | Jakefile.js | copyFiles | function copyFiles(dir) {
var files = fs.readdirSync(srcDir + dir);
files.forEach(function(file) {
var currentDir = dir + file;
if (!regexExcludeFiles.test(currentDir)) {
var stats = fs.statSync(srcDir + currentDir);
if (stats.isDirectory()) {
if (!fs.existsSync(publishDir + currentDir)) {
fs.mkdirSync(publishDir + currentDir);
}
copyFiles(currentDir + "/");
} else if (stats.isFile()) {
var contents = fs.readFileSync(srcDir + currentDir);
fs.writeFileSync(publishDir + currentDir, contents);
}
}
});
} | javascript | function copyFiles(dir) {
var files = fs.readdirSync(srcDir + dir);
files.forEach(function(file) {
var currentDir = dir + file;
if (!regexExcludeFiles.test(currentDir)) {
var stats = fs.statSync(srcDir + currentDir);
if (stats.isDirectory()) {
if (!fs.existsSync(publishDir + currentDir)) {
fs.mkdirSync(publishDir + currentDir);
}
copyFiles(currentDir + "/");
} else if (stats.isFile()) {
var contents = fs.readFileSync(srcDir + currentDir);
fs.writeFileSync(publishDir + currentDir, contents);
}
}
});
} | [
"function",
"copyFiles",
"(",
"dir",
")",
"{",
"var",
"files",
"=",
"fs",
".",
"readdirSync",
"(",
"srcDir",
"+",
"dir",
")",
";",
"files",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"var",
"currentDir",
"=",
"dir",
"+",
"file",
";",
"if",
"(",
"!",
"regexExcludeFiles",
".",
"test",
"(",
"currentDir",
")",
")",
"{",
"var",
"stats",
"=",
"fs",
".",
"statSync",
"(",
"srcDir",
"+",
"currentDir",
")",
";",
"if",
"(",
"stats",
".",
"isDirectory",
"(",
")",
")",
"{",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"publishDir",
"+",
"currentDir",
")",
")",
"{",
"fs",
".",
"mkdirSync",
"(",
"publishDir",
"+",
"currentDir",
")",
";",
"}",
"copyFiles",
"(",
"currentDir",
"+",
"\"/\"",
")",
";",
"}",
"else",
"if",
"(",
"stats",
".",
"isFile",
"(",
")",
")",
"{",
"var",
"contents",
"=",
"fs",
".",
"readFileSync",
"(",
"srcDir",
"+",
"currentDir",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"publishDir",
"+",
"currentDir",
",",
"contents",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] | Recursively copies all files that dont match the exclude filter from the
base directory to the publish directory. | [
"Recursively",
"copies",
"all",
"files",
"that",
"dont",
"match",
"the",
"exclude",
"filter",
"from",
"the",
"base",
"directory",
"to",
"the",
"publish",
"directory",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/Jakefile.js#L125-L142 |
6,735 | drichard/mindmaps | src/js/CanvasView.js | makeDraggable | function makeDraggable() {
self.$getContainer().dragscrollable({
dragSelector : "#drawing-area, canvas.line-canvas",
acceptPropagatedEvent : false,
delegateMode : true,
preventDefault : true
});
} | javascript | function makeDraggable() {
self.$getContainer().dragscrollable({
dragSelector : "#drawing-area, canvas.line-canvas",
acceptPropagatedEvent : false,
delegateMode : true,
preventDefault : true
});
} | [
"function",
"makeDraggable",
"(",
")",
"{",
"self",
".",
"$getContainer",
"(",
")",
".",
"dragscrollable",
"(",
"{",
"dragSelector",
":",
"\"#drawing-area, canvas.line-canvas\"",
",",
"acceptPropagatedEvent",
":",
"false",
",",
"delegateMode",
":",
"true",
",",
"preventDefault",
":",
"true",
"}",
")",
";",
"}"
] | Enables dragging of the map with the mouse. | [
"Enables",
"dragging",
"of",
"the",
"map",
"with",
"the",
"mouse",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/CanvasView.js#L159-L166 |
6,736 | drichard/mindmaps | src/js/CanvasView.js | drawNodeCanvas | function drawNodeCanvas(node, color) {
var parent = node.getParent();
var depth = node.getDepth();
var offsetX = node.offset.x;
var offsetY = node.offset.y;
color = color || node.branchColor;
var $node = $getNode(node);
var $parent = $getNode(parent);
var $canvas = $getNodeCanvas(node);
drawLineCanvas($canvas, depth, offsetX, offsetY, $node, $parent, color);
} | javascript | function drawNodeCanvas(node, color) {
var parent = node.getParent();
var depth = node.getDepth();
var offsetX = node.offset.x;
var offsetY = node.offset.y;
color = color || node.branchColor;
var $node = $getNode(node);
var $parent = $getNode(parent);
var $canvas = $getNodeCanvas(node);
drawLineCanvas($canvas, depth, offsetX, offsetY, $node, $parent, color);
} | [
"function",
"drawNodeCanvas",
"(",
"node",
",",
"color",
")",
"{",
"var",
"parent",
"=",
"node",
".",
"getParent",
"(",
")",
";",
"var",
"depth",
"=",
"node",
".",
"getDepth",
"(",
")",
";",
"var",
"offsetX",
"=",
"node",
".",
"offset",
".",
"x",
";",
"var",
"offsetY",
"=",
"node",
".",
"offset",
".",
"y",
";",
"color",
"=",
"color",
"||",
"node",
".",
"branchColor",
";",
"var",
"$node",
"=",
"$getNode",
"(",
"node",
")",
";",
"var",
"$parent",
"=",
"$getNode",
"(",
"parent",
")",
";",
"var",
"$canvas",
"=",
"$getNodeCanvas",
"(",
"node",
")",
";",
"drawLineCanvas",
"(",
"$canvas",
",",
"depth",
",",
"offsetX",
",",
"offsetY",
",",
"$node",
",",
"$parent",
",",
"color",
")",
";",
"}"
] | Redraws a node's branch to its parent.
@param {mindmaps.Node} node
@param {String} optional color | [
"Redraws",
"a",
"node",
"s",
"branch",
"to",
"its",
"parent",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/CanvasView.js#L596-L608 |
6,737 | drichard/mindmaps | src/js/CanvasView.js | CaptionEditor | function CaptionEditor(view) {
var self = this;
var attached = false;
// text input for node edits.
var $editor = $("<textarea/>", {
id : "caption-editor",
"class" : "node-text-behaviour"
}).bind("keydown", "esc", function() {
self.stop();
}).bind("keydown", "return", function() {
commitText();
}).mousedown(function(e) {
// avoid premature canceling
e.stopPropagation();
}).blur(function() {
commitText();
}).bind(
"input",
function() {
var metrics = textMetrics.getTextMetrics(self.node,
view.zoomFactor, $editor.val());
$editor.css(metrics);
alignBranches();
});
function commitText() {
if (attached && self.commit) {
self.commit(self.node, $editor.val());
}
}
function alignBranches() {
// slightly defer execution for better performance on slow
// browsers
setTimeout(function() {
view.redrawNodeConnectors(self.node);
}, 1);
}
/**
* Attaches the textarea to the node and temporarily removes the
* original node caption.
*
* @param {mindmaps.Node} node
* @param {jQuery} $cancelArea
*/
this.edit = function(node, $cancelArea) {
if (attached) {
return;
}
this.node = node;
attached = true;
// TODO put text into span and hide()
this.$text = $getNodeCaption(node);
this.$cancelArea = $cancelArea;
this.text = this.$text.text();
this.$text.css({
width : "auto",
height : "auto"
}).empty().addClass("edit");
// jquery ui prevents blur() event from happening when dragging a
// draggable. need this
// workaround to detect click on other draggable
$cancelArea.bind("mousedown.editNodeCaption", function(e) {
commitText();
});
var metrics = textMetrics.getTextMetrics(self.node,
view.zoomFactor, this.text);
$editor.attr({
value : this.text
}).css(metrics).appendTo(this.$text).select();
};
/**
* Removes the editor from the node and restores its old text value.
*/
this.stop = function() {
if (attached) {
attached = false;
this.$text.removeClass("edit");
$editor.detach();
this.$cancelArea.unbind("mousedown.editNodeCaption");
view.setNodeText(this.node, this.text);
alignBranches();
}
};
} | javascript | function CaptionEditor(view) {
var self = this;
var attached = false;
// text input for node edits.
var $editor = $("<textarea/>", {
id : "caption-editor",
"class" : "node-text-behaviour"
}).bind("keydown", "esc", function() {
self.stop();
}).bind("keydown", "return", function() {
commitText();
}).mousedown(function(e) {
// avoid premature canceling
e.stopPropagation();
}).blur(function() {
commitText();
}).bind(
"input",
function() {
var metrics = textMetrics.getTextMetrics(self.node,
view.zoomFactor, $editor.val());
$editor.css(metrics);
alignBranches();
});
function commitText() {
if (attached && self.commit) {
self.commit(self.node, $editor.val());
}
}
function alignBranches() {
// slightly defer execution for better performance on slow
// browsers
setTimeout(function() {
view.redrawNodeConnectors(self.node);
}, 1);
}
/**
* Attaches the textarea to the node and temporarily removes the
* original node caption.
*
* @param {mindmaps.Node} node
* @param {jQuery} $cancelArea
*/
this.edit = function(node, $cancelArea) {
if (attached) {
return;
}
this.node = node;
attached = true;
// TODO put text into span and hide()
this.$text = $getNodeCaption(node);
this.$cancelArea = $cancelArea;
this.text = this.$text.text();
this.$text.css({
width : "auto",
height : "auto"
}).empty().addClass("edit");
// jquery ui prevents blur() event from happening when dragging a
// draggable. need this
// workaround to detect click on other draggable
$cancelArea.bind("mousedown.editNodeCaption", function(e) {
commitText();
});
var metrics = textMetrics.getTextMetrics(self.node,
view.zoomFactor, this.text);
$editor.attr({
value : this.text
}).css(metrics).appendTo(this.$text).select();
};
/**
* Removes the editor from the node and restores its old text value.
*/
this.stop = function() {
if (attached) {
attached = false;
this.$text.removeClass("edit");
$editor.detach();
this.$cancelArea.unbind("mousedown.editNodeCaption");
view.setNodeText(this.node, this.text);
alignBranches();
}
};
} | [
"function",
"CaptionEditor",
"(",
"view",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"attached",
"=",
"false",
";",
"// text input for node edits.\r",
"var",
"$editor",
"=",
"$",
"(",
"\"<textarea/>\"",
",",
"{",
"id",
":",
"\"caption-editor\"",
",",
"\"class\"",
":",
"\"node-text-behaviour\"",
"}",
")",
".",
"bind",
"(",
"\"keydown\"",
",",
"\"esc\"",
",",
"function",
"(",
")",
"{",
"self",
".",
"stop",
"(",
")",
";",
"}",
")",
".",
"bind",
"(",
"\"keydown\"",
",",
"\"return\"",
",",
"function",
"(",
")",
"{",
"commitText",
"(",
")",
";",
"}",
")",
".",
"mousedown",
"(",
"function",
"(",
"e",
")",
"{",
"// avoid premature canceling\r",
"e",
".",
"stopPropagation",
"(",
")",
";",
"}",
")",
".",
"blur",
"(",
"function",
"(",
")",
"{",
"commitText",
"(",
")",
";",
"}",
")",
".",
"bind",
"(",
"\"input\"",
",",
"function",
"(",
")",
"{",
"var",
"metrics",
"=",
"textMetrics",
".",
"getTextMetrics",
"(",
"self",
".",
"node",
",",
"view",
".",
"zoomFactor",
",",
"$editor",
".",
"val",
"(",
")",
")",
";",
"$editor",
".",
"css",
"(",
"metrics",
")",
";",
"alignBranches",
"(",
")",
";",
"}",
")",
";",
"function",
"commitText",
"(",
")",
"{",
"if",
"(",
"attached",
"&&",
"self",
".",
"commit",
")",
"{",
"self",
".",
"commit",
"(",
"self",
".",
"node",
",",
"$editor",
".",
"val",
"(",
")",
")",
";",
"}",
"}",
"function",
"alignBranches",
"(",
")",
"{",
"// slightly defer execution for better performance on slow\r",
"// browsers\r",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"view",
".",
"redrawNodeConnectors",
"(",
"self",
".",
"node",
")",
";",
"}",
",",
"1",
")",
";",
"}",
"/**\r\n * Attaches the textarea to the node and temporarily removes the\r\n * original node caption.\r\n * \r\n * @param {mindmaps.Node} node\r\n * @param {jQuery} $cancelArea\r\n */",
"this",
".",
"edit",
"=",
"function",
"(",
"node",
",",
"$cancelArea",
")",
"{",
"if",
"(",
"attached",
")",
"{",
"return",
";",
"}",
"this",
".",
"node",
"=",
"node",
";",
"attached",
"=",
"true",
";",
"// TODO put text into span and hide()\r",
"this",
".",
"$text",
"=",
"$getNodeCaption",
"(",
"node",
")",
";",
"this",
".",
"$cancelArea",
"=",
"$cancelArea",
";",
"this",
".",
"text",
"=",
"this",
".",
"$text",
".",
"text",
"(",
")",
";",
"this",
".",
"$text",
".",
"css",
"(",
"{",
"width",
":",
"\"auto\"",
",",
"height",
":",
"\"auto\"",
"}",
")",
".",
"empty",
"(",
")",
".",
"addClass",
"(",
"\"edit\"",
")",
";",
"// jquery ui prevents blur() event from happening when dragging a\r",
"// draggable. need this\r",
"// workaround to detect click on other draggable\r",
"$cancelArea",
".",
"bind",
"(",
"\"mousedown.editNodeCaption\"",
",",
"function",
"(",
"e",
")",
"{",
"commitText",
"(",
")",
";",
"}",
")",
";",
"var",
"metrics",
"=",
"textMetrics",
".",
"getTextMetrics",
"(",
"self",
".",
"node",
",",
"view",
".",
"zoomFactor",
",",
"this",
".",
"text",
")",
";",
"$editor",
".",
"attr",
"(",
"{",
"value",
":",
"this",
".",
"text",
"}",
")",
".",
"css",
"(",
"metrics",
")",
".",
"appendTo",
"(",
"this",
".",
"$text",
")",
".",
"select",
"(",
")",
";",
"}",
";",
"/**\r\n * Removes the editor from the node and restores its old text value.\r\n */",
"this",
".",
"stop",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"attached",
")",
"{",
"attached",
"=",
"false",
";",
"this",
".",
"$text",
".",
"removeClass",
"(",
"\"edit\"",
")",
";",
"$editor",
".",
"detach",
"(",
")",
";",
"this",
".",
"$cancelArea",
".",
"unbind",
"(",
"\"mousedown.editNodeCaption\"",
")",
";",
"view",
".",
"setNodeText",
"(",
"this",
".",
"node",
",",
"this",
".",
"text",
")",
";",
"alignBranches",
"(",
")",
";",
"}",
"}",
";",
"}"
] | Creates a new CaptionEditor. This tool offers an inline editor component
to change a node's caption.
@constructor
@param {mindmaps.CanvasView} view | [
"Creates",
"a",
"new",
"CaptionEditor",
".",
"This",
"tool",
"offers",
"an",
"inline",
"editor",
"component",
"to",
"change",
"a",
"node",
"s",
"caption",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/CanvasView.js#L759-L853 |
6,738 | drichard/mindmaps | src/js/HelpController.js | setupHelpButton | function setupHelpButton() {
var command = commandRegistry.get(mindmaps.HelpCommand);
command.setHandler(showHelp);
var notifications = [];
function showHelp() {
// true if atleast one notifications is still on screen
var displaying = notifications.some(function(noti) {
return noti.isVisible();
});
// hide notifications if visible
if (displaying) {
notifications.forEach(function(noti) {
noti.close();
});
notifications.length = 0;
return;
}
// show notifications
var helpRoot = new mindmaps.Notification(
".node-caption.root",
{
position : "bottomLeft",
closeButton : true,
maxWidth : 350,
title : "This is your main idea",
content : "Double click an idea to edit its text. Move the mouse over "
+ "an idea and drag the red circle to create a new idea."
});
var helpNavigator = new mindmaps.Notification(
"#navigator",
{
position : "leftTop",
closeButton : true,
maxWidth : 350,
padding : 20,
title : "This is the navigator",
content : "Use this panel to get an overview of your map. "
+ "You can navigate around by dragging the red rectangle or change the zoom by clicking on the magnifier buttons."
});
var helpInspector = new mindmaps.Notification(
"#inspector",
{
position : "leftTop",
closeButton : true,
maxWidth : 350,
padding : 20,
title : "This is the inspector",
content : "Use these controls to change the appearance of your ideas. "
+ "Try clicking the icon in the upper right corner to minimize this panel."
});
var helpToolbar = new mindmaps.Notification(
"#toolbar .buttons-left",
{
position : "bottomLeft",
closeButton : true,
maxWidth : 350,
title : "This is your toolbar",
content : "Those buttons do what they say. You can use them or work with keyboard shortcuts. "
+ "Hover over the buttons for the key combinations."
});
notifications.push(helpRoot, helpNavigator, helpInspector,
helpToolbar);
}
} | javascript | function setupHelpButton() {
var command = commandRegistry.get(mindmaps.HelpCommand);
command.setHandler(showHelp);
var notifications = [];
function showHelp() {
// true if atleast one notifications is still on screen
var displaying = notifications.some(function(noti) {
return noti.isVisible();
});
// hide notifications if visible
if (displaying) {
notifications.forEach(function(noti) {
noti.close();
});
notifications.length = 0;
return;
}
// show notifications
var helpRoot = new mindmaps.Notification(
".node-caption.root",
{
position : "bottomLeft",
closeButton : true,
maxWidth : 350,
title : "This is your main idea",
content : "Double click an idea to edit its text. Move the mouse over "
+ "an idea and drag the red circle to create a new idea."
});
var helpNavigator = new mindmaps.Notification(
"#navigator",
{
position : "leftTop",
closeButton : true,
maxWidth : 350,
padding : 20,
title : "This is the navigator",
content : "Use this panel to get an overview of your map. "
+ "You can navigate around by dragging the red rectangle or change the zoom by clicking on the magnifier buttons."
});
var helpInspector = new mindmaps.Notification(
"#inspector",
{
position : "leftTop",
closeButton : true,
maxWidth : 350,
padding : 20,
title : "This is the inspector",
content : "Use these controls to change the appearance of your ideas. "
+ "Try clicking the icon in the upper right corner to minimize this panel."
});
var helpToolbar = new mindmaps.Notification(
"#toolbar .buttons-left",
{
position : "bottomLeft",
closeButton : true,
maxWidth : 350,
title : "This is your toolbar",
content : "Those buttons do what they say. You can use them or work with keyboard shortcuts. "
+ "Hover over the buttons for the key combinations."
});
notifications.push(helpRoot, helpNavigator, helpInspector,
helpToolbar);
}
} | [
"function",
"setupHelpButton",
"(",
")",
"{",
"var",
"command",
"=",
"commandRegistry",
".",
"get",
"(",
"mindmaps",
".",
"HelpCommand",
")",
";",
"command",
".",
"setHandler",
"(",
"showHelp",
")",
";",
"var",
"notifications",
"=",
"[",
"]",
";",
"function",
"showHelp",
"(",
")",
"{",
"// true if atleast one notifications is still on screen",
"var",
"displaying",
"=",
"notifications",
".",
"some",
"(",
"function",
"(",
"noti",
")",
"{",
"return",
"noti",
".",
"isVisible",
"(",
")",
";",
"}",
")",
";",
"// hide notifications if visible",
"if",
"(",
"displaying",
")",
"{",
"notifications",
".",
"forEach",
"(",
"function",
"(",
"noti",
")",
"{",
"noti",
".",
"close",
"(",
")",
";",
"}",
")",
";",
"notifications",
".",
"length",
"=",
"0",
";",
"return",
";",
"}",
"// show notifications",
"var",
"helpRoot",
"=",
"new",
"mindmaps",
".",
"Notification",
"(",
"\".node-caption.root\"",
",",
"{",
"position",
":",
"\"bottomLeft\"",
",",
"closeButton",
":",
"true",
",",
"maxWidth",
":",
"350",
",",
"title",
":",
"\"This is your main idea\"",
",",
"content",
":",
"\"Double click an idea to edit its text. Move the mouse over \"",
"+",
"\"an idea and drag the red circle to create a new idea.\"",
"}",
")",
";",
"var",
"helpNavigator",
"=",
"new",
"mindmaps",
".",
"Notification",
"(",
"\"#navigator\"",
",",
"{",
"position",
":",
"\"leftTop\"",
",",
"closeButton",
":",
"true",
",",
"maxWidth",
":",
"350",
",",
"padding",
":",
"20",
",",
"title",
":",
"\"This is the navigator\"",
",",
"content",
":",
"\"Use this panel to get an overview of your map. \"",
"+",
"\"You can navigate around by dragging the red rectangle or change the zoom by clicking on the magnifier buttons.\"",
"}",
")",
";",
"var",
"helpInspector",
"=",
"new",
"mindmaps",
".",
"Notification",
"(",
"\"#inspector\"",
",",
"{",
"position",
":",
"\"leftTop\"",
",",
"closeButton",
":",
"true",
",",
"maxWidth",
":",
"350",
",",
"padding",
":",
"20",
",",
"title",
":",
"\"This is the inspector\"",
",",
"content",
":",
"\"Use these controls to change the appearance of your ideas. \"",
"+",
"\"Try clicking the icon in the upper right corner to minimize this panel.\"",
"}",
")",
";",
"var",
"helpToolbar",
"=",
"new",
"mindmaps",
".",
"Notification",
"(",
"\"#toolbar .buttons-left\"",
",",
"{",
"position",
":",
"\"bottomLeft\"",
",",
"closeButton",
":",
"true",
",",
"maxWidth",
":",
"350",
",",
"title",
":",
"\"This is your toolbar\"",
",",
"content",
":",
"\"Those buttons do what they say. You can use them or work with keyboard shortcuts. \"",
"+",
"\"Hover over the buttons for the key combinations.\"",
"}",
")",
";",
"notifications",
".",
"push",
"(",
"helpRoot",
",",
"helpNavigator",
",",
"helpInspector",
",",
"helpToolbar",
")",
";",
"}",
"}"
] | Prepares notfications to show for help command. | [
"Prepares",
"notfications",
"to",
"show",
"for",
"help",
"command",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/HelpController.js#L209-L279 |
6,739 | drichard/mindmaps | src/js/CanvasDrawingTools.js | roundedRect | function roundedRect(ctx, x, y, width, height, radius) {
// from MDN docs
ctx.beginPath();
ctx.moveTo(x, y + radius);
ctx.lineTo(x, y + height - radius);
ctx.quadraticCurveTo(x, y + height, x + radius, y + height);
ctx.lineTo(x + width - radius, y + height);
ctx.quadraticCurveTo(x + width, y + height, x + width, y + height
- radius);
ctx.lineTo(x + width, y + radius);
ctx.quadraticCurveTo(x + width, y, x + width - radius, y);
ctx.lineTo(x + radius, y);
ctx.quadraticCurveTo(x, y, x, y + radius);
ctx.stroke();
ctx.fill();
} | javascript | function roundedRect(ctx, x, y, width, height, radius) {
// from MDN docs
ctx.beginPath();
ctx.moveTo(x, y + radius);
ctx.lineTo(x, y + height - radius);
ctx.quadraticCurveTo(x, y + height, x + radius, y + height);
ctx.lineTo(x + width - radius, y + height);
ctx.quadraticCurveTo(x + width, y + height, x + width, y + height
- radius);
ctx.lineTo(x + width, y + radius);
ctx.quadraticCurveTo(x + width, y, x + width - radius, y);
ctx.lineTo(x + radius, y);
ctx.quadraticCurveTo(x, y, x, y + radius);
ctx.stroke();
ctx.fill();
} | [
"function",
"roundedRect",
"(",
"ctx",
",",
"x",
",",
"y",
",",
"width",
",",
"height",
",",
"radius",
")",
"{",
"// from MDN docs",
"ctx",
".",
"beginPath",
"(",
")",
";",
"ctx",
".",
"moveTo",
"(",
"x",
",",
"y",
"+",
"radius",
")",
";",
"ctx",
".",
"lineTo",
"(",
"x",
",",
"y",
"+",
"height",
"-",
"radius",
")",
";",
"ctx",
".",
"quadraticCurveTo",
"(",
"x",
",",
"y",
"+",
"height",
",",
"x",
"+",
"radius",
",",
"y",
"+",
"height",
")",
";",
"ctx",
".",
"lineTo",
"(",
"x",
"+",
"width",
"-",
"radius",
",",
"y",
"+",
"height",
")",
";",
"ctx",
".",
"quadraticCurveTo",
"(",
"x",
"+",
"width",
",",
"y",
"+",
"height",
",",
"x",
"+",
"width",
",",
"y",
"+",
"height",
"-",
"radius",
")",
";",
"ctx",
".",
"lineTo",
"(",
"x",
"+",
"width",
",",
"y",
"+",
"radius",
")",
";",
"ctx",
".",
"quadraticCurveTo",
"(",
"x",
"+",
"width",
",",
"y",
",",
"x",
"+",
"width",
"-",
"radius",
",",
"y",
")",
";",
"ctx",
".",
"lineTo",
"(",
"x",
"+",
"radius",
",",
"y",
")",
";",
"ctx",
".",
"quadraticCurveTo",
"(",
"x",
",",
"y",
",",
"x",
",",
"y",
"+",
"radius",
")",
";",
"ctx",
".",
"stroke",
"(",
")",
";",
"ctx",
".",
"fill",
"(",
")",
";",
"}"
] | Draws a rounded rectangle
@param ctx
@param x
@param y
@param width
@param height
@param radius | [
"Draws",
"a",
"rounded",
"rectangle"
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/CanvasDrawingTools.js#L28-L43 |
6,740 | drichard/mindmaps | src/js/CanvasPresenter.js | function(node) {
if (!node) {
node = mindmapModel.selectedNode;
}
// toggle node visibility
var action = new mindmaps.action.ToggleNodeFoldAction(node);
mindmapModel.executeAction(action);
} | javascript | function(node) {
if (!node) {
node = mindmapModel.selectedNode;
}
// toggle node visibility
var action = new mindmaps.action.ToggleNodeFoldAction(node);
mindmapModel.executeAction(action);
} | [
"function",
"(",
"node",
")",
"{",
"if",
"(",
"!",
"node",
")",
"{",
"node",
"=",
"mindmapModel",
".",
"selectedNode",
";",
"}",
"// toggle node visibility\r",
"var",
"action",
"=",
"new",
"mindmaps",
".",
"action",
".",
"ToggleNodeFoldAction",
"(",
"node",
")",
";",
"mindmapModel",
".",
"executeAction",
"(",
"action",
")",
";",
"}"
] | Toggles the fold state of a node.
@param {mindmaps.Node} node | [
"Toggles",
"the",
"fold",
"state",
"of",
"a",
"node",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/CanvasPresenter.js#L47-L55 |
|
6,741 | drichard/mindmaps | src/js/CanvasPresenter.js | showMindMap | function showMindMap(doc) {
view.setZoomFactor(zoomController.DEFAULT_ZOOM);
var dimensions = doc.dimensions;
view.setDimensions(dimensions.x, dimensions.y);
var map = doc.mindmap;
view.drawMap(map);
view.center();
mindmapModel.selectNode(map.root);
} | javascript | function showMindMap(doc) {
view.setZoomFactor(zoomController.DEFAULT_ZOOM);
var dimensions = doc.dimensions;
view.setDimensions(dimensions.x, dimensions.y);
var map = doc.mindmap;
view.drawMap(map);
view.center();
mindmapModel.selectNode(map.root);
} | [
"function",
"showMindMap",
"(",
"doc",
")",
"{",
"view",
".",
"setZoomFactor",
"(",
"zoomController",
".",
"DEFAULT_ZOOM",
")",
";",
"var",
"dimensions",
"=",
"doc",
".",
"dimensions",
";",
"view",
".",
"setDimensions",
"(",
"dimensions",
".",
"x",
",",
"dimensions",
".",
"y",
")",
";",
"var",
"map",
"=",
"doc",
".",
"mindmap",
";",
"view",
".",
"drawMap",
"(",
"map",
")",
";",
"view",
".",
"center",
"(",
")",
";",
"mindmapModel",
".",
"selectNode",
"(",
"map",
".",
"root",
")",
";",
"}"
] | Draw the mind map on the canvas.
@param {mindmaps.Document} doc | [
"Draw",
"the",
"mind",
"map",
"on",
"the",
"canvas",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/CanvasPresenter.js#L225-L234 |
6,742 | drichard/mindmaps | src/js/CanvasPresenter.js | bind | function bind() {
// listen to global events
eventBus.subscribe(mindmaps.Event.DOCUMENT_OPENED, function(doc,
newDocument) {
showMindMap(doc);
// if (doc.isNew()) {
// // edit root node on start
// var root = doc.mindmap.root;
// view.editNodeCaption(root);
// }
});
eventBus.subscribe(mindmaps.Event.DOCUMENT_CLOSED, function(doc) {
view.clear();
});
eventBus.subscribe(mindmaps.Event.NODE_MOVED, function(node) {
view.positionNode(node);
});
eventBus.subscribe(mindmaps.Event.NODE_TEXT_CAPTION_CHANGED, function(
node) {
view.setNodeText(node, node.getCaption());
// redraw node in case height has changed
// TODO maybe only redraw if height has changed
view.redrawNodeConnectors(node);
});
eventBus.subscribe(mindmaps.Event.NODE_CREATED, function(node) {
view.createNode(node);
// edit node caption immediately if requested
if (node.shouldEditCaption) {
delete node.shouldEditCaption;
// open parent node when creating a new child and the other
// children are hidden
var parent = node.getParent();
if (parent.foldChildren) {
var action = new mindmaps.action.OpenNodeAction(parent);
mindmapModel.executeAction(action);
}
// select and go into edit mode on new node
mindmapModel.selectNode(node);
// attach creator manually, sometimes the mouseover listener wont fire
creator.attachToNode(node);
view.editNodeCaption(node);
}
});
eventBus.subscribe(mindmaps.Event.NODE_DELETED, function(node, parent) {
// select parent if we are deleting a selected node or a descendant
var selected = mindmapModel.selectedNode;
if (node === selected || node.isDescendant(selected)) {
// deselectCurrentNode();
mindmapModel.selectNode(parent);
}
// update view
view.deleteNode(node);
if (parent.isLeaf()) {
view.removeFoldButton(parent);
}
});
eventBus.subscribe(mindmaps.Event.NODE_SELECTED, selectNode);
eventBus.subscribe(mindmaps.Event.NODE_OPENED, function(node) {
view.openNode(node);
});
eventBus.subscribe(mindmaps.Event.NODE_CLOSED, function(node) {
view.closeNode(node);
});
eventBus.subscribe(mindmaps.Event.NODE_FONT_CHANGED, function(node) {
view.updateNode(node);
});
eventBus.subscribe(mindmaps.Event.NODE_FONT_COLOR_PREVIEW, function(node, color) {
view.updateFontColor(node, color);
});
eventBus.subscribe(mindmaps.Event.NODE_BRANCH_COLOR_CHANGED, function(
node) {
view.updateNode(node);
});
eventBus.subscribe(mindmaps.Event.NODE_BRANCH_COLOR_PREVIEW, function(node, color) {
view.updateBranchColor(node, color)
});
eventBus.subscribe(mindmaps.Event.ZOOM_CHANGED, function(zoomFactor) {
view.setZoomFactor(zoomFactor);
view.applyViewZoom();
view.scaleMap();
});
} | javascript | function bind() {
// listen to global events
eventBus.subscribe(mindmaps.Event.DOCUMENT_OPENED, function(doc,
newDocument) {
showMindMap(doc);
// if (doc.isNew()) {
// // edit root node on start
// var root = doc.mindmap.root;
// view.editNodeCaption(root);
// }
});
eventBus.subscribe(mindmaps.Event.DOCUMENT_CLOSED, function(doc) {
view.clear();
});
eventBus.subscribe(mindmaps.Event.NODE_MOVED, function(node) {
view.positionNode(node);
});
eventBus.subscribe(mindmaps.Event.NODE_TEXT_CAPTION_CHANGED, function(
node) {
view.setNodeText(node, node.getCaption());
// redraw node in case height has changed
// TODO maybe only redraw if height has changed
view.redrawNodeConnectors(node);
});
eventBus.subscribe(mindmaps.Event.NODE_CREATED, function(node) {
view.createNode(node);
// edit node caption immediately if requested
if (node.shouldEditCaption) {
delete node.shouldEditCaption;
// open parent node when creating a new child and the other
// children are hidden
var parent = node.getParent();
if (parent.foldChildren) {
var action = new mindmaps.action.OpenNodeAction(parent);
mindmapModel.executeAction(action);
}
// select and go into edit mode on new node
mindmapModel.selectNode(node);
// attach creator manually, sometimes the mouseover listener wont fire
creator.attachToNode(node);
view.editNodeCaption(node);
}
});
eventBus.subscribe(mindmaps.Event.NODE_DELETED, function(node, parent) {
// select parent if we are deleting a selected node or a descendant
var selected = mindmapModel.selectedNode;
if (node === selected || node.isDescendant(selected)) {
// deselectCurrentNode();
mindmapModel.selectNode(parent);
}
// update view
view.deleteNode(node);
if (parent.isLeaf()) {
view.removeFoldButton(parent);
}
});
eventBus.subscribe(mindmaps.Event.NODE_SELECTED, selectNode);
eventBus.subscribe(mindmaps.Event.NODE_OPENED, function(node) {
view.openNode(node);
});
eventBus.subscribe(mindmaps.Event.NODE_CLOSED, function(node) {
view.closeNode(node);
});
eventBus.subscribe(mindmaps.Event.NODE_FONT_CHANGED, function(node) {
view.updateNode(node);
});
eventBus.subscribe(mindmaps.Event.NODE_FONT_COLOR_PREVIEW, function(node, color) {
view.updateFontColor(node, color);
});
eventBus.subscribe(mindmaps.Event.NODE_BRANCH_COLOR_CHANGED, function(
node) {
view.updateNode(node);
});
eventBus.subscribe(mindmaps.Event.NODE_BRANCH_COLOR_PREVIEW, function(node, color) {
view.updateBranchColor(node, color)
});
eventBus.subscribe(mindmaps.Event.ZOOM_CHANGED, function(zoomFactor) {
view.setZoomFactor(zoomFactor);
view.applyViewZoom();
view.scaleMap();
});
} | [
"function",
"bind",
"(",
")",
"{",
"// listen to global events\r",
"eventBus",
".",
"subscribe",
"(",
"mindmaps",
".",
"Event",
".",
"DOCUMENT_OPENED",
",",
"function",
"(",
"doc",
",",
"newDocument",
")",
"{",
"showMindMap",
"(",
"doc",
")",
";",
"// if (doc.isNew()) {\r",
"// // edit root node on start\r",
"// var root = doc.mindmap.root;\r",
"// view.editNodeCaption(root);\r",
"// }\r",
"}",
")",
";",
"eventBus",
".",
"subscribe",
"(",
"mindmaps",
".",
"Event",
".",
"DOCUMENT_CLOSED",
",",
"function",
"(",
"doc",
")",
"{",
"view",
".",
"clear",
"(",
")",
";",
"}",
")",
";",
"eventBus",
".",
"subscribe",
"(",
"mindmaps",
".",
"Event",
".",
"NODE_MOVED",
",",
"function",
"(",
"node",
")",
"{",
"view",
".",
"positionNode",
"(",
"node",
")",
";",
"}",
")",
";",
"eventBus",
".",
"subscribe",
"(",
"mindmaps",
".",
"Event",
".",
"NODE_TEXT_CAPTION_CHANGED",
",",
"function",
"(",
"node",
")",
"{",
"view",
".",
"setNodeText",
"(",
"node",
",",
"node",
".",
"getCaption",
"(",
")",
")",
";",
"// redraw node in case height has changed\r",
"// TODO maybe only redraw if height has changed\r",
"view",
".",
"redrawNodeConnectors",
"(",
"node",
")",
";",
"}",
")",
";",
"eventBus",
".",
"subscribe",
"(",
"mindmaps",
".",
"Event",
".",
"NODE_CREATED",
",",
"function",
"(",
"node",
")",
"{",
"view",
".",
"createNode",
"(",
"node",
")",
";",
"// edit node caption immediately if requested\r",
"if",
"(",
"node",
".",
"shouldEditCaption",
")",
"{",
"delete",
"node",
".",
"shouldEditCaption",
";",
"// open parent node when creating a new child and the other\r",
"// children are hidden\r",
"var",
"parent",
"=",
"node",
".",
"getParent",
"(",
")",
";",
"if",
"(",
"parent",
".",
"foldChildren",
")",
"{",
"var",
"action",
"=",
"new",
"mindmaps",
".",
"action",
".",
"OpenNodeAction",
"(",
"parent",
")",
";",
"mindmapModel",
".",
"executeAction",
"(",
"action",
")",
";",
"}",
"// select and go into edit mode on new node\r",
"mindmapModel",
".",
"selectNode",
"(",
"node",
")",
";",
"// attach creator manually, sometimes the mouseover listener wont fire\r",
"creator",
".",
"attachToNode",
"(",
"node",
")",
";",
"view",
".",
"editNodeCaption",
"(",
"node",
")",
";",
"}",
"}",
")",
";",
"eventBus",
".",
"subscribe",
"(",
"mindmaps",
".",
"Event",
".",
"NODE_DELETED",
",",
"function",
"(",
"node",
",",
"parent",
")",
"{",
"// select parent if we are deleting a selected node or a descendant\r",
"var",
"selected",
"=",
"mindmapModel",
".",
"selectedNode",
";",
"if",
"(",
"node",
"===",
"selected",
"||",
"node",
".",
"isDescendant",
"(",
"selected",
")",
")",
"{",
"// deselectCurrentNode();\r",
"mindmapModel",
".",
"selectNode",
"(",
"parent",
")",
";",
"}",
"// update view\r",
"view",
".",
"deleteNode",
"(",
"node",
")",
";",
"if",
"(",
"parent",
".",
"isLeaf",
"(",
")",
")",
"{",
"view",
".",
"removeFoldButton",
"(",
"parent",
")",
";",
"}",
"}",
")",
";",
"eventBus",
".",
"subscribe",
"(",
"mindmaps",
".",
"Event",
".",
"NODE_SELECTED",
",",
"selectNode",
")",
";",
"eventBus",
".",
"subscribe",
"(",
"mindmaps",
".",
"Event",
".",
"NODE_OPENED",
",",
"function",
"(",
"node",
")",
"{",
"view",
".",
"openNode",
"(",
"node",
")",
";",
"}",
")",
";",
"eventBus",
".",
"subscribe",
"(",
"mindmaps",
".",
"Event",
".",
"NODE_CLOSED",
",",
"function",
"(",
"node",
")",
"{",
"view",
".",
"closeNode",
"(",
"node",
")",
";",
"}",
")",
";",
"eventBus",
".",
"subscribe",
"(",
"mindmaps",
".",
"Event",
".",
"NODE_FONT_CHANGED",
",",
"function",
"(",
"node",
")",
"{",
"view",
".",
"updateNode",
"(",
"node",
")",
";",
"}",
")",
";",
"eventBus",
".",
"subscribe",
"(",
"mindmaps",
".",
"Event",
".",
"NODE_FONT_COLOR_PREVIEW",
",",
"function",
"(",
"node",
",",
"color",
")",
"{",
"view",
".",
"updateFontColor",
"(",
"node",
",",
"color",
")",
";",
"}",
")",
";",
"eventBus",
".",
"subscribe",
"(",
"mindmaps",
".",
"Event",
".",
"NODE_BRANCH_COLOR_CHANGED",
",",
"function",
"(",
"node",
")",
"{",
"view",
".",
"updateNode",
"(",
"node",
")",
";",
"}",
")",
";",
"eventBus",
".",
"subscribe",
"(",
"mindmaps",
".",
"Event",
".",
"NODE_BRANCH_COLOR_PREVIEW",
",",
"function",
"(",
"node",
",",
"color",
")",
"{",
"view",
".",
"updateBranchColor",
"(",
"node",
",",
"color",
")",
"}",
")",
";",
"eventBus",
".",
"subscribe",
"(",
"mindmaps",
".",
"Event",
".",
"ZOOM_CHANGED",
",",
"function",
"(",
"zoomFactor",
")",
"{",
"view",
".",
"setZoomFactor",
"(",
"zoomFactor",
")",
";",
"view",
".",
"applyViewZoom",
"(",
")",
";",
"view",
".",
"scaleMap",
"(",
")",
";",
"}",
")",
";",
"}"
] | Hook up with EventBus. | [
"Hook",
"up",
"with",
"EventBus",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/CanvasPresenter.js#L239-L338 |
6,743 | drichard/mindmaps | src/js/Util.js | getBinaryMapWithDepth | function getBinaryMapWithDepth(depth) {
var mm = new mindmaps.MindMap();
var root = mm.root;
function createTwoChildren(node, depth) {
if (depth === 0) {
return;
}
var left = mm.createNode();
left.text.caption = "Node " + left.id;
node.addChild(left);
createTwoChildren(left, depth - 1);
var right = mm.createNode();
right.text.caption = "Node " + right.id;
node.addChild(right);
createTwoChildren(right, depth - 1);
}
// depth 10: about 400kb, 800kb in chrome
// depth 12: about 1600kb
// depth 16: 25mb
var depth = depth || 10;
createTwoChildren(root, depth);
// generate positions for all nodes.
// tree grows balanced from left to right
root.offset = new mindmaps.Point(400, 400);
// var offset = Math.pow(2, depth-1) * 10;
var offset = 80;
var c = root.children.values();
setOffset(c[0], 0, -offset);
setOffset(c[1], 0, offset);
function setOffset(node, depth, offsetY) {
node.offset = new mindmaps.Point((depth + 1) * 50, offsetY);
if (node.isLeaf()) {
return;
}
var c = node.children.values();
var left = c[0];
setOffset(left, depth + 1, offsetY - offsetY / 2);
var right = c[1];
setOffset(right, depth + 1, offsetY + offsetY / 2);
}
// color nodes
c[0].branchColor = mindmaps.Util.randomColor();
c[0].forEachDescendant(function(node) {
node.branchColor = mindmaps.Util.randomColor();
});
c[1].branchColor = mindmaps.Util.randomColor();
c[1].forEachDescendant(function(node) {
node.branchColor = mindmaps.Util.randomColor();
});
return mm;
} | javascript | function getBinaryMapWithDepth(depth) {
var mm = new mindmaps.MindMap();
var root = mm.root;
function createTwoChildren(node, depth) {
if (depth === 0) {
return;
}
var left = mm.createNode();
left.text.caption = "Node " + left.id;
node.addChild(left);
createTwoChildren(left, depth - 1);
var right = mm.createNode();
right.text.caption = "Node " + right.id;
node.addChild(right);
createTwoChildren(right, depth - 1);
}
// depth 10: about 400kb, 800kb in chrome
// depth 12: about 1600kb
// depth 16: 25mb
var depth = depth || 10;
createTwoChildren(root, depth);
// generate positions for all nodes.
// tree grows balanced from left to right
root.offset = new mindmaps.Point(400, 400);
// var offset = Math.pow(2, depth-1) * 10;
var offset = 80;
var c = root.children.values();
setOffset(c[0], 0, -offset);
setOffset(c[1], 0, offset);
function setOffset(node, depth, offsetY) {
node.offset = new mindmaps.Point((depth + 1) * 50, offsetY);
if (node.isLeaf()) {
return;
}
var c = node.children.values();
var left = c[0];
setOffset(left, depth + 1, offsetY - offsetY / 2);
var right = c[1];
setOffset(right, depth + 1, offsetY + offsetY / 2);
}
// color nodes
c[0].branchColor = mindmaps.Util.randomColor();
c[0].forEachDescendant(function(node) {
node.branchColor = mindmaps.Util.randomColor();
});
c[1].branchColor = mindmaps.Util.randomColor();
c[1].forEachDescendant(function(node) {
node.branchColor = mindmaps.Util.randomColor();
});
return mm;
} | [
"function",
"getBinaryMapWithDepth",
"(",
"depth",
")",
"{",
"var",
"mm",
"=",
"new",
"mindmaps",
".",
"MindMap",
"(",
")",
";",
"var",
"root",
"=",
"mm",
".",
"root",
";",
"function",
"createTwoChildren",
"(",
"node",
",",
"depth",
")",
"{",
"if",
"(",
"depth",
"===",
"0",
")",
"{",
"return",
";",
"}",
"var",
"left",
"=",
"mm",
".",
"createNode",
"(",
")",
";",
"left",
".",
"text",
".",
"caption",
"=",
"\"Node \"",
"+",
"left",
".",
"id",
";",
"node",
".",
"addChild",
"(",
"left",
")",
";",
"createTwoChildren",
"(",
"left",
",",
"depth",
"-",
"1",
")",
";",
"var",
"right",
"=",
"mm",
".",
"createNode",
"(",
")",
";",
"right",
".",
"text",
".",
"caption",
"=",
"\"Node \"",
"+",
"right",
".",
"id",
";",
"node",
".",
"addChild",
"(",
"right",
")",
";",
"createTwoChildren",
"(",
"right",
",",
"depth",
"-",
"1",
")",
";",
"}",
"// depth 10: about 400kb, 800kb in chrome\r",
"// depth 12: about 1600kb\r",
"// depth 16: 25mb\r",
"var",
"depth",
"=",
"depth",
"||",
"10",
";",
"createTwoChildren",
"(",
"root",
",",
"depth",
")",
";",
"// generate positions for all nodes.\r",
"// tree grows balanced from left to right\r",
"root",
".",
"offset",
"=",
"new",
"mindmaps",
".",
"Point",
"(",
"400",
",",
"400",
")",
";",
"// var offset = Math.pow(2, depth-1) * 10;\r",
"var",
"offset",
"=",
"80",
";",
"var",
"c",
"=",
"root",
".",
"children",
".",
"values",
"(",
")",
";",
"setOffset",
"(",
"c",
"[",
"0",
"]",
",",
"0",
",",
"-",
"offset",
")",
";",
"setOffset",
"(",
"c",
"[",
"1",
"]",
",",
"0",
",",
"offset",
")",
";",
"function",
"setOffset",
"(",
"node",
",",
"depth",
",",
"offsetY",
")",
"{",
"node",
".",
"offset",
"=",
"new",
"mindmaps",
".",
"Point",
"(",
"(",
"depth",
"+",
"1",
")",
"*",
"50",
",",
"offsetY",
")",
";",
"if",
"(",
"node",
".",
"isLeaf",
"(",
")",
")",
"{",
"return",
";",
"}",
"var",
"c",
"=",
"node",
".",
"children",
".",
"values",
"(",
")",
";",
"var",
"left",
"=",
"c",
"[",
"0",
"]",
";",
"setOffset",
"(",
"left",
",",
"depth",
"+",
"1",
",",
"offsetY",
"-",
"offsetY",
"/",
"2",
")",
";",
"var",
"right",
"=",
"c",
"[",
"1",
"]",
";",
"setOffset",
"(",
"right",
",",
"depth",
"+",
"1",
",",
"offsetY",
"+",
"offsetY",
"/",
"2",
")",
";",
"}",
"// color nodes\r",
"c",
"[",
"0",
"]",
".",
"branchColor",
"=",
"mindmaps",
".",
"Util",
".",
"randomColor",
"(",
")",
";",
"c",
"[",
"0",
"]",
".",
"forEachDescendant",
"(",
"function",
"(",
"node",
")",
"{",
"node",
".",
"branchColor",
"=",
"mindmaps",
".",
"Util",
".",
"randomColor",
"(",
")",
";",
"}",
")",
";",
"c",
"[",
"1",
"]",
".",
"branchColor",
"=",
"mindmaps",
".",
"Util",
".",
"randomColor",
"(",
")",
";",
"c",
"[",
"1",
"]",
".",
"forEachDescendant",
"(",
"function",
"(",
"node",
")",
"{",
"node",
".",
"branchColor",
"=",
"mindmaps",
".",
"Util",
".",
"randomColor",
"(",
")",
";",
"}",
")",
";",
"return",
"mm",
";",
"}"
] | test Default documents | [
"test",
"Default",
"documents"
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/Util.js#L96-L156 |
6,744 | drichard/mindmaps | src/js/StaticCanvas.js | prepareNodes | function prepareNodes(mindmap) {
// clone tree since we modify it
var root = mindmap.getRoot().clone();
function addProps(node) {
var lineWidth = mindmaps.CanvasDrawingUtil.getLineWidth(zoomFactor,
node.getDepth());
var metrics = mindmaps.TextMetrics.getTextMetrics(node, zoomFactor);
var props = {
lineWidth : lineWidth,
textMetrics : metrics,
width : function() {
if (node.isRoot()) {
return 0;
}
return metrics.width;
},
innerHeight : function() {
return metrics.height + padding;
},
outerHeight : function() {
return metrics.height + lineWidth + padding;
}
};
$.extend(node, props);
node.forEachChild(function(child) {
addProps(child);
});
}
addProps(root);
return root;
} | javascript | function prepareNodes(mindmap) {
// clone tree since we modify it
var root = mindmap.getRoot().clone();
function addProps(node) {
var lineWidth = mindmaps.CanvasDrawingUtil.getLineWidth(zoomFactor,
node.getDepth());
var metrics = mindmaps.TextMetrics.getTextMetrics(node, zoomFactor);
var props = {
lineWidth : lineWidth,
textMetrics : metrics,
width : function() {
if (node.isRoot()) {
return 0;
}
return metrics.width;
},
innerHeight : function() {
return metrics.height + padding;
},
outerHeight : function() {
return metrics.height + lineWidth + padding;
}
};
$.extend(node, props);
node.forEachChild(function(child) {
addProps(child);
});
}
addProps(root);
return root;
} | [
"function",
"prepareNodes",
"(",
"mindmap",
")",
"{",
"// clone tree since we modify it",
"var",
"root",
"=",
"mindmap",
".",
"getRoot",
"(",
")",
".",
"clone",
"(",
")",
";",
"function",
"addProps",
"(",
"node",
")",
"{",
"var",
"lineWidth",
"=",
"mindmaps",
".",
"CanvasDrawingUtil",
".",
"getLineWidth",
"(",
"zoomFactor",
",",
"node",
".",
"getDepth",
"(",
")",
")",
";",
"var",
"metrics",
"=",
"mindmaps",
".",
"TextMetrics",
".",
"getTextMetrics",
"(",
"node",
",",
"zoomFactor",
")",
";",
"var",
"props",
"=",
"{",
"lineWidth",
":",
"lineWidth",
",",
"textMetrics",
":",
"metrics",
",",
"width",
":",
"function",
"(",
")",
"{",
"if",
"(",
"node",
".",
"isRoot",
"(",
")",
")",
"{",
"return",
"0",
";",
"}",
"return",
"metrics",
".",
"width",
";",
"}",
",",
"innerHeight",
":",
"function",
"(",
")",
"{",
"return",
"metrics",
".",
"height",
"+",
"padding",
";",
"}",
",",
"outerHeight",
":",
"function",
"(",
")",
"{",
"return",
"metrics",
".",
"height",
"+",
"lineWidth",
"+",
"padding",
";",
"}",
"}",
";",
"$",
".",
"extend",
"(",
"node",
",",
"props",
")",
";",
"node",
".",
"forEachChild",
"(",
"function",
"(",
"child",
")",
"{",
"addProps",
"(",
"child",
")",
";",
"}",
")",
";",
"}",
"addProps",
"(",
"root",
")",
";",
"return",
"root",
";",
"}"
] | Adds some information to each node which are needed for rendering.
@param mindmap
@returns | [
"Adds",
"some",
"information",
"to",
"each",
"node",
"which",
"are",
"needed",
"for",
"rendering",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/StaticCanvas.js#L42-L79 |
6,745 | drichard/mindmaps | src/js/StaticCanvas.js | getMindMapDimensions | function getMindMapDimensions(root) {
var pos = root.getPosition();
var left = 0, top = 0, right = 0, bottom = 0;
var padding = 50;
function checkDimensions(node) {
var pos = node.getPosition();
var tm = node.textMetrics;
if (pos.x < left) {
left = pos.x;
}
if (pos.x + tm.width > right) {
right = pos.x + tm.width;
}
if (pos.y < top) {
top = pos.y;
}
if (pos.y + node.outerHeight() > bottom) {
bottom = pos.y + node.outerHeight();
}
}
checkDimensions(root);
root.forEachDescendant(function(node) {
checkDimensions(node);
});
// find the longest offset to either side and use twice the length for
// canvas width
var horizontal = Math.max(Math.abs(right), Math.abs(left));
var vertical = Math.max(Math.abs(bottom), Math.abs(top));
return {
width : 2 * horizontal + padding,
height : 2 * vertical + padding
};
} | javascript | function getMindMapDimensions(root) {
var pos = root.getPosition();
var left = 0, top = 0, right = 0, bottom = 0;
var padding = 50;
function checkDimensions(node) {
var pos = node.getPosition();
var tm = node.textMetrics;
if (pos.x < left) {
left = pos.x;
}
if (pos.x + tm.width > right) {
right = pos.x + tm.width;
}
if (pos.y < top) {
top = pos.y;
}
if (pos.y + node.outerHeight() > bottom) {
bottom = pos.y + node.outerHeight();
}
}
checkDimensions(root);
root.forEachDescendant(function(node) {
checkDimensions(node);
});
// find the longest offset to either side and use twice the length for
// canvas width
var horizontal = Math.max(Math.abs(right), Math.abs(left));
var vertical = Math.max(Math.abs(bottom), Math.abs(top));
return {
width : 2 * horizontal + padding,
height : 2 * vertical + padding
};
} | [
"function",
"getMindMapDimensions",
"(",
"root",
")",
"{",
"var",
"pos",
"=",
"root",
".",
"getPosition",
"(",
")",
";",
"var",
"left",
"=",
"0",
",",
"top",
"=",
"0",
",",
"right",
"=",
"0",
",",
"bottom",
"=",
"0",
";",
"var",
"padding",
"=",
"50",
";",
"function",
"checkDimensions",
"(",
"node",
")",
"{",
"var",
"pos",
"=",
"node",
".",
"getPosition",
"(",
")",
";",
"var",
"tm",
"=",
"node",
".",
"textMetrics",
";",
"if",
"(",
"pos",
".",
"x",
"<",
"left",
")",
"{",
"left",
"=",
"pos",
".",
"x",
";",
"}",
"if",
"(",
"pos",
".",
"x",
"+",
"tm",
".",
"width",
">",
"right",
")",
"{",
"right",
"=",
"pos",
".",
"x",
"+",
"tm",
".",
"width",
";",
"}",
"if",
"(",
"pos",
".",
"y",
"<",
"top",
")",
"{",
"top",
"=",
"pos",
".",
"y",
";",
"}",
"if",
"(",
"pos",
".",
"y",
"+",
"node",
".",
"outerHeight",
"(",
")",
">",
"bottom",
")",
"{",
"bottom",
"=",
"pos",
".",
"y",
"+",
"node",
".",
"outerHeight",
"(",
")",
";",
"}",
"}",
"checkDimensions",
"(",
"root",
")",
";",
"root",
".",
"forEachDescendant",
"(",
"function",
"(",
"node",
")",
"{",
"checkDimensions",
"(",
"node",
")",
";",
"}",
")",
";",
"// find the longest offset to either side and use twice the length for",
"// canvas width",
"var",
"horizontal",
"=",
"Math",
".",
"max",
"(",
"Math",
".",
"abs",
"(",
"right",
")",
",",
"Math",
".",
"abs",
"(",
"left",
")",
")",
";",
"var",
"vertical",
"=",
"Math",
".",
"max",
"(",
"Math",
".",
"abs",
"(",
"bottom",
")",
",",
"Math",
".",
"abs",
"(",
"top",
")",
")",
";",
"return",
"{",
"width",
":",
"2",
"*",
"horizontal",
"+",
"padding",
",",
"height",
":",
"2",
"*",
"vertical",
"+",
"padding",
"}",
";",
"}"
] | Finds the nodes which are farthest away from the root and calculates the
actual dimensions of the mind map.
@param {mindmaps.Node} root
@returns {object} with properties width and height | [
"Finds",
"the",
"nodes",
"which",
"are",
"farthest",
"away",
"from",
"the",
"root",
"and",
"calculates",
"the",
"actual",
"dimensions",
"of",
"the",
"mind",
"map",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/StaticCanvas.js#L88-L128 |
6,746 | drichard/mindmaps | src/js/StaticCanvas.js | drawLines | function drawLines(node, parent) {
ctx.save();
var x = node.offset.x;
var y = node.offset.y;
ctx.translate(x, y);
// branch
if (parent) {
drawBranch(node, parent);
}
// bottom border
if (!node.isRoot()) {
ctx.fillStyle = node.branchColor;
var tm = node.textMetrics;
ctx.fillRect(0, tm.height + padding, tm.width, node.lineWidth);
}
node.forEachChild(function(child) {
drawLines(child, node);
});
ctx.restore();
} | javascript | function drawLines(node, parent) {
ctx.save();
var x = node.offset.x;
var y = node.offset.y;
ctx.translate(x, y);
// branch
if (parent) {
drawBranch(node, parent);
}
// bottom border
if (!node.isRoot()) {
ctx.fillStyle = node.branchColor;
var tm = node.textMetrics;
ctx.fillRect(0, tm.height + padding, tm.width, node.lineWidth);
}
node.forEachChild(function(child) {
drawLines(child, node);
});
ctx.restore();
} | [
"function",
"drawLines",
"(",
"node",
",",
"parent",
")",
"{",
"ctx",
".",
"save",
"(",
")",
";",
"var",
"x",
"=",
"node",
".",
"offset",
".",
"x",
";",
"var",
"y",
"=",
"node",
".",
"offset",
".",
"y",
";",
"ctx",
".",
"translate",
"(",
"x",
",",
"y",
")",
";",
"// branch",
"if",
"(",
"parent",
")",
"{",
"drawBranch",
"(",
"node",
",",
"parent",
")",
";",
"}",
"// bottom border",
"if",
"(",
"!",
"node",
".",
"isRoot",
"(",
")",
")",
"{",
"ctx",
".",
"fillStyle",
"=",
"node",
".",
"branchColor",
";",
"var",
"tm",
"=",
"node",
".",
"textMetrics",
";",
"ctx",
".",
"fillRect",
"(",
"0",
",",
"tm",
".",
"height",
"+",
"padding",
",",
"tm",
".",
"width",
",",
"node",
".",
"lineWidth",
")",
";",
"}",
"node",
".",
"forEachChild",
"(",
"function",
"(",
"child",
")",
"{",
"drawLines",
"(",
"child",
",",
"node",
")",
";",
"}",
")",
";",
"ctx",
".",
"restore",
"(",
")",
";",
"}"
] | Draws all branches | [
"Draws",
"all",
"branches"
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/StaticCanvas.js#L204-L227 |
6,747 | drichard/mindmaps | src/js/Command.js | function() {
if (this.handler) {
this.handler();
if (mindmaps.DEBUG) {
console.log("handler called for", this.id);
}
} else {
if (mindmaps.DEBUG) {
console.log("no handler found for", this.id);
}
}
} | javascript | function() {
if (this.handler) {
this.handler();
if (mindmaps.DEBUG) {
console.log("handler called for", this.id);
}
} else {
if (mindmaps.DEBUG) {
console.log("no handler found for", this.id);
}
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"handler",
")",
"{",
"this",
".",
"handler",
"(",
")",
";",
"if",
"(",
"mindmaps",
".",
"DEBUG",
")",
"{",
"console",
".",
"log",
"(",
"\"handler called for\"",
",",
"this",
".",
"id",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"mindmaps",
".",
"DEBUG",
")",
"{",
"console",
".",
"log",
"(",
"\"no handler found for\"",
",",
"this",
".",
"id",
")",
";",
"}",
"}",
"}"
] | Executes the command. Tries to call the handler function. | [
"Executes",
"the",
"command",
".",
"Tries",
"to",
"call",
"the",
"handler",
"function",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/Command.js#L40-L51 |
|
6,748 | drichard/mindmaps | src/js/UndoManager.js | UndoManager | function UndoManager(maxStackSize) {
this.maxStackSize = maxStackSize || 64;
var State = {
UNDO : "undo",
REDO : "redo"
};
var self = this;
var undoStack = new UndoManager.CircularStack(this.maxStackSize);
var redoStack = new UndoManager.CircularStack(this.maxStackSize);
var undoContext = false;
var currentAction = null;
var currentState = null;
var onStateChange = function() {
if (self.stateChanged) {
self.stateChanged();
}
};
var callAction = function(action) {
currentAction = action;
undoContext = true;
switch (currentState) {
case State.UNDO:
action.undo();
break;
case State.REDO:
action.redo();
break;
}
undoContext = false;
};
/**
* Register an undo operation. A call to .undo() will cause the undo
* function to be executed. If you omit the second argument and the undo
* function will cause the registration of another undo operation, then this
* operation will be used as the redo function.
*
* If you provide both arguments, a call to addUndo() during an undo() or
* redo() will have no effect.
*
*
* @param {Function} undoFunc The function that should undo the changes.
* @param {Function} [redoFunc] The function that should redo the undone
* changes.
*/
this.addUndo = function(undoFunc, redoFunc) {
if (undoContext) {
/**
* If we are currently undoing an action and don't have a redo
* function yet, store the undo function to the undo function, which
* is in turn the redo function.
*/
if (currentAction.redo == null && currentState == State.UNDO) {
currentAction.redo = undoFunc;
}
} else {
/**
* We are not undoing right now. Store the functions as an action.
*/
var action = {
undo : undoFunc,
redo : redoFunc
};
undoStack.push(action);
// clear redo stack
redoStack.clear();
onStateChange();
}
};
/**
* Undoes the last action.
*/
this.undo = function() {
if (this.canUndo()) {
currentState = State.UNDO;
var action = undoStack.pop();
callAction(action);
if (action.redo) {
redoStack.push(action);
}
onStateChange();
}
};
/**
* Redoes the last action.
*/
this.redo = function() {
if (this.canRedo()) {
currentState = State.REDO;
var action = redoStack.pop();
callAction(action);
if (action.undo) {
undoStack.push(action);
}
onStateChange();
}
};
/**
*
* @returns {Boolean} true if undo is possible, false otherwise.
*/
this.canUndo = function() {
return !undoStack.isEmpty();
};
/**
*
* @returns {Boolean} true if redo is possible, false otherwise.
*/
this.canRedo = function() {
return !redoStack.isEmpty();
};
/**
* Resets this instance of the undo manager.
*/
this.reset = function() {
undoStack.clear();
redoStack.clear();
undoContext = false;
currentAction = null;
currentState = null;
onStateChange();
};
/**
* Event that is fired when undo or redo state changes.
*
* @event
*/
this.stateChanged = function() {
};
} | javascript | function UndoManager(maxStackSize) {
this.maxStackSize = maxStackSize || 64;
var State = {
UNDO : "undo",
REDO : "redo"
};
var self = this;
var undoStack = new UndoManager.CircularStack(this.maxStackSize);
var redoStack = new UndoManager.CircularStack(this.maxStackSize);
var undoContext = false;
var currentAction = null;
var currentState = null;
var onStateChange = function() {
if (self.stateChanged) {
self.stateChanged();
}
};
var callAction = function(action) {
currentAction = action;
undoContext = true;
switch (currentState) {
case State.UNDO:
action.undo();
break;
case State.REDO:
action.redo();
break;
}
undoContext = false;
};
/**
* Register an undo operation. A call to .undo() will cause the undo
* function to be executed. If you omit the second argument and the undo
* function will cause the registration of another undo operation, then this
* operation will be used as the redo function.
*
* If you provide both arguments, a call to addUndo() during an undo() or
* redo() will have no effect.
*
*
* @param {Function} undoFunc The function that should undo the changes.
* @param {Function} [redoFunc] The function that should redo the undone
* changes.
*/
this.addUndo = function(undoFunc, redoFunc) {
if (undoContext) {
/**
* If we are currently undoing an action and don't have a redo
* function yet, store the undo function to the undo function, which
* is in turn the redo function.
*/
if (currentAction.redo == null && currentState == State.UNDO) {
currentAction.redo = undoFunc;
}
} else {
/**
* We are not undoing right now. Store the functions as an action.
*/
var action = {
undo : undoFunc,
redo : redoFunc
};
undoStack.push(action);
// clear redo stack
redoStack.clear();
onStateChange();
}
};
/**
* Undoes the last action.
*/
this.undo = function() {
if (this.canUndo()) {
currentState = State.UNDO;
var action = undoStack.pop();
callAction(action);
if (action.redo) {
redoStack.push(action);
}
onStateChange();
}
};
/**
* Redoes the last action.
*/
this.redo = function() {
if (this.canRedo()) {
currentState = State.REDO;
var action = redoStack.pop();
callAction(action);
if (action.undo) {
undoStack.push(action);
}
onStateChange();
}
};
/**
*
* @returns {Boolean} true if undo is possible, false otherwise.
*/
this.canUndo = function() {
return !undoStack.isEmpty();
};
/**
*
* @returns {Boolean} true if redo is possible, false otherwise.
*/
this.canRedo = function() {
return !redoStack.isEmpty();
};
/**
* Resets this instance of the undo manager.
*/
this.reset = function() {
undoStack.clear();
redoStack.clear();
undoContext = false;
currentAction = null;
currentState = null;
onStateChange();
};
/**
* Event that is fired when undo or redo state changes.
*
* @event
*/
this.stateChanged = function() {
};
} | [
"function",
"UndoManager",
"(",
"maxStackSize",
")",
"{",
"this",
".",
"maxStackSize",
"=",
"maxStackSize",
"||",
"64",
";",
"var",
"State",
"=",
"{",
"UNDO",
":",
"\"undo\"",
",",
"REDO",
":",
"\"redo\"",
"}",
";",
"var",
"self",
"=",
"this",
";",
"var",
"undoStack",
"=",
"new",
"UndoManager",
".",
"CircularStack",
"(",
"this",
".",
"maxStackSize",
")",
";",
"var",
"redoStack",
"=",
"new",
"UndoManager",
".",
"CircularStack",
"(",
"this",
".",
"maxStackSize",
")",
";",
"var",
"undoContext",
"=",
"false",
";",
"var",
"currentAction",
"=",
"null",
";",
"var",
"currentState",
"=",
"null",
";",
"var",
"onStateChange",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"self",
".",
"stateChanged",
")",
"{",
"self",
".",
"stateChanged",
"(",
")",
";",
"}",
"}",
";",
"var",
"callAction",
"=",
"function",
"(",
"action",
")",
"{",
"currentAction",
"=",
"action",
";",
"undoContext",
"=",
"true",
";",
"switch",
"(",
"currentState",
")",
"{",
"case",
"State",
".",
"UNDO",
":",
"action",
".",
"undo",
"(",
")",
";",
"break",
";",
"case",
"State",
".",
"REDO",
":",
"action",
".",
"redo",
"(",
")",
";",
"break",
";",
"}",
"undoContext",
"=",
"false",
";",
"}",
";",
"/**\r\n * Register an undo operation. A call to .undo() will cause the undo\r\n * function to be executed. If you omit the second argument and the undo\r\n * function will cause the registration of another undo operation, then this\r\n * operation will be used as the redo function.\r\n * \r\n * If you provide both arguments, a call to addUndo() during an undo() or\r\n * redo() will have no effect.\r\n * \r\n * \r\n * @param {Function} undoFunc The function that should undo the changes.\r\n * @param {Function} [redoFunc] The function that should redo the undone\r\n * changes.\r\n */",
"this",
".",
"addUndo",
"=",
"function",
"(",
"undoFunc",
",",
"redoFunc",
")",
"{",
"if",
"(",
"undoContext",
")",
"{",
"/**\r\n * If we are currently undoing an action and don't have a redo\r\n * function yet, store the undo function to the undo function, which\r\n * is in turn the redo function.\r\n */",
"if",
"(",
"currentAction",
".",
"redo",
"==",
"null",
"&&",
"currentState",
"==",
"State",
".",
"UNDO",
")",
"{",
"currentAction",
".",
"redo",
"=",
"undoFunc",
";",
"}",
"}",
"else",
"{",
"/**\r\n * We are not undoing right now. Store the functions as an action.\r\n */",
"var",
"action",
"=",
"{",
"undo",
":",
"undoFunc",
",",
"redo",
":",
"redoFunc",
"}",
";",
"undoStack",
".",
"push",
"(",
"action",
")",
";",
"// clear redo stack\r",
"redoStack",
".",
"clear",
"(",
")",
";",
"onStateChange",
"(",
")",
";",
"}",
"}",
";",
"/**\r\n * Undoes the last action.\r\n */",
"this",
".",
"undo",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"canUndo",
"(",
")",
")",
"{",
"currentState",
"=",
"State",
".",
"UNDO",
";",
"var",
"action",
"=",
"undoStack",
".",
"pop",
"(",
")",
";",
"callAction",
"(",
"action",
")",
";",
"if",
"(",
"action",
".",
"redo",
")",
"{",
"redoStack",
".",
"push",
"(",
"action",
")",
";",
"}",
"onStateChange",
"(",
")",
";",
"}",
"}",
";",
"/**\r\n * Redoes the last action.\r\n */",
"this",
".",
"redo",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"canRedo",
"(",
")",
")",
"{",
"currentState",
"=",
"State",
".",
"REDO",
";",
"var",
"action",
"=",
"redoStack",
".",
"pop",
"(",
")",
";",
"callAction",
"(",
"action",
")",
";",
"if",
"(",
"action",
".",
"undo",
")",
"{",
"undoStack",
".",
"push",
"(",
"action",
")",
";",
"}",
"onStateChange",
"(",
")",
";",
"}",
"}",
";",
"/**\r\n * \r\n * @returns {Boolean} true if undo is possible, false otherwise.\r\n */",
"this",
".",
"canUndo",
"=",
"function",
"(",
")",
"{",
"return",
"!",
"undoStack",
".",
"isEmpty",
"(",
")",
";",
"}",
";",
"/**\r\n * \r\n * @returns {Boolean} true if redo is possible, false otherwise.\r\n */",
"this",
".",
"canRedo",
"=",
"function",
"(",
")",
"{",
"return",
"!",
"redoStack",
".",
"isEmpty",
"(",
")",
";",
"}",
";",
"/**\r\n * Resets this instance of the undo manager.\r\n */",
"this",
".",
"reset",
"=",
"function",
"(",
")",
"{",
"undoStack",
".",
"clear",
"(",
")",
";",
"redoStack",
".",
"clear",
"(",
")",
";",
"undoContext",
"=",
"false",
";",
"currentAction",
"=",
"null",
";",
"currentState",
"=",
"null",
";",
"onStateChange",
"(",
")",
";",
"}",
";",
"/**\r\n * Event that is fired when undo or redo state changes.\r\n * \r\n * @event\r\n */",
"this",
".",
"stateChanged",
"=",
"function",
"(",
")",
"{",
"}",
";",
"}"
] | Creates a new UndoManager
@constructor
@param {Integer} [maxStackSize=64] | [
"Creates",
"a",
"new",
"UndoManager"
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/UndoManager.js#L7-L152 |
6,749 | drichard/mindmaps | src/js/Storage.js | function(doc) {
try {
localStorage.setItem(prefix + doc.id, doc.serialize());
return true;
} catch (error) {
// QUOTA_EXCEEDED
console.error("Error while saving document to local storage",
error);
return false;
}
} | javascript | function(doc) {
try {
localStorage.setItem(prefix + doc.id, doc.serialize());
return true;
} catch (error) {
// QUOTA_EXCEEDED
console.error("Error while saving document to local storage",
error);
return false;
}
} | [
"function",
"(",
"doc",
")",
"{",
"try",
"{",
"localStorage",
".",
"setItem",
"(",
"prefix",
"+",
"doc",
".",
"id",
",",
"doc",
".",
"serialize",
"(",
")",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"// QUOTA_EXCEEDED\r",
"console",
".",
"error",
"(",
"\"Error while saving document to local storage\"",
",",
"error",
")",
";",
"return",
"false",
";",
"}",
"}"
] | Saves a document to the localstorage. Overwrites the old document if
one with the same id exists.
@param {mindmaps.Document} doc
@returns {Boolean} true if save was successful, false otherwise. | [
"Saves",
"a",
"document",
"to",
"the",
"localstorage",
".",
"Overwrites",
"the",
"old",
"document",
"if",
"one",
"with",
"the",
"same",
"id",
"exists",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/Storage.js#L69-L79 |
|
6,750 | drichard/mindmaps | src/js/Storage.js | function() {
var documents = [];
// search localstorage for saved documents
for ( var i = 0, max = localStorage.length; i < max; i++) {
var key = localStorage.key(i);
// value is a document if key confirms to prefix
if (key.indexOf(prefix) == 0) {
var doc = getDocumentByKey(key);
if (doc) {
documents.push(doc);
}
}
}
return documents;
} | javascript | function() {
var documents = [];
// search localstorage for saved documents
for ( var i = 0, max = localStorage.length; i < max; i++) {
var key = localStorage.key(i);
// value is a document if key confirms to prefix
if (key.indexOf(prefix) == 0) {
var doc = getDocumentByKey(key);
if (doc) {
documents.push(doc);
}
}
}
return documents;
} | [
"function",
"(",
")",
"{",
"var",
"documents",
"=",
"[",
"]",
";",
"// search localstorage for saved documents\r",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"max",
"=",
"localStorage",
".",
"length",
";",
"i",
"<",
"max",
";",
"i",
"++",
")",
"{",
"var",
"key",
"=",
"localStorage",
".",
"key",
"(",
"i",
")",
";",
"// value is a document if key confirms to prefix\r",
"if",
"(",
"key",
".",
"indexOf",
"(",
"prefix",
")",
"==",
"0",
")",
"{",
"var",
"doc",
"=",
"getDocumentByKey",
"(",
"key",
")",
";",
"if",
"(",
"doc",
")",
"{",
"documents",
".",
"push",
"(",
"doc",
")",
";",
"}",
"}",
"}",
"return",
"documents",
";",
"}"
] | Finds all documents in the local storage object.
@returns {Array} an Array of documents | [
"Finds",
"all",
"documents",
"in",
"the",
"local",
"storage",
"object",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/Storage.js#L97-L111 |
|
6,751 | drichard/mindmaps | src/js/Storage.js | function() {
var ids = [];
// search localstorage for saved documents
for ( var i = 0, max = localStorage.length; i < max; i++) {
var key = localStorage.key(i);
// value is a document if key confirms to prefix
if (key.indexOf(prefix) == 0) {
ids.push(key.substring(prefix.length));
}
}
return ids;
} | javascript | function() {
var ids = [];
// search localstorage for saved documents
for ( var i = 0, max = localStorage.length; i < max; i++) {
var key = localStorage.key(i);
// value is a document if key confirms to prefix
if (key.indexOf(prefix) == 0) {
ids.push(key.substring(prefix.length));
}
}
return ids;
} | [
"function",
"(",
")",
"{",
"var",
"ids",
"=",
"[",
"]",
";",
"// search localstorage for saved documents\r",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"max",
"=",
"localStorage",
".",
"length",
";",
"i",
"<",
"max",
";",
"i",
"++",
")",
"{",
"var",
"key",
"=",
"localStorage",
".",
"key",
"(",
"i",
")",
";",
"// value is a document if key confirms to prefix\r",
"if",
"(",
"key",
".",
"indexOf",
"(",
"prefix",
")",
"==",
"0",
")",
"{",
"ids",
".",
"push",
"(",
"key",
".",
"substring",
"(",
"prefix",
".",
"length",
")",
")",
";",
"}",
"}",
"return",
"ids",
";",
"}"
] | Gets all document ids found in the local storage object.
@returns {Array} an Array of document ids | [
"Gets",
"all",
"document",
"ids",
"found",
"in",
"the",
"local",
"storage",
"object",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/Storage.js#L118-L129 |
|
6,752 | drichard/mindmaps | src/js/MindMaps.js | addUnloadHook | function addUnloadHook () {
window.onbeforeunload = function (e) {
var msg = "Are you sure? Any unsaved progress will be lost."
e = e || window.event;
// For IE and Firefox prior to version 4
if (e) {
e.returnValue = msg;
}
// For Safari
return msg;
};
} | javascript | function addUnloadHook () {
window.onbeforeunload = function (e) {
var msg = "Are you sure? Any unsaved progress will be lost."
e = e || window.event;
// For IE and Firefox prior to version 4
if (e) {
e.returnValue = msg;
}
// For Safari
return msg;
};
} | [
"function",
"addUnloadHook",
"(",
")",
"{",
"window",
".",
"onbeforeunload",
"=",
"function",
"(",
"e",
")",
"{",
"var",
"msg",
"=",
"\"Are you sure? Any unsaved progress will be lost.\"",
"e",
"=",
"e",
"||",
"window",
".",
"event",
";",
"// For IE and Firefox prior to version 4\r",
"if",
"(",
"e",
")",
"{",
"e",
".",
"returnValue",
"=",
"msg",
";",
"}",
"// For Safari\r",
"return",
"msg",
";",
"}",
";",
"}"
] | Adds a confirmation dialog when the user navigates away from the app. | [
"Adds",
"a",
"confirmation",
"dialog",
"when",
"the",
"user",
"navigates",
"away",
"from",
"the",
"app",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/MindMaps.js#L105-L118 |
6,753 | drichard/mindmaps | src/js/MindMaps.js | setupConsole | function setupConsole() {
var noOp = function() {};
// provide console object and dummy functions if not built-in
var console = window.console || {};
['log', 'info', 'debug', 'warn', 'error'].forEach(function(prop) {
console[prop] = console[prop] || noOp;
});
// turn all console.xx calls into no-ops when in production mode except
// for errors, do an alert.
if (!mindmaps.DEBUG) {
console.debug = noOp;
console.info = noOp;
console.log = noOp;
console.warn = noOp;
console.error = function(s) {
window.alert("Error: " + s);
};
}
window.console = console;
} | javascript | function setupConsole() {
var noOp = function() {};
// provide console object and dummy functions if not built-in
var console = window.console || {};
['log', 'info', 'debug', 'warn', 'error'].forEach(function(prop) {
console[prop] = console[prop] || noOp;
});
// turn all console.xx calls into no-ops when in production mode except
// for errors, do an alert.
if (!mindmaps.DEBUG) {
console.debug = noOp;
console.info = noOp;
console.log = noOp;
console.warn = noOp;
console.error = function(s) {
window.alert("Error: " + s);
};
}
window.console = console;
} | [
"function",
"setupConsole",
"(",
")",
"{",
"var",
"noOp",
"=",
"function",
"(",
")",
"{",
"}",
";",
"// provide console object and dummy functions if not built-in\r",
"var",
"console",
"=",
"window",
".",
"console",
"||",
"{",
"}",
";",
"[",
"'log'",
",",
"'info'",
",",
"'debug'",
",",
"'warn'",
",",
"'error'",
"]",
".",
"forEach",
"(",
"function",
"(",
"prop",
")",
"{",
"console",
"[",
"prop",
"]",
"=",
"console",
"[",
"prop",
"]",
"||",
"noOp",
";",
"}",
")",
";",
"// turn all console.xx calls into no-ops when in production mode except\r",
"// for errors, do an alert.\r",
"if",
"(",
"!",
"mindmaps",
".",
"DEBUG",
")",
"{",
"console",
".",
"debug",
"=",
"noOp",
";",
"console",
".",
"info",
"=",
"noOp",
";",
"console",
".",
"log",
"=",
"noOp",
";",
"console",
".",
"warn",
"=",
"noOp",
";",
"console",
".",
"error",
"=",
"function",
"(",
"s",
")",
"{",
"window",
".",
"alert",
"(",
"\"Error: \"",
"+",
"s",
")",
";",
"}",
";",
"}",
"window",
".",
"console",
"=",
"console",
";",
"}"
] | Initialize the console object. | [
"Initialize",
"the",
"console",
"object",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/MindMaps.js#L141-L163 |
6,754 | drichard/mindmaps | src/js/MindMaps.js | createHTML5Shims | function createHTML5Shims() {
// localstorage dummy (does nothing)
if (typeof window.localStorage == 'undefined') {
window.localStorage = {
getItem : function() {
return null;
},
setItem : function() {
},
clear : function() {
},
removeItem : function() {
},
length : 0,
key : function() {
return null;
}
};
}
} | javascript | function createHTML5Shims() {
// localstorage dummy (does nothing)
if (typeof window.localStorage == 'undefined') {
window.localStorage = {
getItem : function() {
return null;
},
setItem : function() {
},
clear : function() {
},
removeItem : function() {
},
length : 0,
key : function() {
return null;
}
};
}
} | [
"function",
"createHTML5Shims",
"(",
")",
"{",
"// localstorage dummy (does nothing)\r",
"if",
"(",
"typeof",
"window",
".",
"localStorage",
"==",
"'undefined'",
")",
"{",
"window",
".",
"localStorage",
"=",
"{",
"getItem",
":",
"function",
"(",
")",
"{",
"return",
"null",
";",
"}",
",",
"setItem",
":",
"function",
"(",
")",
"{",
"}",
",",
"clear",
":",
"function",
"(",
")",
"{",
"}",
",",
"removeItem",
":",
"function",
"(",
")",
"{",
"}",
",",
"length",
":",
"0",
",",
"key",
":",
"function",
"(",
")",
"{",
"return",
"null",
";",
"}",
"}",
";",
"}",
"}"
] | Create shims for HTML5 functionality if not supported by browser. | [
"Create",
"shims",
"for",
"HTML5",
"functionality",
"if",
"not",
"supported",
"by",
"browser",
"."
] | 489f04f499409ae7a9f70ad4861e999c230fa6a5 | https://github.com/drichard/mindmaps/blob/489f04f499409ae7a9f70ad4861e999c230fa6a5/src/js/MindMaps.js#L405-L424 |
6,755 | hshoff/vx | scripts/docs/index.js | getReadmeText | function getReadmeText(pkg) {
const pkgDir = atPackagesDirectory().dir(pkg);
const generatedDoc = pkgDir.read('./docs/docs.md');
if (generatedDoc) pkgDir.write('Readme.md', generatedDoc);
const text = pkgDir.read(README);
if (text) return text;
else return ''; // don't return "undefined"
} | javascript | function getReadmeText(pkg) {
const pkgDir = atPackagesDirectory().dir(pkg);
const generatedDoc = pkgDir.read('./docs/docs.md');
if (generatedDoc) pkgDir.write('Readme.md', generatedDoc);
const text = pkgDir.read(README);
if (text) return text;
else return ''; // don't return "undefined"
} | [
"function",
"getReadmeText",
"(",
"pkg",
")",
"{",
"const",
"pkgDir",
"=",
"atPackagesDirectory",
"(",
")",
".",
"dir",
"(",
"pkg",
")",
";",
"const",
"generatedDoc",
"=",
"pkgDir",
".",
"read",
"(",
"'./docs/docs.md'",
")",
";",
"if",
"(",
"generatedDoc",
")",
"pkgDir",
".",
"write",
"(",
"'Readme.md'",
",",
"generatedDoc",
")",
";",
"const",
"text",
"=",
"pkgDir",
".",
"read",
"(",
"README",
")",
";",
"if",
"(",
"text",
")",
"return",
"text",
";",
"else",
"return",
"''",
";",
"// don't return \"undefined\"",
"}"
] | Returns the text of a README at a specific package | [
"Returns",
"the",
"text",
"of",
"a",
"README",
"at",
"a",
"specific",
"package"
] | 850ecd6c9dd3791febfcc49073c6eef5dcc04dc7 | https://github.com/hshoff/vx/blob/850ecd6c9dd3791febfcc49073c6eef5dcc04dc7/scripts/docs/index.js#L28-L35 |
6,756 | hshoff/vx | scripts/docs/index.js | getDocObject | function getDocObject(dir, info) {
const markdown = getReadmeText(dir);
const html = marked(markdown);
const cleanedHTML = prepareHTML(html, info);
return { pkg: dir, html: cleanedHTML };
} | javascript | function getDocObject(dir, info) {
const markdown = getReadmeText(dir);
const html = marked(markdown);
const cleanedHTML = prepareHTML(html, info);
return { pkg: dir, html: cleanedHTML };
} | [
"function",
"getDocObject",
"(",
"dir",
",",
"info",
")",
"{",
"const",
"markdown",
"=",
"getReadmeText",
"(",
"dir",
")",
";",
"const",
"html",
"=",
"marked",
"(",
"markdown",
")",
";",
"const",
"cleanedHTML",
"=",
"prepareHTML",
"(",
"html",
",",
"info",
")",
";",
"return",
"{",
"pkg",
":",
"dir",
",",
"html",
":",
"cleanedHTML",
"}",
";",
"}"
] | From a package directory, get the html from the markdown
@return {pkg, html} | [
"From",
"a",
"package",
"directory",
"get",
"the",
"html",
"from",
"the",
"markdown"
] | 850ecd6c9dd3791febfcc49073c6eef5dcc04dc7 | https://github.com/hshoff/vx/blob/850ecd6c9dd3791febfcc49073c6eef5dcc04dc7/scripts/docs/index.js#L41-L46 |
6,757 | Automattic/kue | lib/http/routes/json.js | get | function get( obj ) {
var pending = 0
, res = {}
, callback
, done;
return function _( arg ) {
switch(typeof arg) {
case 'function':
callback = arg;
break;
case 'string':
++pending;
obj[ arg ](function( err, val ) {
if( done ) return;
if( err ) return done = true, callback(err);
res[ arg ] = val;
--pending || callback(null, res);
});
break;
}
return _;
};
} | javascript | function get( obj ) {
var pending = 0
, res = {}
, callback
, done;
return function _( arg ) {
switch(typeof arg) {
case 'function':
callback = arg;
break;
case 'string':
++pending;
obj[ arg ](function( err, val ) {
if( done ) return;
if( err ) return done = true, callback(err);
res[ arg ] = val;
--pending || callback(null, res);
});
break;
}
return _;
};
} | [
"function",
"get",
"(",
"obj",
")",
"{",
"var",
"pending",
"=",
"0",
",",
"res",
"=",
"{",
"}",
",",
"callback",
",",
"done",
";",
"return",
"function",
"_",
"(",
"arg",
")",
"{",
"switch",
"(",
"typeof",
"arg",
")",
"{",
"case",
"'function'",
":",
"callback",
"=",
"arg",
";",
"break",
";",
"case",
"'string'",
":",
"++",
"pending",
";",
"obj",
"[",
"arg",
"]",
"(",
"function",
"(",
"err",
",",
"val",
")",
"{",
"if",
"(",
"done",
")",
"return",
";",
"if",
"(",
"err",
")",
"return",
"done",
"=",
"true",
",",
"callback",
"(",
"err",
")",
";",
"res",
"[",
"arg",
"]",
"=",
"val",
";",
"--",
"pending",
"||",
"callback",
"(",
"null",
",",
"res",
")",
";",
"}",
")",
";",
"break",
";",
"}",
"return",
"_",
";",
"}",
";",
"}"
] | Data fetching helper. | [
"Data",
"fetching",
"helper",
"."
] | 87d61503d3d9cc024633efc7611bd25551f0f87d | https://github.com/Automattic/kue/blob/87d61503d3d9cc024633efc7611bd25551f0f87d/lib/http/routes/json.js#L305-L328 |
6,758 | Automattic/kue | lib/http/public/javascripts/main.js | init | function init(state) {
var canvas = o('#loading canvas').get(0)
, ctx = canvas.getContext('2d');
loading = new LoadingIndicator;
loading.ctx = ctx;
loading.size(canvas.width);
pollStats(1000);
show(state)();
o('li.inactive a').click(show('inactive'));
o('li.complete a').click(show('complete'));
o('li.active a').click(show('active'));
o('li.failed a').click(show('failed'));
o('li.delayed a').click(show('delayed'));
o('#filter').change(function () {
filter = $(this).val();
});
o('#sort').change(function () {
sort = $(this).val();
o('#jobs .job').remove();
});
onpopstate = function (e) {
if (e.state) show(e.state.state)();
};
} | javascript | function init(state) {
var canvas = o('#loading canvas').get(0)
, ctx = canvas.getContext('2d');
loading = new LoadingIndicator;
loading.ctx = ctx;
loading.size(canvas.width);
pollStats(1000);
show(state)();
o('li.inactive a').click(show('inactive'));
o('li.complete a').click(show('complete'));
o('li.active a').click(show('active'));
o('li.failed a').click(show('failed'));
o('li.delayed a').click(show('delayed'));
o('#filter').change(function () {
filter = $(this).val();
});
o('#sort').change(function () {
sort = $(this).val();
o('#jobs .job').remove();
});
onpopstate = function (e) {
if (e.state) show(e.state.state)();
};
} | [
"function",
"init",
"(",
"state",
")",
"{",
"var",
"canvas",
"=",
"o",
"(",
"'#loading canvas'",
")",
".",
"get",
"(",
"0",
")",
",",
"ctx",
"=",
"canvas",
".",
"getContext",
"(",
"'2d'",
")",
";",
"loading",
"=",
"new",
"LoadingIndicator",
";",
"loading",
".",
"ctx",
"=",
"ctx",
";",
"loading",
".",
"size",
"(",
"canvas",
".",
"width",
")",
";",
"pollStats",
"(",
"1000",
")",
";",
"show",
"(",
"state",
")",
"(",
")",
";",
"o",
"(",
"'li.inactive a'",
")",
".",
"click",
"(",
"show",
"(",
"'inactive'",
")",
")",
";",
"o",
"(",
"'li.complete a'",
")",
".",
"click",
"(",
"show",
"(",
"'complete'",
")",
")",
";",
"o",
"(",
"'li.active a'",
")",
".",
"click",
"(",
"show",
"(",
"'active'",
")",
")",
";",
"o",
"(",
"'li.failed a'",
")",
".",
"click",
"(",
"show",
"(",
"'failed'",
")",
")",
";",
"o",
"(",
"'li.delayed a'",
")",
".",
"click",
"(",
"show",
"(",
"'delayed'",
")",
")",
";",
"o",
"(",
"'#filter'",
")",
".",
"change",
"(",
"function",
"(",
")",
"{",
"filter",
"=",
"$",
"(",
"this",
")",
".",
"val",
"(",
")",
";",
"}",
")",
";",
"o",
"(",
"'#sort'",
")",
".",
"change",
"(",
"function",
"(",
")",
"{",
"sort",
"=",
"$",
"(",
"this",
")",
".",
"val",
"(",
")",
";",
"o",
"(",
"'#jobs .job'",
")",
".",
"remove",
"(",
")",
";",
"}",
")",
";",
"onpopstate",
"=",
"function",
"(",
"e",
")",
"{",
"if",
"(",
"e",
".",
"state",
")",
"show",
"(",
"e",
".",
"state",
".",
"state",
")",
"(",
")",
";",
"}",
";",
"}"
] | Initialize UI. | [
"Initialize",
"UI",
"."
] | 87d61503d3d9cc024633efc7611bd25551f0f87d | https://github.com/Automattic/kue/blob/87d61503d3d9cc024633efc7611bd25551f0f87d/lib/http/public/javascripts/main.js#L51-L79 |
6,759 | Automattic/kue | lib/http/public/javascripts/main.js | showLoading | function showLoading() {
var n = 0;
o('#loading').show();
showLoading.timer = setInterval(function () {
loading.update(++n).draw(loading.ctx);
}, 50);
} | javascript | function showLoading() {
var n = 0;
o('#loading').show();
showLoading.timer = setInterval(function () {
loading.update(++n).draw(loading.ctx);
}, 50);
} | [
"function",
"showLoading",
"(",
")",
"{",
"var",
"n",
"=",
"0",
";",
"o",
"(",
"'#loading'",
")",
".",
"show",
"(",
")",
";",
"showLoading",
".",
"timer",
"=",
"setInterval",
"(",
"function",
"(",
")",
"{",
"loading",
".",
"update",
"(",
"++",
"n",
")",
".",
"draw",
"(",
"loading",
".",
"ctx",
")",
";",
"}",
",",
"50",
")",
";",
"}"
] | Show loading indicator. | [
"Show",
"loading",
"indicator",
"."
] | 87d61503d3d9cc024633efc7611bd25551f0f87d | https://github.com/Automattic/kue/blob/87d61503d3d9cc024633efc7611bd25551f0f87d/lib/http/public/javascripts/main.js#L85-L91 |
6,760 | Automattic/kue | lib/http/public/javascripts/main.js | infiniteScroll | function infiniteScroll() {
if (infiniteScroll.bound) return;
var body = o('body');
hideLoading();
infiniteScroll.bound = true;
o(window).scroll(function (e) {
var top = body.scrollTop()
, height = body.innerHeight()
, windowHeight = window.innerHeight
, pad = 30;
if (top + windowHeight + pad >= height) {
to += more;
infiniteScroll.bound = false;
showLoading();
o(window).unbind('scroll');
}
});
} | javascript | function infiniteScroll() {
if (infiniteScroll.bound) return;
var body = o('body');
hideLoading();
infiniteScroll.bound = true;
o(window).scroll(function (e) {
var top = body.scrollTop()
, height = body.innerHeight()
, windowHeight = window.innerHeight
, pad = 30;
if (top + windowHeight + pad >= height) {
to += more;
infiniteScroll.bound = false;
showLoading();
o(window).unbind('scroll');
}
});
} | [
"function",
"infiniteScroll",
"(",
")",
"{",
"if",
"(",
"infiniteScroll",
".",
"bound",
")",
"return",
";",
"var",
"body",
"=",
"o",
"(",
"'body'",
")",
";",
"hideLoading",
"(",
")",
";",
"infiniteScroll",
".",
"bound",
"=",
"true",
";",
"o",
"(",
"window",
")",
".",
"scroll",
"(",
"function",
"(",
"e",
")",
"{",
"var",
"top",
"=",
"body",
".",
"scrollTop",
"(",
")",
",",
"height",
"=",
"body",
".",
"innerHeight",
"(",
")",
",",
"windowHeight",
"=",
"window",
".",
"innerHeight",
",",
"pad",
"=",
"30",
";",
"if",
"(",
"top",
"+",
"windowHeight",
"+",
"pad",
">=",
"height",
")",
"{",
"to",
"+=",
"more",
";",
"infiniteScroll",
".",
"bound",
"=",
"false",
";",
"showLoading",
"(",
")",
";",
"o",
"(",
"window",
")",
".",
"unbind",
"(",
"'scroll'",
")",
";",
"}",
"}",
")",
";",
"}"
] | Infinite scroll. | [
"Infinite",
"scroll",
"."
] | 87d61503d3d9cc024633efc7611bd25551f0f87d | https://github.com/Automattic/kue/blob/87d61503d3d9cc024633efc7611bd25551f0f87d/lib/http/public/javascripts/main.js#L106-L125 |
6,761 | Automattic/kue | lib/http/public/javascripts/main.js | show | function show(state) {
return function () {
active = state;
if (pollForJobs.timer) {
clearTimeout(pollForJobs.timer);
delete pollForJobs.timer;
}
history.pushState({ state: state }, state, state);
o('#jobs .job').remove();
o('#menu li a').removeClass('active');
o('#menu li.' + state + ' a').addClass('active');
pollForJobs(state, 1000);
return false;
}
} | javascript | function show(state) {
return function () {
active = state;
if (pollForJobs.timer) {
clearTimeout(pollForJobs.timer);
delete pollForJobs.timer;
}
history.pushState({ state: state }, state, state);
o('#jobs .job').remove();
o('#menu li a').removeClass('active');
o('#menu li.' + state + ' a').addClass('active');
pollForJobs(state, 1000);
return false;
}
} | [
"function",
"show",
"(",
"state",
")",
"{",
"return",
"function",
"(",
")",
"{",
"active",
"=",
"state",
";",
"if",
"(",
"pollForJobs",
".",
"timer",
")",
"{",
"clearTimeout",
"(",
"pollForJobs",
".",
"timer",
")",
";",
"delete",
"pollForJobs",
".",
"timer",
";",
"}",
"history",
".",
"pushState",
"(",
"{",
"state",
":",
"state",
"}",
",",
"state",
",",
"state",
")",
";",
"o",
"(",
"'#jobs .job'",
")",
".",
"remove",
"(",
")",
";",
"o",
"(",
"'#menu li a'",
")",
".",
"removeClass",
"(",
"'active'",
")",
";",
"o",
"(",
"'#menu li.'",
"+",
"state",
"+",
"' a'",
")",
".",
"addClass",
"(",
"'active'",
")",
";",
"pollForJobs",
"(",
"state",
",",
"1000",
")",
";",
"return",
"false",
";",
"}",
"}"
] | Show jobs with `state`.
@param {String} state
@param {Boolean} init
@return {Function} | [
"Show",
"jobs",
"with",
"state",
"."
] | 87d61503d3d9cc024633efc7611bd25551f0f87d | https://github.com/Automattic/kue/blob/87d61503d3d9cc024633efc7611bd25551f0f87d/lib/http/public/javascripts/main.js#L135-L149 |
6,762 | Automattic/kue | lib/http/public/javascripts/main.js | pollForJobs | function pollForJobs(state, ms) {
o('h1').text(state);
refreshJobs(state, function () {
infiniteScroll();
if (!pollForJobs.timer) pollForJobs.timer = setTimeout(function () {
delete pollForJobs.timer;
pollForJobs(state, ms);
}, ms);
});
} | javascript | function pollForJobs(state, ms) {
o('h1').text(state);
refreshJobs(state, function () {
infiniteScroll();
if (!pollForJobs.timer) pollForJobs.timer = setTimeout(function () {
delete pollForJobs.timer;
pollForJobs(state, ms);
}, ms);
});
} | [
"function",
"pollForJobs",
"(",
"state",
",",
"ms",
")",
"{",
"o",
"(",
"'h1'",
")",
".",
"text",
"(",
"state",
")",
";",
"refreshJobs",
"(",
"state",
",",
"function",
"(",
")",
"{",
"infiniteScroll",
"(",
")",
";",
"if",
"(",
"!",
"pollForJobs",
".",
"timer",
")",
"pollForJobs",
".",
"timer",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"delete",
"pollForJobs",
".",
"timer",
";",
"pollForJobs",
"(",
"state",
",",
"ms",
")",
";",
"}",
",",
"ms",
")",
";",
"}",
")",
";",
"}"
] | Poll for jobs with `state` every `ms`.
@param {String} state
@param {Number} ms | [
"Poll",
"for",
"jobs",
"with",
"state",
"every",
"ms",
"."
] | 87d61503d3d9cc024633efc7611bd25551f0f87d | https://github.com/Automattic/kue/blob/87d61503d3d9cc024633efc7611bd25551f0f87d/lib/http/public/javascripts/main.js#L158-L167 |
6,763 | Automattic/kue | lib/http/public/javascripts/main.js | refreshJobs | function refreshJobs(state, fn) {
// TODO: clean this crap up
var jobHeight = o('#jobs .job .block').outerHeight(true)
, top = o(window).scrollTop()
, height = window.innerHeight
, visibleFrom = Math.max(0, Math.floor(top / jobHeight))
, visibleTo = Math.floor((top + height) / jobHeight)
, url = './jobs/'
+ (filter ? filter + '/' : '')
+ state + '/0..' + to
+ '/' + sort;
// var color = ['blue', 'red', 'yellow', 'green', 'purple'][Math.random() * 5 | 0];
request(url, function (jobs) {
var len = jobs.length
, job
, el;
// remove jobs which have changed their state
o('#jobs .job').each(function (i, el) {
var el = $(el)
, id = (el.attr('id') || '').replace('job-', '')
, found = jobs.some(function (job) {
return job && id == job.id;
});
if (!found) el.remove();
});
for (var i = 0; i < len; ++i) {
if (!jobs[i]) continue;
// exists
if (o('#job-' + jobs[i].id).length) {
if (i < visibleFrom || i > visibleTo) continue;
el = o('#job-' + jobs[i].id);
// el.css('background-color', color);
job = el.get(0).job;
job.update(jobs[i])
.showProgress('active' == active)
.showErrorMessage('failed' == active)
.render();
// new
} else {
job = new Job(jobs[i]);
el = job.showProgress('active' == active)
.showErrorMessage('failed' == active)
.render(true);
el.get(0).job = job;
el.appendTo('#jobs');
}
}
fn();
});
} | javascript | function refreshJobs(state, fn) {
// TODO: clean this crap up
var jobHeight = o('#jobs .job .block').outerHeight(true)
, top = o(window).scrollTop()
, height = window.innerHeight
, visibleFrom = Math.max(0, Math.floor(top / jobHeight))
, visibleTo = Math.floor((top + height) / jobHeight)
, url = './jobs/'
+ (filter ? filter + '/' : '')
+ state + '/0..' + to
+ '/' + sort;
// var color = ['blue', 'red', 'yellow', 'green', 'purple'][Math.random() * 5 | 0];
request(url, function (jobs) {
var len = jobs.length
, job
, el;
// remove jobs which have changed their state
o('#jobs .job').each(function (i, el) {
var el = $(el)
, id = (el.attr('id') || '').replace('job-', '')
, found = jobs.some(function (job) {
return job && id == job.id;
});
if (!found) el.remove();
});
for (var i = 0; i < len; ++i) {
if (!jobs[i]) continue;
// exists
if (o('#job-' + jobs[i].id).length) {
if (i < visibleFrom || i > visibleTo) continue;
el = o('#job-' + jobs[i].id);
// el.css('background-color', color);
job = el.get(0).job;
job.update(jobs[i])
.showProgress('active' == active)
.showErrorMessage('failed' == active)
.render();
// new
} else {
job = new Job(jobs[i]);
el = job.showProgress('active' == active)
.showErrorMessage('failed' == active)
.render(true);
el.get(0).job = job;
el.appendTo('#jobs');
}
}
fn();
});
} | [
"function",
"refreshJobs",
"(",
"state",
",",
"fn",
")",
"{",
"// TODO: clean this crap up",
"var",
"jobHeight",
"=",
"o",
"(",
"'#jobs .job .block'",
")",
".",
"outerHeight",
"(",
"true",
")",
",",
"top",
"=",
"o",
"(",
"window",
")",
".",
"scrollTop",
"(",
")",
",",
"height",
"=",
"window",
".",
"innerHeight",
",",
"visibleFrom",
"=",
"Math",
".",
"max",
"(",
"0",
",",
"Math",
".",
"floor",
"(",
"top",
"/",
"jobHeight",
")",
")",
",",
"visibleTo",
"=",
"Math",
".",
"floor",
"(",
"(",
"top",
"+",
"height",
")",
"/",
"jobHeight",
")",
",",
"url",
"=",
"'./jobs/'",
"+",
"(",
"filter",
"?",
"filter",
"+",
"'/'",
":",
"''",
")",
"+",
"state",
"+",
"'/0..'",
"+",
"to",
"+",
"'/'",
"+",
"sort",
";",
"// var color = ['blue', 'red', 'yellow', 'green', 'purple'][Math.random() * 5 | 0];",
"request",
"(",
"url",
",",
"function",
"(",
"jobs",
")",
"{",
"var",
"len",
"=",
"jobs",
".",
"length",
",",
"job",
",",
"el",
";",
"// remove jobs which have changed their state",
"o",
"(",
"'#jobs .job'",
")",
".",
"each",
"(",
"function",
"(",
"i",
",",
"el",
")",
"{",
"var",
"el",
"=",
"$",
"(",
"el",
")",
",",
"id",
"=",
"(",
"el",
".",
"attr",
"(",
"'id'",
")",
"||",
"''",
")",
".",
"replace",
"(",
"'job-'",
",",
"''",
")",
",",
"found",
"=",
"jobs",
".",
"some",
"(",
"function",
"(",
"job",
")",
"{",
"return",
"job",
"&&",
"id",
"==",
"job",
".",
"id",
";",
"}",
")",
";",
"if",
"(",
"!",
"found",
")",
"el",
".",
"remove",
"(",
")",
";",
"}",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"++",
"i",
")",
"{",
"if",
"(",
"!",
"jobs",
"[",
"i",
"]",
")",
"continue",
";",
"// exists",
"if",
"(",
"o",
"(",
"'#job-'",
"+",
"jobs",
"[",
"i",
"]",
".",
"id",
")",
".",
"length",
")",
"{",
"if",
"(",
"i",
"<",
"visibleFrom",
"||",
"i",
">",
"visibleTo",
")",
"continue",
";",
"el",
"=",
"o",
"(",
"'#job-'",
"+",
"jobs",
"[",
"i",
"]",
".",
"id",
")",
";",
"// el.css('background-color', color);",
"job",
"=",
"el",
".",
"get",
"(",
"0",
")",
".",
"job",
";",
"job",
".",
"update",
"(",
"jobs",
"[",
"i",
"]",
")",
".",
"showProgress",
"(",
"'active'",
"==",
"active",
")",
".",
"showErrorMessage",
"(",
"'failed'",
"==",
"active",
")",
".",
"render",
"(",
")",
";",
"// new",
"}",
"else",
"{",
"job",
"=",
"new",
"Job",
"(",
"jobs",
"[",
"i",
"]",
")",
";",
"el",
"=",
"job",
".",
"showProgress",
"(",
"'active'",
"==",
"active",
")",
".",
"showErrorMessage",
"(",
"'failed'",
"==",
"active",
")",
".",
"render",
"(",
"true",
")",
";",
"el",
".",
"get",
"(",
"0",
")",
".",
"job",
"=",
"job",
";",
"el",
".",
"appendTo",
"(",
"'#jobs'",
")",
";",
"}",
"}",
"fn",
"(",
")",
";",
"}",
")",
";",
"}"
] | Re-request and refresh job elements.
@param {String} state
@param {Function} fn | [
"Re",
"-",
"request",
"and",
"refresh",
"job",
"elements",
"."
] | 87d61503d3d9cc024633efc7611bd25551f0f87d | https://github.com/Automattic/kue/blob/87d61503d3d9cc024633efc7611bd25551f0f87d/lib/http/public/javascripts/main.js#L176-L232 |
6,764 | Automattic/kue | lib/http/public/javascripts/main.js | pollStats | function pollStats(ms) {
request('./stats', function (data) {
o('li.inactive .count').text(data.inactiveCount);
o('li.active .count').text(data.activeCount);
o('li.complete .count').text(data.completeCount);
o('li.failed .count').text(data.failedCount);
o('li.delayed .count').text(data.delayedCount);
setTimeout(function () {
pollStats(ms);
}, ms);
});
} | javascript | function pollStats(ms) {
request('./stats', function (data) {
o('li.inactive .count').text(data.inactiveCount);
o('li.active .count').text(data.activeCount);
o('li.complete .count').text(data.completeCount);
o('li.failed .count').text(data.failedCount);
o('li.delayed .count').text(data.delayedCount);
setTimeout(function () {
pollStats(ms);
}, ms);
});
} | [
"function",
"pollStats",
"(",
"ms",
")",
"{",
"request",
"(",
"'./stats'",
",",
"function",
"(",
"data",
")",
"{",
"o",
"(",
"'li.inactive .count'",
")",
".",
"text",
"(",
"data",
".",
"inactiveCount",
")",
";",
"o",
"(",
"'li.active .count'",
")",
".",
"text",
"(",
"data",
".",
"activeCount",
")",
";",
"o",
"(",
"'li.complete .count'",
")",
".",
"text",
"(",
"data",
".",
"completeCount",
")",
";",
"o",
"(",
"'li.failed .count'",
")",
".",
"text",
"(",
"data",
".",
"failedCount",
")",
";",
"o",
"(",
"'li.delayed .count'",
")",
".",
"text",
"(",
"data",
".",
"delayedCount",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"pollStats",
"(",
"ms",
")",
";",
"}",
",",
"ms",
")",
";",
"}",
")",
";",
"}"
] | Poll for stats every `ms`.
@param {Number} ms | [
"Poll",
"for",
"stats",
"every",
"ms",
"."
] | 87d61503d3d9cc024633efc7611bd25551f0f87d | https://github.com/Automattic/kue/blob/87d61503d3d9cc024633efc7611bd25551f0f87d/lib/http/public/javascripts/main.js#L240-L251 |
6,765 | Automattic/kue | examples/events.js | create | function create() {
var name = [ 'tobi', 'loki', 'jane', 'manny' ][ Math.random() * 4 | 0 ];
var job = jobs.create( 'video conversion', {
title: 'converting ' + name + '\'s to avi', user: 1, frames: 200
} );
job.on( 'complete', function () {
console.log( " Job complete" );
} ).on( 'failed', function () {
console.log( " Job failed" );
} ).on( 'progress', function ( progress ) {
process.stdout.write( '\r job #' + job.id + ' ' + progress + '% complete' );
} );
job.save();
setTimeout( create, Math.random() * 2000 | 0 );
} | javascript | function create() {
var name = [ 'tobi', 'loki', 'jane', 'manny' ][ Math.random() * 4 | 0 ];
var job = jobs.create( 'video conversion', {
title: 'converting ' + name + '\'s to avi', user: 1, frames: 200
} );
job.on( 'complete', function () {
console.log( " Job complete" );
} ).on( 'failed', function () {
console.log( " Job failed" );
} ).on( 'progress', function ( progress ) {
process.stdout.write( '\r job #' + job.id + ' ' + progress + '% complete' );
} );
job.save();
setTimeout( create, Math.random() * 2000 | 0 );
} | [
"function",
"create",
"(",
")",
"{",
"var",
"name",
"=",
"[",
"'tobi'",
",",
"'loki'",
",",
"'jane'",
",",
"'manny'",
"]",
"[",
"Math",
".",
"random",
"(",
")",
"*",
"4",
"|",
"0",
"]",
";",
"var",
"job",
"=",
"jobs",
".",
"create",
"(",
"'video conversion'",
",",
"{",
"title",
":",
"'converting '",
"+",
"name",
"+",
"'\\'s to avi'",
",",
"user",
":",
"1",
",",
"frames",
":",
"200",
"}",
")",
";",
"job",
".",
"on",
"(",
"'complete'",
",",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
"\" Job complete\"",
")",
";",
"}",
")",
".",
"on",
"(",
"'failed'",
",",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
"\" Job failed\"",
")",
";",
"}",
")",
".",
"on",
"(",
"'progress'",
",",
"function",
"(",
"progress",
")",
"{",
"process",
".",
"stdout",
".",
"write",
"(",
"'\\r job #'",
"+",
"job",
".",
"id",
"+",
"' '",
"+",
"progress",
"+",
"'% complete'",
")",
";",
"}",
")",
";",
"job",
".",
"save",
"(",
")",
";",
"setTimeout",
"(",
"create",
",",
"Math",
".",
"random",
"(",
")",
"*",
"2000",
"|",
"0",
")",
";",
"}"
] | create some jobs at random, usually you would create these in your http processes upon user input etc. | [
"create",
"some",
"jobs",
"at",
"random",
"usually",
"you",
"would",
"create",
"these",
"in",
"your",
"http",
"processes",
"upon",
"user",
"input",
"etc",
"."
] | 87d61503d3d9cc024633efc7611bd25551f0f87d | https://github.com/Automattic/kue/blob/87d61503d3d9cc024633efc7611bd25551f0f87d/examples/events.js#L14-L31 |
6,766 | google/marzipano | src/util/compose.js | compose | function compose() {
var fnList = arguments;
return function composed(initialArg) {
var ret = initialArg;
for (var i = 0; i < fnList.length; i++) {
var fn = fnList[i];
ret = fn.call(null, ret);
}
return ret;
};
} | javascript | function compose() {
var fnList = arguments;
return function composed(initialArg) {
var ret = initialArg;
for (var i = 0; i < fnList.length; i++) {
var fn = fnList[i];
ret = fn.call(null, ret);
}
return ret;
};
} | [
"function",
"compose",
"(",
")",
"{",
"var",
"fnList",
"=",
"arguments",
";",
"return",
"function",
"composed",
"(",
"initialArg",
")",
"{",
"var",
"ret",
"=",
"initialArg",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"fnList",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"fn",
"=",
"fnList",
"[",
"i",
"]",
";",
"ret",
"=",
"fn",
".",
"call",
"(",
"null",
",",
"ret",
")",
";",
"}",
"return",
"ret",
";",
"}",
";",
"}"
] | Compose multiple functions
`compose(f, g)` returns `function(x) { return f(g(x)); }`
@memberof util
@param {Function[]} functions The functions to compose
@return {Function} | [
"Compose",
"multiple",
"functions"
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/util/compose.js#L27-L37 |
6,767 | google/marzipano | src/Viewer.js | tweenDone | function tweenDone() {
if (self._replacedScene) {
self._removeSceneEventListeners(self._replacedScene);
oldSceneLayers = self._replacedScene.listLayers();
for (var i = 0; i < oldSceneLayers.length; i++) {
self._removeLayerFromStage(oldSceneLayers[i]);
}
self._replacedScene = null;
}
self._cancelCurrentTween = null;
done();
} | javascript | function tweenDone() {
if (self._replacedScene) {
self._removeSceneEventListeners(self._replacedScene);
oldSceneLayers = self._replacedScene.listLayers();
for (var i = 0; i < oldSceneLayers.length; i++) {
self._removeLayerFromStage(oldSceneLayers[i]);
}
self._replacedScene = null;
}
self._cancelCurrentTween = null;
done();
} | [
"function",
"tweenDone",
"(",
")",
"{",
"if",
"(",
"self",
".",
"_replacedScene",
")",
"{",
"self",
".",
"_removeSceneEventListeners",
"(",
"self",
".",
"_replacedScene",
")",
";",
"oldSceneLayers",
"=",
"self",
".",
"_replacedScene",
".",
"listLayers",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"oldSceneLayers",
".",
"length",
";",
"i",
"++",
")",
"{",
"self",
".",
"_removeLayerFromStage",
"(",
"oldSceneLayers",
"[",
"i",
"]",
")",
";",
"}",
"self",
".",
"_replacedScene",
"=",
"null",
";",
"}",
"self",
".",
"_cancelCurrentTween",
"=",
"null",
";",
"done",
"(",
")",
";",
"}"
] | Once the transition is complete, remove old scene layers from the stage and remove the event listeners. If the old scene was destroyed during the transition, this has already been taken care of. Otherwise, we still need to get a fresh copy of the scene's layers, since they might have changed during the transition. | [
"Once",
"the",
"transition",
"is",
"complete",
"remove",
"old",
"scene",
"layers",
"from",
"the",
"stage",
"and",
"remove",
"the",
"event",
"listeners",
".",
"If",
"the",
"old",
"scene",
"was",
"destroyed",
"during",
"the",
"transition",
"this",
"has",
"already",
"been",
"taken",
"care",
"of",
".",
"Otherwise",
"we",
"still",
"need",
"to",
"get",
"a",
"fresh",
"copy",
"of",
"the",
"scene",
"s",
"layers",
"since",
"they",
"might",
"have",
"changed",
"during",
"the",
"transition",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/Viewer.js#L763-L774 |
6,768 | google/marzipano | src/geometries/Cube.js | rotateVector | function rotateVector(vec, z, x, y) {
if (z) {
vec3.rotateZ(vec, vec, origin, z);
}
if (x) {
vec3.rotateX(vec, vec, origin, x);
}
if (y) {
vec3.rotateY(vec, vec, origin, y);
}
} | javascript | function rotateVector(vec, z, x, y) {
if (z) {
vec3.rotateZ(vec, vec, origin, z);
}
if (x) {
vec3.rotateX(vec, vec, origin, x);
}
if (y) {
vec3.rotateY(vec, vec, origin, y);
}
} | [
"function",
"rotateVector",
"(",
"vec",
",",
"z",
",",
"x",
",",
"y",
")",
"{",
"if",
"(",
"z",
")",
"{",
"vec3",
".",
"rotateZ",
"(",
"vec",
",",
"vec",
",",
"origin",
",",
"z",
")",
";",
"}",
"if",
"(",
"x",
")",
"{",
"vec3",
".",
"rotateX",
"(",
"vec",
",",
"vec",
",",
"origin",
",",
"x",
")",
";",
"}",
"if",
"(",
"y",
")",
"{",
"vec3",
".",
"rotateY",
"(",
"vec",
",",
"vec",
",",
"origin",
",",
"y",
")",
";",
"}",
"}"
] | Rotate a vector in ZXY order. | [
"Rotate",
"a",
"vector",
"in",
"ZXY",
"order",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/geometries/Cube.js#L74-L84 |
6,769 | google/marzipano | demos/sample-tour/index.js | stopTouchAndScrollEventPropagation | function stopTouchAndScrollEventPropagation(element, eventList) {
var eventList = [ 'touchstart', 'touchmove', 'touchend', 'touchcancel',
'wheel', 'mousewheel' ];
for (var i = 0; i < eventList.length; i++) {
element.addEventListener(eventList[i], function(event) {
event.stopPropagation();
});
}
} | javascript | function stopTouchAndScrollEventPropagation(element, eventList) {
var eventList = [ 'touchstart', 'touchmove', 'touchend', 'touchcancel',
'wheel', 'mousewheel' ];
for (var i = 0; i < eventList.length; i++) {
element.addEventListener(eventList[i], function(event) {
event.stopPropagation();
});
}
} | [
"function",
"stopTouchAndScrollEventPropagation",
"(",
"element",
",",
"eventList",
")",
"{",
"var",
"eventList",
"=",
"[",
"'touchstart'",
",",
"'touchmove'",
",",
"'touchend'",
",",
"'touchcancel'",
",",
"'wheel'",
",",
"'mousewheel'",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"eventList",
".",
"length",
";",
"i",
"++",
")",
"{",
"element",
".",
"addEventListener",
"(",
"eventList",
"[",
"i",
"]",
",",
"function",
"(",
"event",
")",
"{",
"event",
".",
"stopPropagation",
"(",
")",
";",
"}",
")",
";",
"}",
"}"
] | Prevent touch and scroll events from reaching the parent element. | [
"Prevent",
"touch",
"and",
"scroll",
"events",
"from",
"reaching",
"the",
"parent",
"element",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/demos/sample-tour/index.js#L361-L369 |
6,770 | google/marzipano | demos/device-orientation/DeviceOrientationControlMethod.js | DeviceOrientationControlMethod | function DeviceOrientationControlMethod() {
this._dynamics = {
yaw: new Marzipano.Dynamics(),
pitch: new Marzipano.Dynamics()
};
this._deviceOrientationHandler = this._handleData.bind(this);
if (window.DeviceOrientationEvent) {
window.addEventListener('deviceorientation', this._deviceOrientationHandler);
}
this._previous = {};
this._current = {};
this._tmp = {};
this._getPitchCallbacks = [];
} | javascript | function DeviceOrientationControlMethod() {
this._dynamics = {
yaw: new Marzipano.Dynamics(),
pitch: new Marzipano.Dynamics()
};
this._deviceOrientationHandler = this._handleData.bind(this);
if (window.DeviceOrientationEvent) {
window.addEventListener('deviceorientation', this._deviceOrientationHandler);
}
this._previous = {};
this._current = {};
this._tmp = {};
this._getPitchCallbacks = [];
} | [
"function",
"DeviceOrientationControlMethod",
"(",
")",
"{",
"this",
".",
"_dynamics",
"=",
"{",
"yaw",
":",
"new",
"Marzipano",
".",
"Dynamics",
"(",
")",
",",
"pitch",
":",
"new",
"Marzipano",
".",
"Dynamics",
"(",
")",
"}",
";",
"this",
".",
"_deviceOrientationHandler",
"=",
"this",
".",
"_handleData",
".",
"bind",
"(",
"this",
")",
";",
"if",
"(",
"window",
".",
"DeviceOrientationEvent",
")",
"{",
"window",
".",
"addEventListener",
"(",
"'deviceorientation'",
",",
"this",
".",
"_deviceOrientationHandler",
")",
";",
"}",
"this",
".",
"_previous",
"=",
"{",
"}",
";",
"this",
".",
"_current",
"=",
"{",
"}",
";",
"this",
".",
"_tmp",
"=",
"{",
"}",
";",
"this",
".",
"_getPitchCallbacks",
"=",
"[",
"]",
";",
"}"
] | Custom control method to alter the view according to the device orientation. | [
"Custom",
"control",
"method",
"to",
"alter",
"the",
"view",
"according",
"to",
"the",
"device",
"orientation",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/demos/device-orientation/DeviceOrientationControlMethod.js#L19-L36 |
6,771 | google/marzipano | src/support/Css.js | checkCssSupported | function checkCssSupported() {
// First, check if the 'perspective' CSS property or a vendor-prefixed
// variant is available.
var perspectiveProperty = prefixProperty('perspective');
var el = document.createElement('div');
var supported = typeof el.style[perspectiveProperty] !== 'undefined';
// Certain versions of Chrome disable 3D transforms even though the CSS
// property exists. In those cases, we use the following media query,
// which only succeeds if the feature is indeed enabled.
if (supported && perspectiveProperty === 'WebkitPerspective') {
var id = '__marzipano_test_css3d_support__';
var st = document.createElement('style');
st.textContent = '@media(-webkit-transform-3d){#' + id + '{height: 3px;})';
document.getElementsByTagName('head')[0].appendChild(st);
el.id = id;
document.body.appendChild(el);
// The offsetHeight seems to be different than 3 at some zoom levels on
// Chrome (and maybe other browsers). Test for > 0 instead.
supported = el.offsetHeight > 0;
st.parentNode.removeChild(st);
el.parentNode.removeChild(el);
}
return supported;
} | javascript | function checkCssSupported() {
// First, check if the 'perspective' CSS property or a vendor-prefixed
// variant is available.
var perspectiveProperty = prefixProperty('perspective');
var el = document.createElement('div');
var supported = typeof el.style[perspectiveProperty] !== 'undefined';
// Certain versions of Chrome disable 3D transforms even though the CSS
// property exists. In those cases, we use the following media query,
// which only succeeds if the feature is indeed enabled.
if (supported && perspectiveProperty === 'WebkitPerspective') {
var id = '__marzipano_test_css3d_support__';
var st = document.createElement('style');
st.textContent = '@media(-webkit-transform-3d){#' + id + '{height: 3px;})';
document.getElementsByTagName('head')[0].appendChild(st);
el.id = id;
document.body.appendChild(el);
// The offsetHeight seems to be different than 3 at some zoom levels on
// Chrome (and maybe other browsers). Test for > 0 instead.
supported = el.offsetHeight > 0;
st.parentNode.removeChild(st);
el.parentNode.removeChild(el);
}
return supported;
} | [
"function",
"checkCssSupported",
"(",
")",
"{",
"// First, check if the 'perspective' CSS property or a vendor-prefixed",
"// variant is available.",
"var",
"perspectiveProperty",
"=",
"prefixProperty",
"(",
"'perspective'",
")",
";",
"var",
"el",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
";",
"var",
"supported",
"=",
"typeof",
"el",
".",
"style",
"[",
"perspectiveProperty",
"]",
"!==",
"'undefined'",
";",
"// Certain versions of Chrome disable 3D transforms even though the CSS",
"// property exists. In those cases, we use the following media query,",
"// which only succeeds if the feature is indeed enabled.",
"if",
"(",
"supported",
"&&",
"perspectiveProperty",
"===",
"'WebkitPerspective'",
")",
"{",
"var",
"id",
"=",
"'__marzipano_test_css3d_support__'",
";",
"var",
"st",
"=",
"document",
".",
"createElement",
"(",
"'style'",
")",
";",
"st",
".",
"textContent",
"=",
"'@media(-webkit-transform-3d){#'",
"+",
"id",
"+",
"'{height: 3px;})'",
";",
"document",
".",
"getElementsByTagName",
"(",
"'head'",
")",
"[",
"0",
"]",
".",
"appendChild",
"(",
"st",
")",
";",
"el",
".",
"id",
"=",
"id",
";",
"document",
".",
"body",
".",
"appendChild",
"(",
"el",
")",
";",
"// The offsetHeight seems to be different than 3 at some zoom levels on",
"// Chrome (and maybe other browsers). Test for > 0 instead.",
"supported",
"=",
"el",
".",
"offsetHeight",
">",
"0",
";",
"st",
".",
"parentNode",
".",
"removeChild",
"(",
"st",
")",
";",
"el",
".",
"parentNode",
".",
"removeChild",
"(",
"el",
")",
";",
"}",
"return",
"supported",
";",
"}"
] | Detect CSS 3D transforms support. Adapted from Modernizr. | [
"Detect",
"CSS",
"3D",
"transforms",
"support",
".",
"Adapted",
"from",
"Modernizr",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/support/Css.js#L21-L46 |
6,772 | google/marzipano | src/colorEffects.js | applyToPixel | function applyToPixel(pixel, effect, result) {
vec4TransformMat4Transposed(result, pixel, effect.colorMatrix);
vec4.add(result, result, effect.colorOffset);
} | javascript | function applyToPixel(pixel, effect, result) {
vec4TransformMat4Transposed(result, pixel, effect.colorMatrix);
vec4.add(result, result, effect.colorOffset);
} | [
"function",
"applyToPixel",
"(",
"pixel",
",",
"effect",
",",
"result",
")",
"{",
"vec4TransformMat4Transposed",
"(",
"result",
",",
"pixel",
",",
"effect",
".",
"colorMatrix",
")",
";",
"vec4",
".",
"add",
"(",
"result",
",",
"result",
",",
"effect",
".",
"colorOffset",
")",
";",
"}"
] | Apply color effects to a single pixel
@param {vec4} pixel Values in range [0,1]
@param {Object} effect
@param {vec4} effect.colorOffset
@param {mat4} effect.colorMatrix
@param {vec4} result Object to store result
@memberof colorEffects | [
"Apply",
"color",
"effects",
"to",
"a",
"single",
"pixel"
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/colorEffects.js#L61-L64 |
6,773 | google/marzipano | src/TextureStore.js | TextureStore | function TextureStore(source, stage, opts) {
opts = defaults(opts || {}, defaultOptions);
this._source = source;
this._stage = stage;
// The current state.
this._state = State.IDLE;
// The number of startFrame calls yet to be matched by endFrame calls during
// the current frame.
this._delimCount = 0;
// The cache proper: map cached tiles to their respective textures/assets.
this._itemMap = new Map();
// The subset of cached tiles that are currently visible.
this._visible = new Set();
// The subset of cached tiles that were visible recently, but are not
// visible right now. Newly inserted tiles replace older ones.
this._previouslyVisible = new LruSet(opts.previouslyVisibleCacheSize);
// The subset of cached tiles that should never be evicted from the cache.
// A tile may be pinned more than once; map each tile into a reference count.
this._pinMap = new Map();
// Temporary variables.
this._newVisible = new Set();
this._noLongerVisible = [];
this._visibleAgain = [];
this._evicted = [];
} | javascript | function TextureStore(source, stage, opts) {
opts = defaults(opts || {}, defaultOptions);
this._source = source;
this._stage = stage;
// The current state.
this._state = State.IDLE;
// The number of startFrame calls yet to be matched by endFrame calls during
// the current frame.
this._delimCount = 0;
// The cache proper: map cached tiles to their respective textures/assets.
this._itemMap = new Map();
// The subset of cached tiles that are currently visible.
this._visible = new Set();
// The subset of cached tiles that were visible recently, but are not
// visible right now. Newly inserted tiles replace older ones.
this._previouslyVisible = new LruSet(opts.previouslyVisibleCacheSize);
// The subset of cached tiles that should never be evicted from the cache.
// A tile may be pinned more than once; map each tile into a reference count.
this._pinMap = new Map();
// Temporary variables.
this._newVisible = new Set();
this._noLongerVisible = [];
this._visibleAgain = [];
this._evicted = [];
} | [
"function",
"TextureStore",
"(",
"source",
",",
"stage",
",",
"opts",
")",
"{",
"opts",
"=",
"defaults",
"(",
"opts",
"||",
"{",
"}",
",",
"defaultOptions",
")",
";",
"this",
".",
"_source",
"=",
"source",
";",
"this",
".",
"_stage",
"=",
"stage",
";",
"// The current state.",
"this",
".",
"_state",
"=",
"State",
".",
"IDLE",
";",
"// The number of startFrame calls yet to be matched by endFrame calls during",
"// the current frame.",
"this",
".",
"_delimCount",
"=",
"0",
";",
"// The cache proper: map cached tiles to their respective textures/assets.",
"this",
".",
"_itemMap",
"=",
"new",
"Map",
"(",
")",
";",
"// The subset of cached tiles that are currently visible.",
"this",
".",
"_visible",
"=",
"new",
"Set",
"(",
")",
";",
"// The subset of cached tiles that were visible recently, but are not",
"// visible right now. Newly inserted tiles replace older ones.",
"this",
".",
"_previouslyVisible",
"=",
"new",
"LruSet",
"(",
"opts",
".",
"previouslyVisibleCacheSize",
")",
";",
"// The subset of cached tiles that should never be evicted from the cache.",
"// A tile may be pinned more than once; map each tile into a reference count.",
"this",
".",
"_pinMap",
"=",
"new",
"Map",
"(",
")",
";",
"// Temporary variables.",
"this",
".",
"_newVisible",
"=",
"new",
"Set",
"(",
")",
";",
"this",
".",
"_noLongerVisible",
"=",
"[",
"]",
";",
"this",
".",
"_visibleAgain",
"=",
"[",
"]",
";",
"this",
".",
"_evicted",
"=",
"[",
"]",
";",
"}"
] | Signals that loading a texture has failed.
This event may follow {@link TextureStore#textureStartLoad} if the texture
fails to load.
@event TextureStore#textureError
@param {Tile} tile The tile for which the texture loading has failed.
@class TextureStore
@classdesc
A TextureStore maintains a cache of textures used to render a {@link Layer}.
A {@link Stage} communicates with the TextureStore through the startFrame(),
markTile() and endFrame() methods, which indicate the tiles that are visible
in the current frame. Textures for visible tiles are loaded and retained
as long as the tiles remain visible. A limited amount of textures whose
tiles were previously visible are cached according to an LRU policy. Tiles
may be pinned to keep their respective textures cached even when they are
invisible; these textures do not count towards the previously visible limit.
Multiple layers belonging to the same underlying {@link WebGlStage} may
share the same TextureStore. Layers belonging to distinct {@link WebGlStage}
instances, or belonging to a {@link CssStage} or a {@link FlashStage},
may not do so due to restrictions on the use of textures across stages.
@param {Source} source The underlying source.
@param {Stage} stage The underlying stage.
@param {Object} opts Options.
@param {Number} [opts.previouslyVisibleCacheSize=32] The maximum number of
previously visible textures to cache according to an LRU policy. | [
"Signals",
"that",
"loading",
"a",
"texture",
"has",
"failed",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/TextureStore.js#L297-L329 |
6,774 | google/marzipano | src/util/retry.js | retry | function retry(fn) {
return function retried() {
var args = arguments.length ? Array.prototype.slice.call(arguments, 0, arguments.length - 1) : [];
var done = arguments.length ? arguments[arguments.length - 1] : noop;
var cfn = null;
var canceled = false;
function exec() {
var err = arguments[0];
if (!err || canceled) {
done.apply(null, arguments);
} else {
cfn = fn.apply(null, args);
}
}
args.push(exec);
exec(true);
return function cancel() {
canceled = true;
cfn.apply(null, arguments);
};
};
} | javascript | function retry(fn) {
return function retried() {
var args = arguments.length ? Array.prototype.slice.call(arguments, 0, arguments.length - 1) : [];
var done = arguments.length ? arguments[arguments.length - 1] : noop;
var cfn = null;
var canceled = false;
function exec() {
var err = arguments[0];
if (!err || canceled) {
done.apply(null, arguments);
} else {
cfn = fn.apply(null, args);
}
}
args.push(exec);
exec(true);
return function cancel() {
canceled = true;
cfn.apply(null, arguments);
};
};
} | [
"function",
"retry",
"(",
"fn",
")",
"{",
"return",
"function",
"retried",
"(",
")",
"{",
"var",
"args",
"=",
"arguments",
".",
"length",
"?",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
",",
"arguments",
".",
"length",
"-",
"1",
")",
":",
"[",
"]",
";",
"var",
"done",
"=",
"arguments",
".",
"length",
"?",
"arguments",
"[",
"arguments",
".",
"length",
"-",
"1",
"]",
":",
"noop",
";",
"var",
"cfn",
"=",
"null",
";",
"var",
"canceled",
"=",
"false",
";",
"function",
"exec",
"(",
")",
"{",
"var",
"err",
"=",
"arguments",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"err",
"||",
"canceled",
")",
"{",
"done",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
";",
"}",
"else",
"{",
"cfn",
"=",
"fn",
".",
"apply",
"(",
"null",
",",
"args",
")",
";",
"}",
"}",
"args",
".",
"push",
"(",
"exec",
")",
";",
"exec",
"(",
"true",
")",
";",
"return",
"function",
"cancel",
"(",
")",
"{",
"canceled",
"=",
"true",
";",
"cfn",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
";",
"}",
";",
"}",
";",
"}"
] | Return a cancelable function that executes fn in a loop until it returns successfully. | [
"Return",
"a",
"cancelable",
"function",
"that",
"executes",
"fn",
"in",
"a",
"loop",
"until",
"it",
"returns",
"successfully",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/util/retry.js#L22-L51 |
6,775 | google/marzipano | demos/fallback-tiles/index.js | ready | function ready() {
for (var i = 0; i < preloadTiles.length; i++) {
var state = layerAbove.textureStore().query(preloadTiles[i]);
if (!state.hasTexture) {
return false;
}
}
return true;
} | javascript | function ready() {
for (var i = 0; i < preloadTiles.length; i++) {
var state = layerAbove.textureStore().query(preloadTiles[i]);
if (!state.hasTexture) {
return false;
}
}
return true;
} | [
"function",
"ready",
"(",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"preloadTiles",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"state",
"=",
"layerAbove",
".",
"textureStore",
"(",
")",
".",
"query",
"(",
"preloadTiles",
"[",
"i",
"]",
")",
";",
"if",
"(",
"!",
"state",
".",
"hasTexture",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Check whether all tiles have loaded. | [
"Check",
"whether",
"all",
"tiles",
"have",
"loaded",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/demos/fallback-tiles/index.js#L126-L134 |
6,776 | google/marzipano | src/renderers/WebGlCommon.js | setViewport | function setViewport(gl, layer, rect, viewportMatrix) {
if (rect.x === 0 && rect.width === 1 && rect.y === 0 && rect.height === 1) {
// Fast path for full rect.
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
mat4.identity(viewportMatrix);
return;
}
var offsetX = rect.x;
var clampedOffsetX = clamp(offsetX, 0, 1);
var leftExcess = clampedOffsetX - offsetX;
var maxClampedWidth = 1 - clampedOffsetX;
var clampedWidth = clamp(rect.width - leftExcess, 0, maxClampedWidth);
var rightExcess = rect.width - clampedWidth;
var offsetY = 1 - rect.height - rect.y;
var clampedOffsetY = clamp(offsetY, 0, 1);
var bottomExcess = clampedOffsetY - offsetY;
var maxClampedHeight = 1 - clampedOffsetY;
var clampedHeight = clamp(rect.height - bottomExcess, 0, maxClampedHeight);
var topExcess = rect.height - clampedHeight;
vec3.set(
scaleVector,
rect.width / clampedWidth,
rect.height / clampedHeight,
1);
vec3.set(
translateVector,
(rightExcess - leftExcess) / clampedWidth,
(topExcess - bottomExcess) / clampedHeight,
0);
mat4.identity(viewportMatrix);
mat4.translate(viewportMatrix, viewportMatrix, translateVector);
mat4.scale(viewportMatrix, viewportMatrix, scaleVector);
gl.viewport(gl.drawingBufferWidth * clampedOffsetX,
gl.drawingBufferHeight * clampedOffsetY,
gl.drawingBufferWidth * clampedWidth,
gl.drawingBufferHeight * clampedHeight);
} | javascript | function setViewport(gl, layer, rect, viewportMatrix) {
if (rect.x === 0 && rect.width === 1 && rect.y === 0 && rect.height === 1) {
// Fast path for full rect.
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
mat4.identity(viewportMatrix);
return;
}
var offsetX = rect.x;
var clampedOffsetX = clamp(offsetX, 0, 1);
var leftExcess = clampedOffsetX - offsetX;
var maxClampedWidth = 1 - clampedOffsetX;
var clampedWidth = clamp(rect.width - leftExcess, 0, maxClampedWidth);
var rightExcess = rect.width - clampedWidth;
var offsetY = 1 - rect.height - rect.y;
var clampedOffsetY = clamp(offsetY, 0, 1);
var bottomExcess = clampedOffsetY - offsetY;
var maxClampedHeight = 1 - clampedOffsetY;
var clampedHeight = clamp(rect.height - bottomExcess, 0, maxClampedHeight);
var topExcess = rect.height - clampedHeight;
vec3.set(
scaleVector,
rect.width / clampedWidth,
rect.height / clampedHeight,
1);
vec3.set(
translateVector,
(rightExcess - leftExcess) / clampedWidth,
(topExcess - bottomExcess) / clampedHeight,
0);
mat4.identity(viewportMatrix);
mat4.translate(viewportMatrix, viewportMatrix, translateVector);
mat4.scale(viewportMatrix, viewportMatrix, scaleVector);
gl.viewport(gl.drawingBufferWidth * clampedOffsetX,
gl.drawingBufferHeight * clampedOffsetY,
gl.drawingBufferWidth * clampedWidth,
gl.drawingBufferHeight * clampedHeight);
} | [
"function",
"setViewport",
"(",
"gl",
",",
"layer",
",",
"rect",
",",
"viewportMatrix",
")",
"{",
"if",
"(",
"rect",
".",
"x",
"===",
"0",
"&&",
"rect",
".",
"width",
"===",
"1",
"&&",
"rect",
".",
"y",
"===",
"0",
"&&",
"rect",
".",
"height",
"===",
"1",
")",
"{",
"// Fast path for full rect.",
"gl",
".",
"viewport",
"(",
"0",
",",
"0",
",",
"gl",
".",
"drawingBufferWidth",
",",
"gl",
".",
"drawingBufferHeight",
")",
";",
"mat4",
".",
"identity",
"(",
"viewportMatrix",
")",
";",
"return",
";",
"}",
"var",
"offsetX",
"=",
"rect",
".",
"x",
";",
"var",
"clampedOffsetX",
"=",
"clamp",
"(",
"offsetX",
",",
"0",
",",
"1",
")",
";",
"var",
"leftExcess",
"=",
"clampedOffsetX",
"-",
"offsetX",
";",
"var",
"maxClampedWidth",
"=",
"1",
"-",
"clampedOffsetX",
";",
"var",
"clampedWidth",
"=",
"clamp",
"(",
"rect",
".",
"width",
"-",
"leftExcess",
",",
"0",
",",
"maxClampedWidth",
")",
";",
"var",
"rightExcess",
"=",
"rect",
".",
"width",
"-",
"clampedWidth",
";",
"var",
"offsetY",
"=",
"1",
"-",
"rect",
".",
"height",
"-",
"rect",
".",
"y",
";",
"var",
"clampedOffsetY",
"=",
"clamp",
"(",
"offsetY",
",",
"0",
",",
"1",
")",
";",
"var",
"bottomExcess",
"=",
"clampedOffsetY",
"-",
"offsetY",
";",
"var",
"maxClampedHeight",
"=",
"1",
"-",
"clampedOffsetY",
";",
"var",
"clampedHeight",
"=",
"clamp",
"(",
"rect",
".",
"height",
"-",
"bottomExcess",
",",
"0",
",",
"maxClampedHeight",
")",
";",
"var",
"topExcess",
"=",
"rect",
".",
"height",
"-",
"clampedHeight",
";",
"vec3",
".",
"set",
"(",
"scaleVector",
",",
"rect",
".",
"width",
"/",
"clampedWidth",
",",
"rect",
".",
"height",
"/",
"clampedHeight",
",",
"1",
")",
";",
"vec3",
".",
"set",
"(",
"translateVector",
",",
"(",
"rightExcess",
"-",
"leftExcess",
")",
"/",
"clampedWidth",
",",
"(",
"topExcess",
"-",
"bottomExcess",
")",
"/",
"clampedHeight",
",",
"0",
")",
";",
"mat4",
".",
"identity",
"(",
"viewportMatrix",
")",
";",
"mat4",
".",
"translate",
"(",
"viewportMatrix",
",",
"viewportMatrix",
",",
"translateVector",
")",
";",
"mat4",
".",
"scale",
"(",
"viewportMatrix",
",",
"viewportMatrix",
",",
"scaleVector",
")",
";",
"gl",
".",
"viewport",
"(",
"gl",
".",
"drawingBufferWidth",
"*",
"clampedOffsetX",
",",
"gl",
".",
"drawingBufferHeight",
"*",
"clampedOffsetY",
",",
"gl",
".",
"drawingBufferWidth",
"*",
"clampedWidth",
",",
"gl",
".",
"drawingBufferHeight",
"*",
"clampedHeight",
")",
";",
"}"
] | Sets the WebGL viewport and returns a viewport clamping compensation matrix. Negative viewport origin coordinates cause rendering issues. Letting the viewport dimensions extend beyond the visible area do not seem to cause rendering issues, but they may still have an impact on performance. Therefore, when the scene's rect is not fully contained in the rendering area, we clamp the viewport to the rendering area, and return a compensation matrix to scale and translate vertices accordingly. | [
"Sets",
"the",
"WebGL",
"viewport",
"and",
"returns",
"a",
"viewport",
"clamping",
"compensation",
"matrix",
".",
"Negative",
"viewport",
"origin",
"coordinates",
"cause",
"rendering",
"issues",
".",
"Letting",
"the",
"viewport",
"dimensions",
"extend",
"beyond",
"the",
"visible",
"area",
"do",
"not",
"seem",
"to",
"cause",
"rendering",
"issues",
"but",
"they",
"may",
"still",
"have",
"an",
"impact",
"on",
"performance",
".",
"Therefore",
"when",
"the",
"scene",
"s",
"rect",
"is",
"not",
"fully",
"contained",
"in",
"the",
"rendering",
"area",
"we",
"clamp",
"the",
"viewport",
"to",
"the",
"rendering",
"area",
"and",
"return",
"a",
"compensation",
"matrix",
"to",
"scale",
"and",
"translate",
"vertices",
"accordingly",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/renderers/WebGlCommon.js#L177-L219 |
6,777 | google/marzipano | src/util/chain.js | exec | function exec() {
// Extract error from arguments.
var err = arguments[0];
// Abort chain on error.
if (err) {
fn = cfn = null;
done.apply(null, arguments);
return;
}
// Terminate if there are no functions left in the chain.
if (!fnList.length) {
fn = cfn = null;
done.apply(null, arguments);
return;
}
// Advance to the next function in the chain.
fn = fnList.shift();
var _fn = fn;
// Extract arguments to pass into the next function.
var ret = Array.prototype.slice.call(arguments, 1);
// Call next function with previous return value and call back exec.
ret.push(exec);
var _cfn = fn.apply(null, ret); // fn(null, ret..., exec)
// Detect when fn has completed synchronously and do not clobber the
// internal state in that case. You're not expected to understand this.
if (_fn !== fn) {
return;
}
// Remember the cancel method for the currently executing function.
// Detect chaining on non-cancellable function.
if (typeof _cfn !== 'function') {
throw new Error('chain: chaining on non-cancellable function');
} else {
cfn = _cfn;
}
} | javascript | function exec() {
// Extract error from arguments.
var err = arguments[0];
// Abort chain on error.
if (err) {
fn = cfn = null;
done.apply(null, arguments);
return;
}
// Terminate if there are no functions left in the chain.
if (!fnList.length) {
fn = cfn = null;
done.apply(null, arguments);
return;
}
// Advance to the next function in the chain.
fn = fnList.shift();
var _fn = fn;
// Extract arguments to pass into the next function.
var ret = Array.prototype.slice.call(arguments, 1);
// Call next function with previous return value and call back exec.
ret.push(exec);
var _cfn = fn.apply(null, ret); // fn(null, ret..., exec)
// Detect when fn has completed synchronously and do not clobber the
// internal state in that case. You're not expected to understand this.
if (_fn !== fn) {
return;
}
// Remember the cancel method for the currently executing function.
// Detect chaining on non-cancellable function.
if (typeof _cfn !== 'function') {
throw new Error('chain: chaining on non-cancellable function');
} else {
cfn = _cfn;
}
} | [
"function",
"exec",
"(",
")",
"{",
"// Extract error from arguments.",
"var",
"err",
"=",
"arguments",
"[",
"0",
"]",
";",
"// Abort chain on error.",
"if",
"(",
"err",
")",
"{",
"fn",
"=",
"cfn",
"=",
"null",
";",
"done",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
";",
"return",
";",
"}",
"// Terminate if there are no functions left in the chain.",
"if",
"(",
"!",
"fnList",
".",
"length",
")",
"{",
"fn",
"=",
"cfn",
"=",
"null",
";",
"done",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
";",
"return",
";",
"}",
"// Advance to the next function in the chain.",
"fn",
"=",
"fnList",
".",
"shift",
"(",
")",
";",
"var",
"_fn",
"=",
"fn",
";",
"// Extract arguments to pass into the next function.",
"var",
"ret",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
";",
"// Call next function with previous return value and call back exec.",
"ret",
".",
"push",
"(",
"exec",
")",
";",
"var",
"_cfn",
"=",
"fn",
".",
"apply",
"(",
"null",
",",
"ret",
")",
";",
"// fn(null, ret..., exec)",
"// Detect when fn has completed synchronously and do not clobber the",
"// internal state in that case. You're not expected to understand this.",
"if",
"(",
"_fn",
"!==",
"fn",
")",
"{",
"return",
";",
"}",
"// Remember the cancel method for the currently executing function.",
"// Detect chaining on non-cancellable function.",
"if",
"(",
"typeof",
"_cfn",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'chain: chaining on non-cancellable function'",
")",
";",
"}",
"else",
"{",
"cfn",
"=",
"_cfn",
";",
"}",
"}"
] | Execute the next function in the chain. Receives the error and return values from the previous function. | [
"Execute",
"the",
"next",
"function",
"in",
"the",
"chain",
".",
"Receives",
"the",
"error",
"and",
"return",
"values",
"from",
"the",
"previous",
"function",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/util/chain.js#L51-L95 |
6,778 | google/marzipano | src/util/inherits.js | inherits | function inherits(ctor, superCtor) {
ctor.super_ = superCtor;
var TempCtor = function() {};
TempCtor.prototype = superCtor.prototype;
ctor.prototype = new TempCtor();
ctor.prototype.constructor = ctor;
} | javascript | function inherits(ctor, superCtor) {
ctor.super_ = superCtor;
var TempCtor = function() {};
TempCtor.prototype = superCtor.prototype;
ctor.prototype = new TempCtor();
ctor.prototype.constructor = ctor;
} | [
"function",
"inherits",
"(",
"ctor",
",",
"superCtor",
")",
"{",
"ctor",
".",
"super_",
"=",
"superCtor",
";",
"var",
"TempCtor",
"=",
"function",
"(",
")",
"{",
"}",
";",
"TempCtor",
".",
"prototype",
"=",
"superCtor",
".",
"prototype",
";",
"ctor",
".",
"prototype",
"=",
"new",
"TempCtor",
"(",
")",
";",
"ctor",
".",
"prototype",
".",
"constructor",
"=",
"ctor",
";",
"}"
] | Make ctor a subclass of superCtor. Do not depend on ES5 Object.create semantics because of older browsers. | [
"Make",
"ctor",
"a",
"subclass",
"of",
"superCtor",
".",
"Do",
"not",
"depend",
"on",
"ES5",
"Object",
".",
"create",
"semantics",
"because",
"of",
"older",
"browsers",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/util/inherits.js#L20-L26 |
6,779 | google/marzipano | demos/layer-effects/index.js | fileToCanvas | function fileToCanvas(file, done) {
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
var img = document.createElement('img');
img.onload = function() {
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
ctx.drawImage(img, 0, 0);
done(null, canvas);
};
img.onerror = function(err) {
done(err);
};
img.src = URL.createObjectURL(file);
} | javascript | function fileToCanvas(file, done) {
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
var img = document.createElement('img');
img.onload = function() {
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
ctx.drawImage(img, 0, 0);
done(null, canvas);
};
img.onerror = function(err) {
done(err);
};
img.src = URL.createObjectURL(file);
} | [
"function",
"fileToCanvas",
"(",
"file",
",",
"done",
")",
"{",
"var",
"canvas",
"=",
"document",
".",
"createElement",
"(",
"'canvas'",
")",
";",
"var",
"ctx",
"=",
"canvas",
".",
"getContext",
"(",
"'2d'",
")",
";",
"var",
"img",
"=",
"document",
".",
"createElement",
"(",
"'img'",
")",
";",
"img",
".",
"onload",
"=",
"function",
"(",
")",
"{",
"canvas",
".",
"width",
"=",
"img",
".",
"naturalWidth",
";",
"canvas",
".",
"height",
"=",
"img",
".",
"naturalHeight",
";",
"ctx",
".",
"drawImage",
"(",
"img",
",",
"0",
",",
"0",
")",
";",
"done",
"(",
"null",
",",
"canvas",
")",
";",
"}",
";",
"img",
".",
"onerror",
"=",
"function",
"(",
"err",
")",
"{",
"done",
"(",
"err",
")",
";",
"}",
";",
"img",
".",
"src",
"=",
"URL",
".",
"createObjectURL",
"(",
"file",
")",
";",
"}"
] | Convert an image file into a canvas. | [
"Convert",
"an",
"image",
"file",
"into",
"a",
"canvas",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/demos/layer-effects/index.js#L53-L67 |
6,780 | google/marzipano | demos/layer-effects/index.js | importLayer | function importLayer(file) {
fileToCanvas(file, function(err, canvas) {
if (err) {
alert('Unable to load image file.');
return;
}
if (canvas.width > maxSize || canvas.height > maxSize) {
alert('Image is too large. The maximum supported size is ' +
maxSize + ' by ' + maxSize + ' pixels.');
return;
}
// Create layer.
var asset = new Marzipano.DynamicAsset(canvas);
var source = new Marzipano.SingleAssetSource(asset);
var geometry = new Marzipano.EquirectGeometry([{ width: canvas.width }]);
var layer = scene.createLayer({
source: source,
geometry: geometry
});
// Create a new effects object for the layer.
var effects = layerEffects(layer);
// Add layer into the view model.
layers.unshift({
name: file.name,
layer: layer,
effects: effects,
canvas: canvas
});
});
} | javascript | function importLayer(file) {
fileToCanvas(file, function(err, canvas) {
if (err) {
alert('Unable to load image file.');
return;
}
if (canvas.width > maxSize || canvas.height > maxSize) {
alert('Image is too large. The maximum supported size is ' +
maxSize + ' by ' + maxSize + ' pixels.');
return;
}
// Create layer.
var asset = new Marzipano.DynamicAsset(canvas);
var source = new Marzipano.SingleAssetSource(asset);
var geometry = new Marzipano.EquirectGeometry([{ width: canvas.width }]);
var layer = scene.createLayer({
source: source,
geometry: geometry
});
// Create a new effects object for the layer.
var effects = layerEffects(layer);
// Add layer into the view model.
layers.unshift({
name: file.name,
layer: layer,
effects: effects,
canvas: canvas
});
});
} | [
"function",
"importLayer",
"(",
"file",
")",
"{",
"fileToCanvas",
"(",
"file",
",",
"function",
"(",
"err",
",",
"canvas",
")",
"{",
"if",
"(",
"err",
")",
"{",
"alert",
"(",
"'Unable to load image file.'",
")",
";",
"return",
";",
"}",
"if",
"(",
"canvas",
".",
"width",
">",
"maxSize",
"||",
"canvas",
".",
"height",
">",
"maxSize",
")",
"{",
"alert",
"(",
"'Image is too large. The maximum supported size is '",
"+",
"maxSize",
"+",
"' by '",
"+",
"maxSize",
"+",
"' pixels.'",
")",
";",
"return",
";",
"}",
"// Create layer.",
"var",
"asset",
"=",
"new",
"Marzipano",
".",
"DynamicAsset",
"(",
"canvas",
")",
";",
"var",
"source",
"=",
"new",
"Marzipano",
".",
"SingleAssetSource",
"(",
"asset",
")",
";",
"var",
"geometry",
"=",
"new",
"Marzipano",
".",
"EquirectGeometry",
"(",
"[",
"{",
"width",
":",
"canvas",
".",
"width",
"}",
"]",
")",
";",
"var",
"layer",
"=",
"scene",
".",
"createLayer",
"(",
"{",
"source",
":",
"source",
",",
"geometry",
":",
"geometry",
"}",
")",
";",
"// Create a new effects object for the layer.",
"var",
"effects",
"=",
"layerEffects",
"(",
"layer",
")",
";",
"// Add layer into the view model.",
"layers",
".",
"unshift",
"(",
"{",
"name",
":",
"file",
".",
"name",
",",
"layer",
":",
"layer",
",",
"effects",
":",
"effects",
",",
"canvas",
":",
"canvas",
"}",
")",
";",
"}",
")",
";",
"}"
] | Import a canvas into a layer. | [
"Import",
"a",
"canvas",
"into",
"a",
"layer",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/demos/layer-effects/index.js#L70-L102 |
6,781 | google/marzipano | demos/layer-effects/index.js | discardLayer | function discardLayer(item) {
if (confirm('Remove this layer?')) {
scene.destroyLayer(item.layer);
layers.remove(item);
}
} | javascript | function discardLayer(item) {
if (confirm('Remove this layer?')) {
scene.destroyLayer(item.layer);
layers.remove(item);
}
} | [
"function",
"discardLayer",
"(",
"item",
")",
"{",
"if",
"(",
"confirm",
"(",
"'Remove this layer?'",
")",
")",
"{",
"scene",
".",
"destroyLayer",
"(",
"item",
".",
"layer",
")",
";",
"layers",
".",
"remove",
"(",
"item",
")",
";",
"}",
"}"
] | Discard an existing layer. | [
"Discard",
"an",
"existing",
"layer",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/demos/layer-effects/index.js#L105-L110 |
6,782 | google/marzipano | demos/touch-gestures/index.js | disableControlsTemporarily | function disableControlsTemporarily() {
viewer.controls().disableMethod('touchView');
viewer.controls().disableMethod('pinch');
setTimeout(function() {
viewer.controls().enableMethod('touchView');
viewer.controls().enableMethod('pinch');
}, 200);
} | javascript | function disableControlsTemporarily() {
viewer.controls().disableMethod('touchView');
viewer.controls().disableMethod('pinch');
setTimeout(function() {
viewer.controls().enableMethod('touchView');
viewer.controls().enableMethod('pinch');
}, 200);
} | [
"function",
"disableControlsTemporarily",
"(",
")",
"{",
"viewer",
".",
"controls",
"(",
")",
".",
"disableMethod",
"(",
"'touchView'",
")",
";",
"viewer",
".",
"controls",
"(",
")",
".",
"disableMethod",
"(",
"'pinch'",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"viewer",
".",
"controls",
"(",
")",
".",
"enableMethod",
"(",
"'touchView'",
")",
";",
"viewer",
".",
"controls",
"(",
")",
".",
"enableMethod",
"(",
"'pinch'",
")",
";",
"}",
",",
"200",
")",
";",
"}"
] | Prevent pan and zoom events from being handled after swipe ends. | [
"Prevent",
"pan",
"and",
"zoom",
"events",
"from",
"being",
"handled",
"after",
"swipe",
"ends",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/demos/touch-gestures/index.js#L136-L143 |
6,783 | google/marzipano | demos/touch-gestures/index.js | zoomOnTap | function zoomOnTap(e) {
var coords = viewer.view().screenToCoordinates(e.center);
coords.fov = viewer.view().fov() * 0.8;
viewer.lookTo(coords, { transitionDuration: 300 });
} | javascript | function zoomOnTap(e) {
var coords = viewer.view().screenToCoordinates(e.center);
coords.fov = viewer.view().fov() * 0.8;
viewer.lookTo(coords, { transitionDuration: 300 });
} | [
"function",
"zoomOnTap",
"(",
"e",
")",
"{",
"var",
"coords",
"=",
"viewer",
".",
"view",
"(",
")",
".",
"screenToCoordinates",
"(",
"e",
".",
"center",
")",
";",
"coords",
".",
"fov",
"=",
"viewer",
".",
"view",
"(",
")",
".",
"fov",
"(",
")",
"*",
"0.8",
";",
"viewer",
".",
"lookTo",
"(",
"coords",
",",
"{",
"transitionDuration",
":",
"300",
"}",
")",
";",
"}"
] | Zoom on tap. | [
"Zoom",
"on",
"tap",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/demos/touch-gestures/index.js#L156-L160 |
6,784 | google/marzipano | src/views/Flat.js | function(min, max) {
return function limitX(params) {
params.x = clamp(params.x, min, max);
return params;
};
} | javascript | function(min, max) {
return function limitX(params) {
params.x = clamp(params.x, min, max);
return params;
};
} | [
"function",
"(",
"min",
",",
"max",
")",
"{",
"return",
"function",
"limitX",
"(",
"params",
")",
"{",
"params",
".",
"x",
"=",
"clamp",
"(",
"params",
".",
"x",
",",
"min",
",",
"max",
")",
";",
"return",
"params",
";",
"}",
";",
"}"
] | Returns a view limiter that constrains the x parameter.
@param {number} min The minimum x value.
@param {number} max The maximum y value.
@return {FlatViewLimiter} | [
"Returns",
"a",
"view",
"limiter",
"that",
"constrains",
"the",
"x",
"parameter",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/views/Flat.js#L702-L707 |
|
6,785 | google/marzipano | src/views/Flat.js | function(min, max) {
return function limitY(params) {
params.y = clamp(params.y, min, max);
return params;
};
} | javascript | function(min, max) {
return function limitY(params) {
params.y = clamp(params.y, min, max);
return params;
};
} | [
"function",
"(",
"min",
",",
"max",
")",
"{",
"return",
"function",
"limitY",
"(",
"params",
")",
"{",
"params",
".",
"y",
"=",
"clamp",
"(",
"params",
".",
"y",
",",
"min",
",",
"max",
")",
";",
"return",
"params",
";",
"}",
";",
"}"
] | Return a view limiter that constrains the y parameter.
@param {number} min The minimum y value.
@param {number} max The maximum y value.
@return {FlatViewLimiter} | [
"Return",
"a",
"view",
"limiter",
"that",
"constrains",
"the",
"y",
"parameter",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/views/Flat.js#L715-L720 |
|
6,786 | google/marzipano | src/views/Flat.js | function(min, max) {
return function limitZoom(params) {
params.zoom = clamp(params.zoom, min, max);
return params;
};
} | javascript | function(min, max) {
return function limitZoom(params) {
params.zoom = clamp(params.zoom, min, max);
return params;
};
} | [
"function",
"(",
"min",
",",
"max",
")",
"{",
"return",
"function",
"limitZoom",
"(",
"params",
")",
"{",
"params",
".",
"zoom",
"=",
"clamp",
"(",
"params",
".",
"zoom",
",",
"min",
",",
"max",
")",
";",
"return",
"params",
";",
"}",
";",
"}"
] | Returns a view limiter than constrains the zoom parameter.
@param {number} min The minimum zoom value.
@param {number} max The maximum zoom value.
@return {FlatViewLimiter} | [
"Returns",
"a",
"view",
"limiter",
"than",
"constrains",
"the",
"zoom",
"parameter",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/views/Flat.js#L728-L733 |
|
6,787 | google/marzipano | src/views/Flat.js | function(min, max) {
return function limitVisibleX(params) {
// Calculate the zoom value that makes the specified range fully visible.
var maxZoom = max - min;
// Clamp zoom to the maximum value.
if (params.zoom > maxZoom) {
params.zoom = maxZoom;
}
// Bound X such that the image is visible up to the range edges.
var minX = min + 0.5 * params.zoom;
var maxX = max - 0.5 * params.zoom;
params.x = clamp(params.x, minX, maxX);
return params;
};
} | javascript | function(min, max) {
return function limitVisibleX(params) {
// Calculate the zoom value that makes the specified range fully visible.
var maxZoom = max - min;
// Clamp zoom to the maximum value.
if (params.zoom > maxZoom) {
params.zoom = maxZoom;
}
// Bound X such that the image is visible up to the range edges.
var minX = min + 0.5 * params.zoom;
var maxX = max - 0.5 * params.zoom;
params.x = clamp(params.x, minX, maxX);
return params;
};
} | [
"function",
"(",
"min",
",",
"max",
")",
"{",
"return",
"function",
"limitVisibleX",
"(",
"params",
")",
"{",
"// Calculate the zoom value that makes the specified range fully visible.",
"var",
"maxZoom",
"=",
"max",
"-",
"min",
";",
"// Clamp zoom to the maximum value.",
"if",
"(",
"params",
".",
"zoom",
">",
"maxZoom",
")",
"{",
"params",
".",
"zoom",
"=",
"maxZoom",
";",
"}",
"// Bound X such that the image is visible up to the range edges.",
"var",
"minX",
"=",
"min",
"+",
"0.5",
"*",
"params",
".",
"zoom",
";",
"var",
"maxX",
"=",
"max",
"-",
"0.5",
"*",
"params",
".",
"zoom",
";",
"params",
".",
"x",
"=",
"clamp",
"(",
"params",
".",
"x",
",",
"minX",
",",
"maxX",
")",
";",
"return",
"params",
";",
"}",
";",
"}"
] | Returns a view limiter that constrains the values of the x parameter that
are inside the viewport.
@param {number} min The minimum x value.
@param {number} max The maximum x value.
@return {FlatViewLimiter} | [
"Returns",
"a",
"view",
"limiter",
"that",
"constrains",
"the",
"values",
"of",
"the",
"x",
"parameter",
"that",
"are",
"inside",
"the",
"viewport",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/views/Flat.js#L760-L777 |
|
6,788 | google/marzipano | src/views/Flat.js | function(min, max) {
return function limitVisibleY(params) {
// Do nothing for a null viewport.
if (params.width <= 0 || params.height <= 0) {
return params;
}
// Calculate the X to Y conversion factor.
var viewportAspectRatio = params.width / params.height;
var factor = viewportAspectRatio / params.mediaAspectRatio;
// Calculate the zoom value that makes the specified range fully visible.
var maxZoom = (max - min) * factor;
// Clamp zoom to the maximum value.
if (params.zoom > maxZoom) {
params.zoom = maxZoom;
}
// Bound Y such that the image is visible up to the range edges.
var minY = min + 0.5 * params.zoom / factor;
var maxY = max - 0.5 * params.zoom / factor;
params.y = clamp(params.y, minY, maxY);
return params;
};
} | javascript | function(min, max) {
return function limitVisibleY(params) {
// Do nothing for a null viewport.
if (params.width <= 0 || params.height <= 0) {
return params;
}
// Calculate the X to Y conversion factor.
var viewportAspectRatio = params.width / params.height;
var factor = viewportAspectRatio / params.mediaAspectRatio;
// Calculate the zoom value that makes the specified range fully visible.
var maxZoom = (max - min) * factor;
// Clamp zoom to the maximum value.
if (params.zoom > maxZoom) {
params.zoom = maxZoom;
}
// Bound Y such that the image is visible up to the range edges.
var minY = min + 0.5 * params.zoom / factor;
var maxY = max - 0.5 * params.zoom / factor;
params.y = clamp(params.y, minY, maxY);
return params;
};
} | [
"function",
"(",
"min",
",",
"max",
")",
"{",
"return",
"function",
"limitVisibleY",
"(",
"params",
")",
"{",
"// Do nothing for a null viewport.",
"if",
"(",
"params",
".",
"width",
"<=",
"0",
"||",
"params",
".",
"height",
"<=",
"0",
")",
"{",
"return",
"params",
";",
"}",
"// Calculate the X to Y conversion factor.",
"var",
"viewportAspectRatio",
"=",
"params",
".",
"width",
"/",
"params",
".",
"height",
";",
"var",
"factor",
"=",
"viewportAspectRatio",
"/",
"params",
".",
"mediaAspectRatio",
";",
"// Calculate the zoom value that makes the specified range fully visible.",
"var",
"maxZoom",
"=",
"(",
"max",
"-",
"min",
")",
"*",
"factor",
";",
"// Clamp zoom to the maximum value.",
"if",
"(",
"params",
".",
"zoom",
">",
"maxZoom",
")",
"{",
"params",
".",
"zoom",
"=",
"maxZoom",
";",
"}",
"// Bound Y such that the image is visible up to the range edges.",
"var",
"minY",
"=",
"min",
"+",
"0.5",
"*",
"params",
".",
"zoom",
"/",
"factor",
";",
"var",
"maxY",
"=",
"max",
"-",
"0.5",
"*",
"params",
".",
"zoom",
"/",
"factor",
";",
"params",
".",
"y",
"=",
"clamp",
"(",
"params",
".",
"y",
",",
"minY",
",",
"maxY",
")",
";",
"return",
"params",
";",
"}",
";",
"}"
] | Returns a view limiter that constrains the values of the y parameter that
are inside the viewport.
@param {number} min The minimum y value.
@param {number} max The maximum y value.
@return {FlatViewLimiter} | [
"Returns",
"a",
"view",
"limiter",
"that",
"constrains",
"the",
"values",
"of",
"the",
"y",
"parameter",
"that",
"are",
"inside",
"the",
"viewport",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/views/Flat.js#L786-L813 |
|
6,789 | google/marzipano | src/views/Flat.js | function() {
return function limitLetterbox(params) {
if(params.width <= 0 || params.height <= 0) {
return params;
}
var viewportAspectRatio = params.width / params.height;
var fullWidthZoom = 1.0;
var fullHeightZoom = viewportAspectRatio / params.mediaAspectRatio;
// If the image is wider than the viewport, limit the horizontal zoom to
// the image width.
if (params.mediaAspectRatio >= viewportAspectRatio) {
params.zoom = Math.min(params.zoom, fullWidthZoom);
}
// If the image is narrower than the viewport, limit the vertical zoom to
// the image height.
if (params.mediaAspectRatio <= viewportAspectRatio) {
params.zoom = Math.min(params.zoom, fullHeightZoom);
}
// If the full image width is visible, limit x to the central point.
// Else, bound x such that image is visible up to the horizontal edges.
var minX, maxX;
if (params.zoom > fullWidthZoom) {
minX = maxX = 0.5;
} else {
minX = 0.0 + 0.5 * params.zoom / fullWidthZoom;
maxX = 1.0 - 0.5 * params.zoom / fullWidthZoom;
}
// If the full image height is visible, limit y to the central point.
// Else, bound y such that image is visible up to the vertical edges.
var minY, maxY;
if (params.zoom > fullHeightZoom) {
minY = maxY = 0.5;
} else {
minY = 0.0 + 0.5 * params.zoom / fullHeightZoom;
maxY = 1.0 - 0.5 * params.zoom / fullHeightZoom;
}
// Clamp x and y into the calculated bounds.
params.x = clamp(params.x, minX, maxX);
params.y = clamp(params.y, minY, maxY);
return params;
};
} | javascript | function() {
return function limitLetterbox(params) {
if(params.width <= 0 || params.height <= 0) {
return params;
}
var viewportAspectRatio = params.width / params.height;
var fullWidthZoom = 1.0;
var fullHeightZoom = viewportAspectRatio / params.mediaAspectRatio;
// If the image is wider than the viewport, limit the horizontal zoom to
// the image width.
if (params.mediaAspectRatio >= viewportAspectRatio) {
params.zoom = Math.min(params.zoom, fullWidthZoom);
}
// If the image is narrower than the viewport, limit the vertical zoom to
// the image height.
if (params.mediaAspectRatio <= viewportAspectRatio) {
params.zoom = Math.min(params.zoom, fullHeightZoom);
}
// If the full image width is visible, limit x to the central point.
// Else, bound x such that image is visible up to the horizontal edges.
var minX, maxX;
if (params.zoom > fullWidthZoom) {
minX = maxX = 0.5;
} else {
minX = 0.0 + 0.5 * params.zoom / fullWidthZoom;
maxX = 1.0 - 0.5 * params.zoom / fullWidthZoom;
}
// If the full image height is visible, limit y to the central point.
// Else, bound y such that image is visible up to the vertical edges.
var minY, maxY;
if (params.zoom > fullHeightZoom) {
minY = maxY = 0.5;
} else {
minY = 0.0 + 0.5 * params.zoom / fullHeightZoom;
maxY = 1.0 - 0.5 * params.zoom / fullHeightZoom;
}
// Clamp x and y into the calculated bounds.
params.x = clamp(params.x, minX, maxX);
params.y = clamp(params.y, minY, maxY);
return params;
};
} | [
"function",
"(",
")",
"{",
"return",
"function",
"limitLetterbox",
"(",
"params",
")",
"{",
"if",
"(",
"params",
".",
"width",
"<=",
"0",
"||",
"params",
".",
"height",
"<=",
"0",
")",
"{",
"return",
"params",
";",
"}",
"var",
"viewportAspectRatio",
"=",
"params",
".",
"width",
"/",
"params",
".",
"height",
";",
"var",
"fullWidthZoom",
"=",
"1.0",
";",
"var",
"fullHeightZoom",
"=",
"viewportAspectRatio",
"/",
"params",
".",
"mediaAspectRatio",
";",
"// If the image is wider than the viewport, limit the horizontal zoom to",
"// the image width.",
"if",
"(",
"params",
".",
"mediaAspectRatio",
">=",
"viewportAspectRatio",
")",
"{",
"params",
".",
"zoom",
"=",
"Math",
".",
"min",
"(",
"params",
".",
"zoom",
",",
"fullWidthZoom",
")",
";",
"}",
"// If the image is narrower than the viewport, limit the vertical zoom to",
"// the image height.",
"if",
"(",
"params",
".",
"mediaAspectRatio",
"<=",
"viewportAspectRatio",
")",
"{",
"params",
".",
"zoom",
"=",
"Math",
".",
"min",
"(",
"params",
".",
"zoom",
",",
"fullHeightZoom",
")",
";",
"}",
"// If the full image width is visible, limit x to the central point.",
"// Else, bound x such that image is visible up to the horizontal edges.",
"var",
"minX",
",",
"maxX",
";",
"if",
"(",
"params",
".",
"zoom",
">",
"fullWidthZoom",
")",
"{",
"minX",
"=",
"maxX",
"=",
"0.5",
";",
"}",
"else",
"{",
"minX",
"=",
"0.0",
"+",
"0.5",
"*",
"params",
".",
"zoom",
"/",
"fullWidthZoom",
";",
"maxX",
"=",
"1.0",
"-",
"0.5",
"*",
"params",
".",
"zoom",
"/",
"fullWidthZoom",
";",
"}",
"// If the full image height is visible, limit y to the central point.",
"// Else, bound y such that image is visible up to the vertical edges.",
"var",
"minY",
",",
"maxY",
";",
"if",
"(",
"params",
".",
"zoom",
">",
"fullHeightZoom",
")",
"{",
"minY",
"=",
"maxY",
"=",
"0.5",
";",
"}",
"else",
"{",
"minY",
"=",
"0.0",
"+",
"0.5",
"*",
"params",
".",
"zoom",
"/",
"fullHeightZoom",
";",
"maxY",
"=",
"1.0",
"-",
"0.5",
"*",
"params",
".",
"zoom",
"/",
"fullHeightZoom",
";",
"}",
"// Clamp x and y into the calculated bounds.",
"params",
".",
"x",
"=",
"clamp",
"(",
"params",
".",
"x",
",",
"minX",
",",
"maxX",
")",
";",
"params",
".",
"y",
"=",
"clamp",
"(",
"params",
".",
"y",
",",
"minY",
",",
"maxY",
")",
";",
"return",
"params",
";",
"}",
";",
"}"
] | Returns a view limiter that constrains the zoom parameter such that
zooming out is prevented beyond the point at which the image is fully
visible. Unless the image and the viewport have the same aspect ratio,
this will cause bands to appear around the image.
@return {FlatViewLimiter} | [
"Returns",
"a",
"view",
"limiter",
"that",
"constrains",
"the",
"zoom",
"parameter",
"such",
"that",
"zooming",
"out",
"is",
"prevented",
"beyond",
"the",
"point",
"at",
"which",
"the",
"image",
"is",
"fully",
"visible",
".",
"Unless",
"the",
"image",
"and",
"the",
"viewport",
"have",
"the",
"same",
"aspect",
"ratio",
"this",
"will",
"cause",
"bands",
"to",
"appear",
"around",
"the",
"image",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/views/Flat.js#L823-L871 |
|
6,790 | google/marzipano | src/util/async.js | async | function async(fn) {
return function asynced(done) {
var err, ret;
try {
ret = fn();
} catch (e) {
err = e;
} finally {
if (err) {
done(err);
} else {
done(null, ret);
}
}
};
} | javascript | function async(fn) {
return function asynced(done) {
var err, ret;
try {
ret = fn();
} catch (e) {
err = e;
} finally {
if (err) {
done(err);
} else {
done(null, ret);
}
}
};
} | [
"function",
"async",
"(",
"fn",
")",
"{",
"return",
"function",
"asynced",
"(",
"done",
")",
"{",
"var",
"err",
",",
"ret",
";",
"try",
"{",
"ret",
"=",
"fn",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"err",
"=",
"e",
";",
"}",
"finally",
"{",
"if",
"(",
"err",
")",
"{",
"done",
"(",
"err",
")",
";",
"}",
"else",
"{",
"done",
"(",
"null",
",",
"ret",
")",
";",
"}",
"}",
"}",
";",
"}"
] | Transform a synchronous function into an asynchronous one. | [
"Transform",
"a",
"synchronous",
"function",
"into",
"an",
"asynchronous",
"one",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/util/async.js#L19-L34 |
6,791 | google/marzipano | demos/video/VideoAsset.js | VideoAsset | function VideoAsset(videoElement) {
this._videoElement = null;
this._destroyed = false;
this._emitChange = this.emit.bind(this, 'change');
this._lastTimestamp = -1;
this._emptyCanvas = document.createElement('canvas');
this._emptyCanvas.width = 1;
this._emptyCanvas.height = 1;
this.setVideo(videoElement);
} | javascript | function VideoAsset(videoElement) {
this._videoElement = null;
this._destroyed = false;
this._emitChange = this.emit.bind(this, 'change');
this._lastTimestamp = -1;
this._emptyCanvas = document.createElement('canvas');
this._emptyCanvas.width = 1;
this._emptyCanvas.height = 1;
this.setVideo(videoElement);
} | [
"function",
"VideoAsset",
"(",
"videoElement",
")",
"{",
"this",
".",
"_videoElement",
"=",
"null",
";",
"this",
".",
"_destroyed",
"=",
"false",
";",
"this",
".",
"_emitChange",
"=",
"this",
".",
"emit",
".",
"bind",
"(",
"this",
",",
"'change'",
")",
";",
"this",
".",
"_lastTimestamp",
"=",
"-",
"1",
";",
"this",
".",
"_emptyCanvas",
"=",
"document",
".",
"createElement",
"(",
"'canvas'",
")",
";",
"this",
".",
"_emptyCanvas",
".",
"width",
"=",
"1",
";",
"this",
".",
"_emptyCanvas",
".",
"height",
"=",
"1",
";",
"this",
".",
"setVideo",
"(",
"videoElement",
")",
";",
"}"
] | Dynamic asset containing a video element. Note that this won't work on IE 11 because of lack of support for video textures. Refer to the video-multi-res demo for a possible workaround. | [
"Dynamic",
"asset",
"containing",
"a",
"video",
"element",
".",
"Note",
"that",
"this",
"won",
"t",
"work",
"on",
"IE",
"11",
"because",
"of",
"lack",
"of",
"support",
"for",
"video",
"textures",
".",
"Refer",
"to",
"the",
"video",
"-",
"multi",
"-",
"res",
"demo",
"for",
"a",
"possible",
"workaround",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/demos/video/VideoAsset.js#L21-L32 |
6,792 | google/marzipano | src/views/Rectilinear.js | function(min, max) {
return function limitYaw(params) {
params.yaw = clamp(params.yaw, min, max);
return params;
};
} | javascript | function(min, max) {
return function limitYaw(params) {
params.yaw = clamp(params.yaw, min, max);
return params;
};
} | [
"function",
"(",
"min",
",",
"max",
")",
"{",
"return",
"function",
"limitYaw",
"(",
"params",
")",
"{",
"params",
".",
"yaw",
"=",
"clamp",
"(",
"params",
".",
"yaw",
",",
"min",
",",
"max",
")",
";",
"return",
"params",
";",
"}",
";",
"}"
] | Returns a view limiter that constrains the yaw angle.
@param {number} min The minimum yaw value.
@param {number} max The maximum yaw value.
@return {RectilinearViewLimiter} | [
"Returns",
"a",
"view",
"limiter",
"that",
"constrains",
"the",
"yaw",
"angle",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/views/Rectilinear.js#L883-L888 |
|
6,793 | google/marzipano | src/views/Rectilinear.js | function(min, max) {
return function limitPitch(params) {
params.pitch = clamp(params.pitch, min, max);
return params;
};
} | javascript | function(min, max) {
return function limitPitch(params) {
params.pitch = clamp(params.pitch, min, max);
return params;
};
} | [
"function",
"(",
"min",
",",
"max",
")",
"{",
"return",
"function",
"limitPitch",
"(",
"params",
")",
"{",
"params",
".",
"pitch",
"=",
"clamp",
"(",
"params",
".",
"pitch",
",",
"min",
",",
"max",
")",
";",
"return",
"params",
";",
"}",
";",
"}"
] | Returns a view limiter that constrains the pitch angle.
@param {number} min The minimum pitch value.
@param {number} max The maximum pitch value.
@return {RectilinearViewLimiter} | [
"Returns",
"a",
"view",
"limiter",
"that",
"constrains",
"the",
"pitch",
"angle",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/views/Rectilinear.js#L896-L901 |
|
6,794 | google/marzipano | src/views/Rectilinear.js | function(min, max) {
return function limitRoll(params) {
params.roll = clamp(params.roll, min, max);
return params;
};
} | javascript | function(min, max) {
return function limitRoll(params) {
params.roll = clamp(params.roll, min, max);
return params;
};
} | [
"function",
"(",
"min",
",",
"max",
")",
"{",
"return",
"function",
"limitRoll",
"(",
"params",
")",
"{",
"params",
".",
"roll",
"=",
"clamp",
"(",
"params",
".",
"roll",
",",
"min",
",",
"max",
")",
";",
"return",
"params",
";",
"}",
";",
"}"
] | Returns a view limiter that constrains the roll angle.
@param {number} min The minimum roll value.
@param {number} max The maximum roll value.
@return {RectilinearViewLimiter} | [
"Returns",
"a",
"view",
"limiter",
"that",
"constrains",
"the",
"roll",
"angle",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/views/Rectilinear.js#L909-L914 |
|
6,795 | google/marzipano | src/views/Rectilinear.js | function(min, max) {
return function limitHfov(params) {
var width = params.width;
var height = params.height;
if (width > 0 && height > 0) {
var vmin = convertFov.htov(min, width, height);
var vmax = convertFov.htov(max, width, height);
params.fov = clamp(params.fov, vmin, vmax);
}
return params;
};
} | javascript | function(min, max) {
return function limitHfov(params) {
var width = params.width;
var height = params.height;
if (width > 0 && height > 0) {
var vmin = convertFov.htov(min, width, height);
var vmax = convertFov.htov(max, width, height);
params.fov = clamp(params.fov, vmin, vmax);
}
return params;
};
} | [
"function",
"(",
"min",
",",
"max",
")",
"{",
"return",
"function",
"limitHfov",
"(",
"params",
")",
"{",
"var",
"width",
"=",
"params",
".",
"width",
";",
"var",
"height",
"=",
"params",
".",
"height",
";",
"if",
"(",
"width",
">",
"0",
"&&",
"height",
">",
"0",
")",
"{",
"var",
"vmin",
"=",
"convertFov",
".",
"htov",
"(",
"min",
",",
"width",
",",
"height",
")",
";",
"var",
"vmax",
"=",
"convertFov",
".",
"htov",
"(",
"max",
",",
"width",
",",
"height",
")",
";",
"params",
".",
"fov",
"=",
"clamp",
"(",
"params",
".",
"fov",
",",
"vmin",
",",
"vmax",
")",
";",
"}",
"return",
"params",
";",
"}",
";",
"}"
] | Returns a view limiter that constrains the horizontal field of view.
@param {number} min The minimum horizontal field of view.
@param {number} max The maximum horizontal field of view.
@return {RectilinearViewLimiter} | [
"Returns",
"a",
"view",
"limiter",
"that",
"constrains",
"the",
"horizontal",
"field",
"of",
"view",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/views/Rectilinear.js#L922-L933 |
|
6,796 | google/marzipano | src/views/Rectilinear.js | function(min, max) {
return function limitVfov(params) {
params.fov = clamp(params.fov, min, max);
return params;
};
} | javascript | function(min, max) {
return function limitVfov(params) {
params.fov = clamp(params.fov, min, max);
return params;
};
} | [
"function",
"(",
"min",
",",
"max",
")",
"{",
"return",
"function",
"limitVfov",
"(",
"params",
")",
"{",
"params",
".",
"fov",
"=",
"clamp",
"(",
"params",
".",
"fov",
",",
"min",
",",
"max",
")",
";",
"return",
"params",
";",
"}",
";",
"}"
] | Returns a view limiter that constrains the vertical field of view.
@param {number} min The minimum vertical field of view.
@param {number} max The maximum vertical field of view.
@return {RectilinearViewLimiter} | [
"Returns",
"a",
"view",
"limiter",
"that",
"constrains",
"the",
"vertical",
"field",
"of",
"view",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/views/Rectilinear.js#L941-L946 |
|
6,797 | google/marzipano | src/support/cssPointerEvents.js | checkCssPointerEventsSupported | function checkCssPointerEventsSupported() {
// Check for existence of CSS property.
var style = document.createElement('a').style;
style.cssText = 'pointer-events:auto';
var hasCssProperty = style.pointerEvents === 'auto';
// The above result is spurious on emulation mode for IE 8-10.
var isOldIE = browser.msie && parseFloat(browser.version) < 11;
return hasCssProperty && !isOldIE;
} | javascript | function checkCssPointerEventsSupported() {
// Check for existence of CSS property.
var style = document.createElement('a').style;
style.cssText = 'pointer-events:auto';
var hasCssProperty = style.pointerEvents === 'auto';
// The above result is spurious on emulation mode for IE 8-10.
var isOldIE = browser.msie && parseFloat(browser.version) < 11;
return hasCssProperty && !isOldIE;
} | [
"function",
"checkCssPointerEventsSupported",
"(",
")",
"{",
"// Check for existence of CSS property.",
"var",
"style",
"=",
"document",
".",
"createElement",
"(",
"'a'",
")",
".",
"style",
";",
"style",
".",
"cssText",
"=",
"'pointer-events:auto'",
";",
"var",
"hasCssProperty",
"=",
"style",
".",
"pointerEvents",
"===",
"'auto'",
";",
"// The above result is spurious on emulation mode for IE 8-10.",
"var",
"isOldIE",
"=",
"browser",
".",
"msie",
"&&",
"parseFloat",
"(",
"browser",
".",
"version",
")",
"<",
"11",
";",
"return",
"hasCssProperty",
"&&",
"!",
"isOldIE",
";",
"}"
] | Detect CSS pointer-events support. | [
"Detect",
"CSS",
"pointer",
"-",
"events",
"support",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/support/cssPointerEvents.js#L21-L32 |
6,798 | google/marzipano | demos/video-multi-res/loadVideoInSync.js | loadVideoInSync | function loadVideoInSync(url, syncElement, cb) {
cb = once(cb);
var element = document.createElement('video');
element.crossOrigin = 'anonymous';
element.autoplay = true;
element.loop = true;
// Prevent the video from going full screen on iOS.
element.playsInline = true;
element.webkitPlaysInline = true;
element.onerror = function(e) {
cb(e.target.error);
};
// The new video will be loaded at currentTime + 5s, to allow time for
// the video to be ready to play
var syncTime = 5000;
element.src = url;
// Checking readyState on an interval seems to be more reliable than using events
waitForReadyState(element, element.HAVE_CURRENT_DATA, 0.2, function() {
if(syncElement) {
if(syncElement.paused) {
// If the video is not playing, we can load the new one to the correct time
element.currentTime = syncElement.currentTime;
}
else {
//If it is playing, we will need to load to a time ahead of the current,
// to account for the time that the loading will take
element.currentTime = syncElement.currentTime + syncTime / 1000;
}
}
waitForReadyState(element, element.HAVE_ENOUGH_DATA, 0.2, function() {
if(!syncElement) {
// If there is no element to sync with we are done
cb(null, element);
}
else if(syncElement.paused) {
// If the element to sync with is paused, we are done
cb(null, element);
}
else {
if(element.currentTime <= syncElement.currentTime) {
// The loading took too long, start playing immediately
// We will be a bit out of sync
element.play();
cb(null, element);
}
else {
// If the loading was too fast, wait before playing
// We should be in sync
setTimeout(function() {
element.play();
cb(null, element);
}, (element.currentTime - syncElement.currentTime) * 1000);
}
}
});
});
} | javascript | function loadVideoInSync(url, syncElement, cb) {
cb = once(cb);
var element = document.createElement('video');
element.crossOrigin = 'anonymous';
element.autoplay = true;
element.loop = true;
// Prevent the video from going full screen on iOS.
element.playsInline = true;
element.webkitPlaysInline = true;
element.onerror = function(e) {
cb(e.target.error);
};
// The new video will be loaded at currentTime + 5s, to allow time for
// the video to be ready to play
var syncTime = 5000;
element.src = url;
// Checking readyState on an interval seems to be more reliable than using events
waitForReadyState(element, element.HAVE_CURRENT_DATA, 0.2, function() {
if(syncElement) {
if(syncElement.paused) {
// If the video is not playing, we can load the new one to the correct time
element.currentTime = syncElement.currentTime;
}
else {
//If it is playing, we will need to load to a time ahead of the current,
// to account for the time that the loading will take
element.currentTime = syncElement.currentTime + syncTime / 1000;
}
}
waitForReadyState(element, element.HAVE_ENOUGH_DATA, 0.2, function() {
if(!syncElement) {
// If there is no element to sync with we are done
cb(null, element);
}
else if(syncElement.paused) {
// If the element to sync with is paused, we are done
cb(null, element);
}
else {
if(element.currentTime <= syncElement.currentTime) {
// The loading took too long, start playing immediately
// We will be a bit out of sync
element.play();
cb(null, element);
}
else {
// If the loading was too fast, wait before playing
// We should be in sync
setTimeout(function() {
element.play();
cb(null, element);
}, (element.currentTime - syncElement.currentTime) * 1000);
}
}
});
});
} | [
"function",
"loadVideoInSync",
"(",
"url",
",",
"syncElement",
",",
"cb",
")",
"{",
"cb",
"=",
"once",
"(",
"cb",
")",
";",
"var",
"element",
"=",
"document",
".",
"createElement",
"(",
"'video'",
")",
";",
"element",
".",
"crossOrigin",
"=",
"'anonymous'",
";",
"element",
".",
"autoplay",
"=",
"true",
";",
"element",
".",
"loop",
"=",
"true",
";",
"// Prevent the video from going full screen on iOS.",
"element",
".",
"playsInline",
"=",
"true",
";",
"element",
".",
"webkitPlaysInline",
"=",
"true",
";",
"element",
".",
"onerror",
"=",
"function",
"(",
"e",
")",
"{",
"cb",
"(",
"e",
".",
"target",
".",
"error",
")",
";",
"}",
";",
"// The new video will be loaded at currentTime + 5s, to allow time for",
"// the video to be ready to play",
"var",
"syncTime",
"=",
"5000",
";",
"element",
".",
"src",
"=",
"url",
";",
"// Checking readyState on an interval seems to be more reliable than using events",
"waitForReadyState",
"(",
"element",
",",
"element",
".",
"HAVE_CURRENT_DATA",
",",
"0.2",
",",
"function",
"(",
")",
"{",
"if",
"(",
"syncElement",
")",
"{",
"if",
"(",
"syncElement",
".",
"paused",
")",
"{",
"// If the video is not playing, we can load the new one to the correct time",
"element",
".",
"currentTime",
"=",
"syncElement",
".",
"currentTime",
";",
"}",
"else",
"{",
"//If it is playing, we will need to load to a time ahead of the current,",
"// to account for the time that the loading will take",
"element",
".",
"currentTime",
"=",
"syncElement",
".",
"currentTime",
"+",
"syncTime",
"/",
"1000",
";",
"}",
"}",
"waitForReadyState",
"(",
"element",
",",
"element",
".",
"HAVE_ENOUGH_DATA",
",",
"0.2",
",",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"syncElement",
")",
"{",
"// If there is no element to sync with we are done",
"cb",
"(",
"null",
",",
"element",
")",
";",
"}",
"else",
"if",
"(",
"syncElement",
".",
"paused",
")",
"{",
"// If the element to sync with is paused, we are done",
"cb",
"(",
"null",
",",
"element",
")",
";",
"}",
"else",
"{",
"if",
"(",
"element",
".",
"currentTime",
"<=",
"syncElement",
".",
"currentTime",
")",
"{",
"// The loading took too long, start playing immediately",
"// We will be a bit out of sync",
"element",
".",
"play",
"(",
")",
";",
"cb",
"(",
"null",
",",
"element",
")",
";",
"}",
"else",
"{",
"// If the loading was too fast, wait before playing",
"// We should be in sync",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"element",
".",
"play",
"(",
")",
";",
"cb",
"(",
"null",
",",
"element",
")",
";",
"}",
",",
"(",
"element",
".",
"currentTime",
"-",
"syncElement",
".",
"currentTime",
")",
"*",
"1000",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] | Attempts to load a video element in sync with another video element | [
"Attempts",
"to",
"load",
"a",
"video",
"element",
"in",
"sync",
"with",
"another",
"video",
"element"
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/demos/video-multi-res/loadVideoInSync.js#L19-L82 |
6,799 | google/marzipano | src/Layer.js | Layer | function Layer(source, geometry, view, textureStore, opts) {
opts = opts || {};
var self = this;
this._source = source;
this._geometry = geometry;
this._view = view;
this._textureStore = textureStore;
this._effects = opts.effects || {};
this._fixedLevelIndex = null;
this._viewChangeHandler = function() {
self.emit('viewChange', self.view());
};
this._view.addEventListener('change', this._viewChangeHandler);
this._textureStoreChangeHandler = function() {
self.emit('textureStoreChange', self.textureStore());
};
this._textureStore.addEventListener('textureLoad',
this._textureStoreChangeHandler);
this._textureStore.addEventListener('textureError',
this._textureStoreChangeHandler);
this._textureStore.addEventListener('textureInvalid',
this._textureStoreChangeHandler);
} | javascript | function Layer(source, geometry, view, textureStore, opts) {
opts = opts || {};
var self = this;
this._source = source;
this._geometry = geometry;
this._view = view;
this._textureStore = textureStore;
this._effects = opts.effects || {};
this._fixedLevelIndex = null;
this._viewChangeHandler = function() {
self.emit('viewChange', self.view());
};
this._view.addEventListener('change', this._viewChangeHandler);
this._textureStoreChangeHandler = function() {
self.emit('textureStoreChange', self.textureStore());
};
this._textureStore.addEventListener('textureLoad',
this._textureStoreChangeHandler);
this._textureStore.addEventListener('textureError',
this._textureStoreChangeHandler);
this._textureStore.addEventListener('textureInvalid',
this._textureStoreChangeHandler);
} | [
"function",
"Layer",
"(",
"source",
",",
"geometry",
",",
"view",
",",
"textureStore",
",",
"opts",
")",
"{",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"var",
"self",
"=",
"this",
";",
"this",
".",
"_source",
"=",
"source",
";",
"this",
".",
"_geometry",
"=",
"geometry",
";",
"this",
".",
"_view",
"=",
"view",
";",
"this",
".",
"_textureStore",
"=",
"textureStore",
";",
"this",
".",
"_effects",
"=",
"opts",
".",
"effects",
"||",
"{",
"}",
";",
"this",
".",
"_fixedLevelIndex",
"=",
"null",
";",
"this",
".",
"_viewChangeHandler",
"=",
"function",
"(",
")",
"{",
"self",
".",
"emit",
"(",
"'viewChange'",
",",
"self",
".",
"view",
"(",
")",
")",
";",
"}",
";",
"this",
".",
"_view",
".",
"addEventListener",
"(",
"'change'",
",",
"this",
".",
"_viewChangeHandler",
")",
";",
"this",
".",
"_textureStoreChangeHandler",
"=",
"function",
"(",
")",
"{",
"self",
".",
"emit",
"(",
"'textureStoreChange'",
",",
"self",
".",
"textureStore",
"(",
")",
")",
";",
"}",
";",
"this",
".",
"_textureStore",
".",
"addEventListener",
"(",
"'textureLoad'",
",",
"this",
".",
"_textureStoreChangeHandler",
")",
";",
"this",
".",
"_textureStore",
".",
"addEventListener",
"(",
"'textureError'",
",",
"this",
".",
"_textureStoreChangeHandler",
")",
";",
"this",
".",
"_textureStore",
".",
"addEventListener",
"(",
"'textureInvalid'",
",",
"this",
".",
"_textureStoreChangeHandler",
")",
";",
"}"
] | Signals that the layer has been rendered.
@param {boolean} stable Whether all tiles were successfully rendered without
missing textures or resorting to fallbacks.
@event Layer#renderComplete
@class Layer
@classdesc
A Layer is a combination of {@link Source}, {@link Geometry}, {@link View}
and {@link TextureStore} that may be added into a {@link Stage} and rendered
with {@link Effects}.
@param {Source} source
@param {Geometry} geometry
@param {View} view
@param {TextureStore} textureStore
@param {Object} opts
@param {Effects} opts.effects | [
"Signals",
"that",
"the",
"layer",
"has",
"been",
"rendered",
"."
] | e3e21b2c1992708992dfeab5970b0f5a3f8f98e0 | https://github.com/google/marzipano/blob/e3e21b2c1992708992dfeab5970b0f5a3f8f98e0/src/Layer.js#L46-L76 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.