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
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
|---|---|---|---|---|---|---|---|---|---|---|---|
11,400
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function (url, callback, options) {
return fabric.util.loadImage(url, function(img) {
this.backgroundImage = img;
if (options && ('backgroundImageOpacity' in options)) {
this.backgroundImageOpacity = options.backgroundImageOpacity;
}
if (options && ('backgroundImageStretch' in options)) {
this.backgroundImageStretch = options.backgroundImageStretch;
}
callback && callback();
}, this);
}
|
javascript
|
function (url, callback, options) {
return fabric.util.loadImage(url, function(img) {
this.backgroundImage = img;
if (options && ('backgroundImageOpacity' in options)) {
this.backgroundImageOpacity = options.backgroundImageOpacity;
}
if (options && ('backgroundImageStretch' in options)) {
this.backgroundImageStretch = options.backgroundImageStretch;
}
callback && callback();
}, this);
}
|
[
"function",
"(",
"url",
",",
"callback",
",",
"options",
")",
"{",
"return",
"fabric",
".",
"util",
".",
"loadImage",
"(",
"url",
",",
"function",
"(",
"img",
")",
"{",
"this",
".",
"backgroundImage",
"=",
"img",
";",
"if",
"(",
"options",
"&&",
"(",
"'backgroundImageOpacity'",
"in",
"options",
")",
")",
"{",
"this",
".",
"backgroundImageOpacity",
"=",
"options",
".",
"backgroundImageOpacity",
";",
"}",
"if",
"(",
"options",
"&&",
"(",
"'backgroundImageStretch'",
"in",
"options",
")",
")",
"{",
"this",
".",
"backgroundImageStretch",
"=",
"options",
".",
"backgroundImageStretch",
";",
"}",
"callback",
"&&",
"callback",
"(",
")",
";",
"}",
",",
"this",
")",
";",
"}"
] |
Sets background image for this canvas
@method setBackgroundImage
@param {String} url url of an image to set background to
@param {Function} callback callback to invoke when image is loaded and set as background
@param {Object} options optional options to set for the background image
@return {fabric.Canvas} thisArg
@chainable
|
[
"Sets",
"background",
"image",
"for",
"this",
"canvas"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L5031-L5042
|
|
11,401
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function (canvasEl) {
this.lowerCanvasEl = fabric.util.getById(canvasEl) || this._createCanvasElement();
this._initCanvasElement(this.lowerCanvasEl);
fabric.util.addClass(this.lowerCanvasEl, 'lower-canvas');
if (this.interactive) {
this._applyCanvasStyle(this.lowerCanvasEl);
}
this.contextContainer = this.lowerCanvasEl.getContext('2d');
}
|
javascript
|
function (canvasEl) {
this.lowerCanvasEl = fabric.util.getById(canvasEl) || this._createCanvasElement();
this._initCanvasElement(this.lowerCanvasEl);
fabric.util.addClass(this.lowerCanvasEl, 'lower-canvas');
if (this.interactive) {
this._applyCanvasStyle(this.lowerCanvasEl);
}
this.contextContainer = this.lowerCanvasEl.getContext('2d');
}
|
[
"function",
"(",
"canvasEl",
")",
"{",
"this",
".",
"lowerCanvasEl",
"=",
"fabric",
".",
"util",
".",
"getById",
"(",
"canvasEl",
")",
"||",
"this",
".",
"_createCanvasElement",
"(",
")",
";",
"this",
".",
"_initCanvasElement",
"(",
"this",
".",
"lowerCanvasEl",
")",
";",
"fabric",
".",
"util",
".",
"addClass",
"(",
"this",
".",
"lowerCanvasEl",
",",
"'lower-canvas'",
")",
";",
"if",
"(",
"this",
".",
"interactive",
")",
"{",
"this",
".",
"_applyCanvasStyle",
"(",
"this",
".",
"lowerCanvasEl",
")",
";",
"}",
"this",
".",
"contextContainer",
"=",
"this",
".",
"lowerCanvasEl",
".",
"getContext",
"(",
"'2d'",
")",
";",
"}"
] |
Creates a secondary canvas
@method _createLowerCanvas
|
[
"Creates",
"a",
"secondary",
"canvas"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L5095-L5106
|
|
11,402
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function (ctx, object) {
if (!object) return;
if (this.controlsAboveOverlay) {
var hasBorders = object.hasBorders, hasCorners = object.hasCorners;
object.hasBorders = object.hasCorners = false;
object.render(ctx);
object.hasBorders = hasBorders;
object.hasCorners = hasCorners;
}
else {
object.render(ctx);
}
}
|
javascript
|
function (ctx, object) {
if (!object) return;
if (this.controlsAboveOverlay) {
var hasBorders = object.hasBorders, hasCorners = object.hasCorners;
object.hasBorders = object.hasCorners = false;
object.render(ctx);
object.hasBorders = hasBorders;
object.hasCorners = hasCorners;
}
else {
object.render(ctx);
}
}
|
[
"function",
"(",
"ctx",
",",
"object",
")",
"{",
"if",
"(",
"!",
"object",
")",
"return",
";",
"if",
"(",
"this",
".",
"controlsAboveOverlay",
")",
"{",
"var",
"hasBorders",
"=",
"object",
".",
"hasBorders",
",",
"hasCorners",
"=",
"object",
".",
"hasCorners",
";",
"object",
".",
"hasBorders",
"=",
"object",
".",
"hasCorners",
"=",
"false",
";",
"object",
".",
"render",
"(",
"ctx",
")",
";",
"object",
".",
"hasBorders",
"=",
"hasBorders",
";",
"object",
".",
"hasCorners",
"=",
"hasCorners",
";",
"}",
"else",
"{",
"object",
".",
"render",
"(",
"ctx",
")",
";",
"}",
"}"
] |
Given a context, renders an object on that context
@param ctx {Object} context to render object on
@param object {Object} object to render
@private
|
[
"Given",
"a",
"context",
"renders",
"an",
"object",
"on",
"that",
"context"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L5217-L5230
|
|
11,403
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function (allOnTop) {
var canvasToDrawOn = this[(allOnTop === true && this.interactive) ? 'contextTop' : 'contextContainer'];
if (this.contextTop) {
this.clearContext(this.contextTop);
}
if (allOnTop === false || (typeof allOnTop === 'undefined')) {
this.clearContext(canvasToDrawOn);
}
var length = this._objects.length,
activeGroup = this.getActiveGroup(),
startTime = new Date();
if (this.clipTo) {
canvasToDrawOn.save();
canvasToDrawOn.beginPath();
this.clipTo(canvasToDrawOn);
canvasToDrawOn.clip();
}
canvasToDrawOn.fillStyle = this.backgroundColor;
canvasToDrawOn.fillRect(0, 0, this.width, this.height);
if (typeof this.backgroundImage == 'object') {
canvasToDrawOn.save();
canvasToDrawOn.globalAlpha = this.backgroundImageOpacity;
if (this.backgroundImageStretch) {
canvasToDrawOn.drawImage(this.backgroundImage, 0, 0, this.width, this.height);
}
else {
canvasToDrawOn.drawImage(this.backgroundImage, 0, 0);
}
canvasToDrawOn.restore();
}
if (length) {
for (var i = 0; i < length; ++i) {
if (!activeGroup ||
(activeGroup && this._objects[i] && !activeGroup.contains(this._objects[i]))) {
this._draw(canvasToDrawOn, this._objects[i]);
}
}
}
if (this.clipTo) {
canvasToDrawOn.restore();
}
// delegate rendering to group selection (if one exists)
if (activeGroup) {
this._draw(this.contextTop, activeGroup);
}
if (this.overlayImage) {
this.contextContainer.drawImage(this.overlayImage, 0, 0);
}
if (this.controlsAboveOverlay) {
this.drawControls(this.contextContainer);
}
if (this.onFpsUpdate) {
var elapsedTime = new Date() - startTime;
this.onFpsUpdate(~~(1000 / elapsedTime));
}
this.fire('after:render');
return this;
}
|
javascript
|
function (allOnTop) {
var canvasToDrawOn = this[(allOnTop === true && this.interactive) ? 'contextTop' : 'contextContainer'];
if (this.contextTop) {
this.clearContext(this.contextTop);
}
if (allOnTop === false || (typeof allOnTop === 'undefined')) {
this.clearContext(canvasToDrawOn);
}
var length = this._objects.length,
activeGroup = this.getActiveGroup(),
startTime = new Date();
if (this.clipTo) {
canvasToDrawOn.save();
canvasToDrawOn.beginPath();
this.clipTo(canvasToDrawOn);
canvasToDrawOn.clip();
}
canvasToDrawOn.fillStyle = this.backgroundColor;
canvasToDrawOn.fillRect(0, 0, this.width, this.height);
if (typeof this.backgroundImage == 'object') {
canvasToDrawOn.save();
canvasToDrawOn.globalAlpha = this.backgroundImageOpacity;
if (this.backgroundImageStretch) {
canvasToDrawOn.drawImage(this.backgroundImage, 0, 0, this.width, this.height);
}
else {
canvasToDrawOn.drawImage(this.backgroundImage, 0, 0);
}
canvasToDrawOn.restore();
}
if (length) {
for (var i = 0; i < length; ++i) {
if (!activeGroup ||
(activeGroup && this._objects[i] && !activeGroup.contains(this._objects[i]))) {
this._draw(canvasToDrawOn, this._objects[i]);
}
}
}
if (this.clipTo) {
canvasToDrawOn.restore();
}
// delegate rendering to group selection (if one exists)
if (activeGroup) {
this._draw(this.contextTop, activeGroup);
}
if (this.overlayImage) {
this.contextContainer.drawImage(this.overlayImage, 0, 0);
}
if (this.controlsAboveOverlay) {
this.drawControls(this.contextContainer);
}
if (this.onFpsUpdate) {
var elapsedTime = new Date() - startTime;
this.onFpsUpdate(~~(1000 / elapsedTime));
}
this.fire('after:render');
return this;
}
|
[
"function",
"(",
"allOnTop",
")",
"{",
"var",
"canvasToDrawOn",
"=",
"this",
"[",
"(",
"allOnTop",
"===",
"true",
"&&",
"this",
".",
"interactive",
")",
"?",
"'contextTop'",
":",
"'contextContainer'",
"]",
";",
"if",
"(",
"this",
".",
"contextTop",
")",
"{",
"this",
".",
"clearContext",
"(",
"this",
".",
"contextTop",
")",
";",
"}",
"if",
"(",
"allOnTop",
"===",
"false",
"||",
"(",
"typeof",
"allOnTop",
"===",
"'undefined'",
")",
")",
"{",
"this",
".",
"clearContext",
"(",
"canvasToDrawOn",
")",
";",
"}",
"var",
"length",
"=",
"this",
".",
"_objects",
".",
"length",
",",
"activeGroup",
"=",
"this",
".",
"getActiveGroup",
"(",
")",
",",
"startTime",
"=",
"new",
"Date",
"(",
")",
";",
"if",
"(",
"this",
".",
"clipTo",
")",
"{",
"canvasToDrawOn",
".",
"save",
"(",
")",
";",
"canvasToDrawOn",
".",
"beginPath",
"(",
")",
";",
"this",
".",
"clipTo",
"(",
"canvasToDrawOn",
")",
";",
"canvasToDrawOn",
".",
"clip",
"(",
")",
";",
"}",
"canvasToDrawOn",
".",
"fillStyle",
"=",
"this",
".",
"backgroundColor",
";",
"canvasToDrawOn",
".",
"fillRect",
"(",
"0",
",",
"0",
",",
"this",
".",
"width",
",",
"this",
".",
"height",
")",
";",
"if",
"(",
"typeof",
"this",
".",
"backgroundImage",
"==",
"'object'",
")",
"{",
"canvasToDrawOn",
".",
"save",
"(",
")",
";",
"canvasToDrawOn",
".",
"globalAlpha",
"=",
"this",
".",
"backgroundImageOpacity",
";",
"if",
"(",
"this",
".",
"backgroundImageStretch",
")",
"{",
"canvasToDrawOn",
".",
"drawImage",
"(",
"this",
".",
"backgroundImage",
",",
"0",
",",
"0",
",",
"this",
".",
"width",
",",
"this",
".",
"height",
")",
";",
"}",
"else",
"{",
"canvasToDrawOn",
".",
"drawImage",
"(",
"this",
".",
"backgroundImage",
",",
"0",
",",
"0",
")",
";",
"}",
"canvasToDrawOn",
".",
"restore",
"(",
")",
";",
"}",
"if",
"(",
"length",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"++",
"i",
")",
"{",
"if",
"(",
"!",
"activeGroup",
"||",
"(",
"activeGroup",
"&&",
"this",
".",
"_objects",
"[",
"i",
"]",
"&&",
"!",
"activeGroup",
".",
"contains",
"(",
"this",
".",
"_objects",
"[",
"i",
"]",
")",
")",
")",
"{",
"this",
".",
"_draw",
"(",
"canvasToDrawOn",
",",
"this",
".",
"_objects",
"[",
"i",
"]",
")",
";",
"}",
"}",
"}",
"if",
"(",
"this",
".",
"clipTo",
")",
"{",
"canvasToDrawOn",
".",
"restore",
"(",
")",
";",
"}",
"// delegate rendering to group selection (if one exists)",
"if",
"(",
"activeGroup",
")",
"{",
"this",
".",
"_draw",
"(",
"this",
".",
"contextTop",
",",
"activeGroup",
")",
";",
"}",
"if",
"(",
"this",
".",
"overlayImage",
")",
"{",
"this",
".",
"contextContainer",
".",
"drawImage",
"(",
"this",
".",
"overlayImage",
",",
"0",
",",
"0",
")",
";",
"}",
"if",
"(",
"this",
".",
"controlsAboveOverlay",
")",
"{",
"this",
".",
"drawControls",
"(",
"this",
".",
"contextContainer",
")",
";",
"}",
"if",
"(",
"this",
".",
"onFpsUpdate",
")",
"{",
"var",
"elapsedTime",
"=",
"new",
"Date",
"(",
")",
"-",
"startTime",
";",
"this",
".",
"onFpsUpdate",
"(",
"~",
"~",
"(",
"1000",
"/",
"elapsedTime",
")",
")",
";",
"}",
"this",
".",
"fire",
"(",
"'after:render'",
")",
";",
"return",
"this",
";",
"}"
] |
Renders both the top canvas and the secondary container canvas.
@method renderAll
@param allOnTop {Boolean} optional Whether we want to force all images to be rendered on the top canvas
@return {fabric.Canvas} instance
@chainable
|
[
"Renders",
"both",
"the",
"top",
"canvas",
"and",
"the",
"secondary",
"container",
"canvas",
"."
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L5334-L5407
|
|
11,404
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function () {
this.clearContext(this.contextTop || this.contextContainer);
if (this.overlayImage) {
this.contextContainer.drawImage(this.overlayImage, 0, 0);
}
// we render the top context - last object
if (this.selection && this._groupSelector) {
this._drawSelection();
}
// delegate rendering to group selection if one exists
// used for drawing selection borders/corners
var activeGroup = this.getActiveGroup();
if (activeGroup) {
activeGroup.render(this.contextTop);
}
this.fire('after:render');
return this;
}
|
javascript
|
function () {
this.clearContext(this.contextTop || this.contextContainer);
if (this.overlayImage) {
this.contextContainer.drawImage(this.overlayImage, 0, 0);
}
// we render the top context - last object
if (this.selection && this._groupSelector) {
this._drawSelection();
}
// delegate rendering to group selection if one exists
// used for drawing selection borders/corners
var activeGroup = this.getActiveGroup();
if (activeGroup) {
activeGroup.render(this.contextTop);
}
this.fire('after:render');
return this;
}
|
[
"function",
"(",
")",
"{",
"this",
".",
"clearContext",
"(",
"this",
".",
"contextTop",
"||",
"this",
".",
"contextContainer",
")",
";",
"if",
"(",
"this",
".",
"overlayImage",
")",
"{",
"this",
".",
"contextContainer",
".",
"drawImage",
"(",
"this",
".",
"overlayImage",
",",
"0",
",",
"0",
")",
";",
"}",
"// we render the top context - last object",
"if",
"(",
"this",
".",
"selection",
"&&",
"this",
".",
"_groupSelector",
")",
"{",
"this",
".",
"_drawSelection",
"(",
")",
";",
"}",
"// delegate rendering to group selection if one exists",
"// used for drawing selection borders/corners",
"var",
"activeGroup",
"=",
"this",
".",
"getActiveGroup",
"(",
")",
";",
"if",
"(",
"activeGroup",
")",
"{",
"activeGroup",
".",
"render",
"(",
"this",
".",
"contextTop",
")",
";",
"}",
"this",
".",
"fire",
"(",
"'after:render'",
")",
";",
"return",
"this",
";",
"}"
] |
Method to render only the top canvas.
Also used to render the group selection box.
@method renderTop
@return {fabric.Canvas} thisArg
@chainable
|
[
"Method",
"to",
"render",
"only",
"the",
"top",
"canvas",
".",
"Also",
"used",
"to",
"render",
"the",
"group",
"selection",
"box",
"."
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L5416-L5438
|
|
11,405
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function (format, quality) {
var canvasEl = this.upperCanvasEl || this.lowerCanvasEl;
this.renderAll(true);
var data = (fabric.StaticCanvas.supports('toDataURLWithQuality'))
? canvasEl.toDataURL('image/' + format, quality)
: canvasEl.toDataURL('image/' + format);
this.renderAll();
return data;
}
|
javascript
|
function (format, quality) {
var canvasEl = this.upperCanvasEl || this.lowerCanvasEl;
this.renderAll(true);
var data = (fabric.StaticCanvas.supports('toDataURLWithQuality'))
? canvasEl.toDataURL('image/' + format, quality)
: canvasEl.toDataURL('image/' + format);
this.renderAll();
return data;
}
|
[
"function",
"(",
"format",
",",
"quality",
")",
"{",
"var",
"canvasEl",
"=",
"this",
".",
"upperCanvasEl",
"||",
"this",
".",
"lowerCanvasEl",
";",
"this",
".",
"renderAll",
"(",
"true",
")",
";",
"var",
"data",
"=",
"(",
"fabric",
".",
"StaticCanvas",
".",
"supports",
"(",
"'toDataURLWithQuality'",
")",
")",
"?",
"canvasEl",
".",
"toDataURL",
"(",
"'image/'",
"+",
"format",
",",
"quality",
")",
":",
"canvasEl",
".",
"toDataURL",
"(",
"'image/'",
"+",
"format",
")",
";",
"this",
".",
"renderAll",
"(",
")",
";",
"return",
"data",
";",
"}"
] |
Exports canvas element to a dataurl image.
@method toDataURL
@param {String} format the format of the output image. Either "jpeg" or "png".
@param {Number} quality quality level (0..1)
@return {String}
|
[
"Exports",
"canvas",
"element",
"to",
"a",
"dataurl",
"image",
"."
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L5472-L5481
|
|
11,406
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function() {
var markup = [
'<?xml version="1.0" standalone="no" ?>',
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" ',
'"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">',
'<svg ',
'xmlns="http://www.w3.org/2000/svg" ',
'xmlns:xlink="http://www.w3.org/1999/xlink" ',
'version="1.1" ',
'width="', this.width, '" ',
'height="', this.height, '" ',
'xml:space="preserve">',
'<desc>Created with Fabric.js ', fabric.version, '</desc>',
fabric.createSVGFontFacesMarkup(this.getObjects())
];
if (this.backgroundImage) {
markup.push(
'<image x="0" y="0" ',
'width="', this.width,
'" height="', this.height,
'" preserveAspectRatio="', (this.backgroundImageStretch ? 'none' : 'defer'),
'" xlink:href="', this.backgroundImage.src,
'" style="opacity:', this.backgroundImageOpacity,
'"></image>'
);
}
for (var i = 0, objects = this.getObjects(), len = objects.length; i < len; i++) {
markup.push(objects[i].toSVG());
}
markup.push('</svg>');
return markup.join('');
}
|
javascript
|
function() {
var markup = [
'<?xml version="1.0" standalone="no" ?>',
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" ',
'"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">',
'<svg ',
'xmlns="http://www.w3.org/2000/svg" ',
'xmlns:xlink="http://www.w3.org/1999/xlink" ',
'version="1.1" ',
'width="', this.width, '" ',
'height="', this.height, '" ',
'xml:space="preserve">',
'<desc>Created with Fabric.js ', fabric.version, '</desc>',
fabric.createSVGFontFacesMarkup(this.getObjects())
];
if (this.backgroundImage) {
markup.push(
'<image x="0" y="0" ',
'width="', this.width,
'" height="', this.height,
'" preserveAspectRatio="', (this.backgroundImageStretch ? 'none' : 'defer'),
'" xlink:href="', this.backgroundImage.src,
'" style="opacity:', this.backgroundImageOpacity,
'"></image>'
);
}
for (var i = 0, objects = this.getObjects(), len = objects.length; i < len; i++) {
markup.push(objects[i].toSVG());
}
markup.push('</svg>');
return markup.join('');
}
|
[
"function",
"(",
")",
"{",
"var",
"markup",
"=",
"[",
"'<?xml version=\"1.0\" standalone=\"no\" ?>'",
",",
"'<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\" '",
",",
"'\"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">'",
",",
"'<svg '",
",",
"'xmlns=\"http://www.w3.org/2000/svg\" '",
",",
"'xmlns:xlink=\"http://www.w3.org/1999/xlink\" '",
",",
"'version=\"1.1\" '",
",",
"'width=\"'",
",",
"this",
".",
"width",
",",
"'\" '",
",",
"'height=\"'",
",",
"this",
".",
"height",
",",
"'\" '",
",",
"'xml:space=\"preserve\">'",
",",
"'<desc>Created with Fabric.js '",
",",
"fabric",
".",
"version",
",",
"'</desc>'",
",",
"fabric",
".",
"createSVGFontFacesMarkup",
"(",
"this",
".",
"getObjects",
"(",
")",
")",
"]",
";",
"if",
"(",
"this",
".",
"backgroundImage",
")",
"{",
"markup",
".",
"push",
"(",
"'<image x=\"0\" y=\"0\" '",
",",
"'width=\"'",
",",
"this",
".",
"width",
",",
"'\" height=\"'",
",",
"this",
".",
"height",
",",
"'\" preserveAspectRatio=\"'",
",",
"(",
"this",
".",
"backgroundImageStretch",
"?",
"'none'",
":",
"'defer'",
")",
",",
"'\" xlink:href=\"'",
",",
"this",
".",
"backgroundImage",
".",
"src",
",",
"'\" style=\"opacity:'",
",",
"this",
".",
"backgroundImageOpacity",
",",
"'\"></image>'",
")",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"objects",
"=",
"this",
".",
"getObjects",
"(",
")",
",",
"len",
"=",
"objects",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"markup",
".",
"push",
"(",
"objects",
"[",
"i",
"]",
".",
"toSVG",
"(",
")",
")",
";",
"}",
"markup",
".",
"push",
"(",
"'</svg>'",
")",
";",
"return",
"markup",
".",
"join",
"(",
"''",
")",
";",
"}"
] |
Returns SVG representation of canvas
@function
@method toSVG
@return {String}
|
[
"Returns",
"SVG",
"representation",
"of",
"canvas"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L5667-L5701
|
|
11,407
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function (object) {
removeFromArray(this._objects, object);
if (this.getActiveObject() === object) {
// removing active object should fire "selection:cleared" events
this.fire('before:selection:cleared', { target: object });
this.discardActiveObject();
this.fire('selection:cleared');
}
this.renderAll();
return object;
}
|
javascript
|
function (object) {
removeFromArray(this._objects, object);
if (this.getActiveObject() === object) {
// removing active object should fire "selection:cleared" events
this.fire('before:selection:cleared', { target: object });
this.discardActiveObject();
this.fire('selection:cleared');
}
this.renderAll();
return object;
}
|
[
"function",
"(",
"object",
")",
"{",
"removeFromArray",
"(",
"this",
".",
"_objects",
",",
"object",
")",
";",
"if",
"(",
"this",
".",
"getActiveObject",
"(",
")",
"===",
"object",
")",
"{",
"// removing active object should fire \"selection:cleared\" events",
"this",
".",
"fire",
"(",
"'before:selection:cleared'",
",",
"{",
"target",
":",
"object",
"}",
")",
";",
"this",
".",
"discardActiveObject",
"(",
")",
";",
"this",
".",
"fire",
"(",
"'selection:cleared'",
")",
";",
"}",
"this",
".",
"renderAll",
"(",
")",
";",
"return",
"object",
";",
"}"
] |
Removes an object from canvas and returns it
@method remove
@param object {Object} Object to remove
@return {Object} removed object
|
[
"Removes",
"an",
"object",
"from",
"canvas",
"and",
"returns",
"it"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L5718-L5729
|
|
11,408
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function (object) {
var idx = this._objects.indexOf(object),
nextIntersectingIdx = idx;
// if object is not on the bottom of stack
if (idx !== 0) {
// traverse down the stack looking for the nearest intersecting object
for (var i=idx-1; i>=0; --i) {
if (object.intersectsWithObject(this._objects[i]) || object.isContainedWithinObject(this._objects[i])) {
nextIntersectingIdx = i;
break;
}
}
removeFromArray(this._objects, object);
this._objects.splice(nextIntersectingIdx, 0, object);
}
return this.renderAll();
}
|
javascript
|
function (object) {
var idx = this._objects.indexOf(object),
nextIntersectingIdx = idx;
// if object is not on the bottom of stack
if (idx !== 0) {
// traverse down the stack looking for the nearest intersecting object
for (var i=idx-1; i>=0; --i) {
if (object.intersectsWithObject(this._objects[i]) || object.isContainedWithinObject(this._objects[i])) {
nextIntersectingIdx = i;
break;
}
}
removeFromArray(this._objects, object);
this._objects.splice(nextIntersectingIdx, 0, object);
}
return this.renderAll();
}
|
[
"function",
"(",
"object",
")",
"{",
"var",
"idx",
"=",
"this",
".",
"_objects",
".",
"indexOf",
"(",
"object",
")",
",",
"nextIntersectingIdx",
"=",
"idx",
";",
"// if object is not on the bottom of stack",
"if",
"(",
"idx",
"!==",
"0",
")",
"{",
"// traverse down the stack looking for the nearest intersecting object",
"for",
"(",
"var",
"i",
"=",
"idx",
"-",
"1",
";",
"i",
">=",
"0",
";",
"--",
"i",
")",
"{",
"if",
"(",
"object",
".",
"intersectsWithObject",
"(",
"this",
".",
"_objects",
"[",
"i",
"]",
")",
"||",
"object",
".",
"isContainedWithinObject",
"(",
"this",
".",
"_objects",
"[",
"i",
"]",
")",
")",
"{",
"nextIntersectingIdx",
"=",
"i",
";",
"break",
";",
"}",
"}",
"removeFromArray",
"(",
"this",
".",
"_objects",
",",
"object",
")",
";",
"this",
".",
"_objects",
".",
"splice",
"(",
"nextIntersectingIdx",
",",
"0",
",",
"object",
")",
";",
"}",
"return",
"this",
".",
"renderAll",
"(",
")",
";",
"}"
] |
Moves an object one level down in stack of drawn objects
@method sendBackwards
@param object {fabric.Object} Object to send
@return {fabric.Canvas} thisArg
@chainable
|
[
"Moves",
"an",
"object",
"one",
"level",
"down",
"in",
"stack",
"of",
"drawn",
"objects"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L5764-L5782
|
|
11,409
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function (object) {
var objects = this.getObjects(),
idx = objects.indexOf(object),
nextIntersectingIdx = idx;
// if object is not on top of stack (last item in an array)
if (idx !== objects.length-1) {
// traverse up the stack looking for the nearest intersecting object
for (var i = idx + 1, l = this._objects.length; i < l; ++i) {
if (object.intersectsWithObject(objects[i]) || object.isContainedWithinObject(this._objects[i])) {
nextIntersectingIdx = i;
break;
}
}
removeFromArray(objects, object);
objects.splice(nextIntersectingIdx, 0, object);
}
this.renderAll();
}
|
javascript
|
function (object) {
var objects = this.getObjects(),
idx = objects.indexOf(object),
nextIntersectingIdx = idx;
// if object is not on top of stack (last item in an array)
if (idx !== objects.length-1) {
// traverse up the stack looking for the nearest intersecting object
for (var i = idx + 1, l = this._objects.length; i < l; ++i) {
if (object.intersectsWithObject(objects[i]) || object.isContainedWithinObject(this._objects[i])) {
nextIntersectingIdx = i;
break;
}
}
removeFromArray(objects, object);
objects.splice(nextIntersectingIdx, 0, object);
}
this.renderAll();
}
|
[
"function",
"(",
"object",
")",
"{",
"var",
"objects",
"=",
"this",
".",
"getObjects",
"(",
")",
",",
"idx",
"=",
"objects",
".",
"indexOf",
"(",
"object",
")",
",",
"nextIntersectingIdx",
"=",
"idx",
";",
"// if object is not on top of stack (last item in an array)",
"if",
"(",
"idx",
"!==",
"objects",
".",
"length",
"-",
"1",
")",
"{",
"// traverse up the stack looking for the nearest intersecting object",
"for",
"(",
"var",
"i",
"=",
"idx",
"+",
"1",
",",
"l",
"=",
"this",
".",
"_objects",
".",
"length",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"if",
"(",
"object",
".",
"intersectsWithObject",
"(",
"objects",
"[",
"i",
"]",
")",
"||",
"object",
".",
"isContainedWithinObject",
"(",
"this",
".",
"_objects",
"[",
"i",
"]",
")",
")",
"{",
"nextIntersectingIdx",
"=",
"i",
";",
"break",
";",
"}",
"}",
"removeFromArray",
"(",
"objects",
",",
"object",
")",
";",
"objects",
".",
"splice",
"(",
"nextIntersectingIdx",
",",
"0",
",",
"object",
")",
";",
"}",
"this",
".",
"renderAll",
"(",
")",
";",
"}"
] |
Moves an object one level up in stack of drawn objects
@method bringForward
@param object {fabric.Object} Object to send
@return {fabric.Canvas} thisArg
@chainable
|
[
"Moves",
"an",
"object",
"one",
"level",
"up",
"in",
"stack",
"of",
"drawn",
"objects"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L5791-L5811
|
|
11,410
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function () {
return this.getObjects().reduce(function (memo, current) {
memo += current.complexity ? current.complexity() : 0;
return memo;
}, 0);
}
|
javascript
|
function () {
return this.getObjects().reduce(function (memo, current) {
memo += current.complexity ? current.complexity() : 0;
return memo;
}, 0);
}
|
[
"function",
"(",
")",
"{",
"return",
"this",
".",
"getObjects",
"(",
")",
".",
"reduce",
"(",
"function",
"(",
"memo",
",",
"current",
")",
"{",
"memo",
"+=",
"current",
".",
"complexity",
"?",
"current",
".",
"complexity",
"(",
")",
":",
"0",
";",
"return",
"memo",
";",
"}",
",",
"0",
")",
";",
"}"
] |
Returns number representation of an instance complexity
@method complexity
@return {Number} complexity
|
[
"Returns",
"number",
"representation",
"of",
"an",
"instance",
"complexity"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L5828-L5833
|
|
11,411
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(callback, context) {
var objects = this.getObjects(),
i = objects.length;
while (i--) {
callback.call(context, objects[i], i, objects);
}
return this;
}
|
javascript
|
function(callback, context) {
var objects = this.getObjects(),
i = objects.length;
while (i--) {
callback.call(context, objects[i], i, objects);
}
return this;
}
|
[
"function",
"(",
"callback",
",",
"context",
")",
"{",
"var",
"objects",
"=",
"this",
".",
"getObjects",
"(",
")",
",",
"i",
"=",
"objects",
".",
"length",
";",
"while",
"(",
"i",
"--",
")",
"{",
"callback",
".",
"call",
"(",
"context",
",",
"objects",
"[",
"i",
"]",
",",
"i",
",",
"objects",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Iterates over all objects, invoking callback for each one of them
@method forEachObject
@return {fabric.Canvas} thisArg
|
[
"Iterates",
"over",
"all",
"objects",
"invoking",
"callback",
"for",
"each",
"one",
"of",
"them"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L5840-L5847
|
|
11,412
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function () {
this.clear();
if (this.interactive) {
removeListener(this.upperCanvasEl, 'mousedown', this._onMouseDown);
removeListener(this.upperCanvasEl, 'mousemove', this._onMouseMove);
removeListener(fabric.window, 'resize', this._onResize);
}
return this;
}
|
javascript
|
function () {
this.clear();
if (this.interactive) {
removeListener(this.upperCanvasEl, 'mousedown', this._onMouseDown);
removeListener(this.upperCanvasEl, 'mousemove', this._onMouseMove);
removeListener(fabric.window, 'resize', this._onResize);
}
return this;
}
|
[
"function",
"(",
")",
"{",
"this",
".",
"clear",
"(",
")",
";",
"if",
"(",
"this",
".",
"interactive",
")",
"{",
"removeListener",
"(",
"this",
".",
"upperCanvasEl",
",",
"'mousedown'",
",",
"this",
".",
"_onMouseDown",
")",
";",
"removeListener",
"(",
"this",
".",
"upperCanvasEl",
",",
"'mousemove'",
",",
"this",
".",
"_onMouseMove",
")",
";",
"removeListener",
"(",
"fabric",
".",
"window",
",",
"'resize'",
",",
"this",
".",
"_onResize",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Clears a canvas element and removes all event handlers.
@method dispose
@return {fabric.Canvas} thisArg
@chainable
|
[
"Clears",
"a",
"canvas",
"element",
"and",
"removes",
"all",
"event",
"handlers",
"."
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L5855-L5863
|
|
11,413
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function () {
var _this = this;
this._onMouseDown = function (e) {
_this.__onMouseDown(e);
addListener(fabric.document, 'mouseup', _this._onMouseUp);
fabric.isTouchSupported && addListener(fabric.document, 'touchend', _this._onMouseUp);
addListener(fabric.document, 'mousemove', _this._onMouseMove);
fabric.isTouchSupported && addListener(fabric.document, 'touchmove', _this._onMouseMove);
removeListener(_this.upperCanvasEl, 'mousemove', _this._onMouseMove);
fabric.isTouchSupported && removeListener(_this.upperCanvasEl, 'touchmove', _this._onMouseMove);
};
this._onMouseUp = function (e) {
_this.__onMouseUp(e);
removeListener(fabric.document, 'mouseup', _this._onMouseUp);
fabric.isTouchSupported && removeListener(fabric.document, 'touchend', _this._onMouseUp);
removeListener(fabric.document, 'mousemove', _this._onMouseMove);
fabric.isTouchSupported && removeListener(fabric.document, 'touchmove', _this._onMouseMove);
addListener(_this.upperCanvasEl, 'mousemove', _this._onMouseMove);
fabric.isTouchSupported && addListener(_this.upperCanvasEl, 'touchmove', _this._onMouseMove);
};
this._onMouseMove = function (e) {
e.preventDefault && e.preventDefault();
_this.__onMouseMove(e);
};
this._onResize = function (e) {
_this.calcOffset();
};
addListener(fabric.window, 'resize', this._onResize);
if (fabric.isTouchSupported) {
addListener(this.upperCanvasEl, 'touchstart', this._onMouseDown);
addListener(this.upperCanvasEl, 'touchmove', this._onMouseMove);
}
else {
addListener(this.upperCanvasEl, 'mousedown', this._onMouseDown);
addListener(this.upperCanvasEl, 'mousemove', this._onMouseMove);
}
}
|
javascript
|
function () {
var _this = this;
this._onMouseDown = function (e) {
_this.__onMouseDown(e);
addListener(fabric.document, 'mouseup', _this._onMouseUp);
fabric.isTouchSupported && addListener(fabric.document, 'touchend', _this._onMouseUp);
addListener(fabric.document, 'mousemove', _this._onMouseMove);
fabric.isTouchSupported && addListener(fabric.document, 'touchmove', _this._onMouseMove);
removeListener(_this.upperCanvasEl, 'mousemove', _this._onMouseMove);
fabric.isTouchSupported && removeListener(_this.upperCanvasEl, 'touchmove', _this._onMouseMove);
};
this._onMouseUp = function (e) {
_this.__onMouseUp(e);
removeListener(fabric.document, 'mouseup', _this._onMouseUp);
fabric.isTouchSupported && removeListener(fabric.document, 'touchend', _this._onMouseUp);
removeListener(fabric.document, 'mousemove', _this._onMouseMove);
fabric.isTouchSupported && removeListener(fabric.document, 'touchmove', _this._onMouseMove);
addListener(_this.upperCanvasEl, 'mousemove', _this._onMouseMove);
fabric.isTouchSupported && addListener(_this.upperCanvasEl, 'touchmove', _this._onMouseMove);
};
this._onMouseMove = function (e) {
e.preventDefault && e.preventDefault();
_this.__onMouseMove(e);
};
this._onResize = function (e) {
_this.calcOffset();
};
addListener(fabric.window, 'resize', this._onResize);
if (fabric.isTouchSupported) {
addListener(this.upperCanvasEl, 'touchstart', this._onMouseDown);
addListener(this.upperCanvasEl, 'touchmove', this._onMouseMove);
}
else {
addListener(this.upperCanvasEl, 'mousedown', this._onMouseDown);
addListener(this.upperCanvasEl, 'mousemove', this._onMouseMove);
}
}
|
[
"function",
"(",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"this",
".",
"_onMouseDown",
"=",
"function",
"(",
"e",
")",
"{",
"_this",
".",
"__onMouseDown",
"(",
"e",
")",
";",
"addListener",
"(",
"fabric",
".",
"document",
",",
"'mouseup'",
",",
"_this",
".",
"_onMouseUp",
")",
";",
"fabric",
".",
"isTouchSupported",
"&&",
"addListener",
"(",
"fabric",
".",
"document",
",",
"'touchend'",
",",
"_this",
".",
"_onMouseUp",
")",
";",
"addListener",
"(",
"fabric",
".",
"document",
",",
"'mousemove'",
",",
"_this",
".",
"_onMouseMove",
")",
";",
"fabric",
".",
"isTouchSupported",
"&&",
"addListener",
"(",
"fabric",
".",
"document",
",",
"'touchmove'",
",",
"_this",
".",
"_onMouseMove",
")",
";",
"removeListener",
"(",
"_this",
".",
"upperCanvasEl",
",",
"'mousemove'",
",",
"_this",
".",
"_onMouseMove",
")",
";",
"fabric",
".",
"isTouchSupported",
"&&",
"removeListener",
"(",
"_this",
".",
"upperCanvasEl",
",",
"'touchmove'",
",",
"_this",
".",
"_onMouseMove",
")",
";",
"}",
";",
"this",
".",
"_onMouseUp",
"=",
"function",
"(",
"e",
")",
"{",
"_this",
".",
"__onMouseUp",
"(",
"e",
")",
";",
"removeListener",
"(",
"fabric",
".",
"document",
",",
"'mouseup'",
",",
"_this",
".",
"_onMouseUp",
")",
";",
"fabric",
".",
"isTouchSupported",
"&&",
"removeListener",
"(",
"fabric",
".",
"document",
",",
"'touchend'",
",",
"_this",
".",
"_onMouseUp",
")",
";",
"removeListener",
"(",
"fabric",
".",
"document",
",",
"'mousemove'",
",",
"_this",
".",
"_onMouseMove",
")",
";",
"fabric",
".",
"isTouchSupported",
"&&",
"removeListener",
"(",
"fabric",
".",
"document",
",",
"'touchmove'",
",",
"_this",
".",
"_onMouseMove",
")",
";",
"addListener",
"(",
"_this",
".",
"upperCanvasEl",
",",
"'mousemove'",
",",
"_this",
".",
"_onMouseMove",
")",
";",
"fabric",
".",
"isTouchSupported",
"&&",
"addListener",
"(",
"_this",
".",
"upperCanvasEl",
",",
"'touchmove'",
",",
"_this",
".",
"_onMouseMove",
")",
";",
"}",
";",
"this",
".",
"_onMouseMove",
"=",
"function",
"(",
"e",
")",
"{",
"e",
".",
"preventDefault",
"&&",
"e",
".",
"preventDefault",
"(",
")",
";",
"_this",
".",
"__onMouseMove",
"(",
"e",
")",
";",
"}",
";",
"this",
".",
"_onResize",
"=",
"function",
"(",
"e",
")",
"{",
"_this",
".",
"calcOffset",
"(",
")",
";",
"}",
";",
"addListener",
"(",
"fabric",
".",
"window",
",",
"'resize'",
",",
"this",
".",
"_onResize",
")",
";",
"if",
"(",
"fabric",
".",
"isTouchSupported",
")",
"{",
"addListener",
"(",
"this",
".",
"upperCanvasEl",
",",
"'touchstart'",
",",
"this",
".",
"_onMouseDown",
")",
";",
"addListener",
"(",
"this",
".",
"upperCanvasEl",
",",
"'touchmove'",
",",
"this",
".",
"_onMouseMove",
")",
";",
"}",
"else",
"{",
"addListener",
"(",
"this",
".",
"upperCanvasEl",
",",
"'mousedown'",
",",
"this",
".",
"_onMouseDown",
")",
";",
"addListener",
"(",
"this",
".",
"upperCanvasEl",
",",
"'mousemove'",
",",
"this",
".",
"_onMouseMove",
")",
";",
"}",
"}"
] |
Adds mouse listeners to canvas
@method _initEvents
@private
See configuration documentation for more details.
|
[
"Adds",
"mouse",
"listeners",
"to",
"canvas"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L6144-L6193
|
|
11,414
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function (e, target) {
var pointer = this.getPointer(e),
xy = this._normalizePointer(target, pointer),
x = xy.x,
y = xy.y;
// http://www.geog.ubc.ca/courses/klink/gis.notes/ncgia/u32.html
// http://idav.ucdavis.edu/~okreylos/TAship/Spring2000/PointInPolygon.html
// we iterate through each object. If target found, return it.
var iLines = target._getImageLines(target.oCoords),
xpoints = target._findCrossPoints(x, y, iLines);
// if xcount is odd then we clicked inside the object
// For the specific case of square images xcount === 1 in all true cases
if ((xpoints && xpoints % 2 === 1) || target._findTargetCorner(e, this._offset)) {
return true;
}
return false;
}
|
javascript
|
function (e, target) {
var pointer = this.getPointer(e),
xy = this._normalizePointer(target, pointer),
x = xy.x,
y = xy.y;
// http://www.geog.ubc.ca/courses/klink/gis.notes/ncgia/u32.html
// http://idav.ucdavis.edu/~okreylos/TAship/Spring2000/PointInPolygon.html
// we iterate through each object. If target found, return it.
var iLines = target._getImageLines(target.oCoords),
xpoints = target._findCrossPoints(x, y, iLines);
// if xcount is odd then we clicked inside the object
// For the specific case of square images xcount === 1 in all true cases
if ((xpoints && xpoints % 2 === 1) || target._findTargetCorner(e, this._offset)) {
return true;
}
return false;
}
|
[
"function",
"(",
"e",
",",
"target",
")",
"{",
"var",
"pointer",
"=",
"this",
".",
"getPointer",
"(",
"e",
")",
",",
"xy",
"=",
"this",
".",
"_normalizePointer",
"(",
"target",
",",
"pointer",
")",
",",
"x",
"=",
"xy",
".",
"x",
",",
"y",
"=",
"xy",
".",
"y",
";",
"// http://www.geog.ubc.ca/courses/klink/gis.notes/ncgia/u32.html",
"// http://idav.ucdavis.edu/~okreylos/TAship/Spring2000/PointInPolygon.html",
"// we iterate through each object. If target found, return it.",
"var",
"iLines",
"=",
"target",
".",
"_getImageLines",
"(",
"target",
".",
"oCoords",
")",
",",
"xpoints",
"=",
"target",
".",
"_findCrossPoints",
"(",
"x",
",",
"y",
",",
"iLines",
")",
";",
"// if xcount is odd then we clicked inside the object",
"// For the specific case of square images xcount === 1 in all true cases",
"if",
"(",
"(",
"xpoints",
"&&",
"xpoints",
"%",
"2",
"===",
"1",
")",
"||",
"target",
".",
"_findTargetCorner",
"(",
"e",
",",
"this",
".",
"_offset",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Applies one implementation of 'point inside polygon' algorithm
@method containsPoint
@param e { Event } event object
@param target { fabric.Object } object to test against
@return {Boolean} true if point contains within area of given object
|
[
"Applies",
"one",
"implementation",
"of",
"point",
"inside",
"polygon",
"algorithm"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L6471-L6490
|
|
11,415
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function (x, y) {
var t = this._currentTransform,
o = this._offset;
if (t.target.lockRotation) return;
var lastAngle = atan2(t.ey - t.top - o.top, t.ex - t.left - o.left),
curAngle = atan2(y - t.top - o.top, x - t.left - o.left);
t.target._theta = (curAngle - lastAngle) + t.theta;
}
|
javascript
|
function (x, y) {
var t = this._currentTransform,
o = this._offset;
if (t.target.lockRotation) return;
var lastAngle = atan2(t.ey - t.top - o.top, t.ex - t.left - o.left),
curAngle = atan2(y - t.top - o.top, x - t.left - o.left);
t.target._theta = (curAngle - lastAngle) + t.theta;
}
|
[
"function",
"(",
"x",
",",
"y",
")",
"{",
"var",
"t",
"=",
"this",
".",
"_currentTransform",
",",
"o",
"=",
"this",
".",
"_offset",
";",
"if",
"(",
"t",
".",
"target",
".",
"lockRotation",
")",
"return",
";",
"var",
"lastAngle",
"=",
"atan2",
"(",
"t",
".",
"ey",
"-",
"t",
".",
"top",
"-",
"o",
".",
"top",
",",
"t",
".",
"ex",
"-",
"t",
".",
"left",
"-",
"o",
".",
"left",
")",
",",
"curAngle",
"=",
"atan2",
"(",
"y",
"-",
"t",
".",
"top",
"-",
"o",
".",
"top",
",",
"x",
"-",
"t",
".",
"left",
"-",
"o",
".",
"left",
")",
";",
"t",
".",
"target",
".",
"_theta",
"=",
"(",
"curAngle",
"-",
"lastAngle",
")",
"+",
"t",
".",
"theta",
";",
"}"
] |
Rotates object by invoking its rotate method
@method _rotateObject
@param x {Number} pointer's x coordinate
@param y {Number} pointer's y coordinate
|
[
"Rotates",
"object",
"by",
"invoking",
"its",
"rotate",
"method"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L6801-L6812
|
|
11,416
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function (e, skipGroup) {
var target,
pointer = this.getPointer(e);
// first check current group (if one exists)
var activeGroup = this.getActiveGroup();
if (activeGroup && !skipGroup && this.containsPoint(e, activeGroup)) {
target = activeGroup;
return target;
}
// then check all of the objects on canvas
// Cache all targets where their bounding box contains point.
var possibleTargets = [];
for (var i = this._objects.length; i--; ) {
if (this._objects[i] && this.containsPoint(e, this._objects[i])) {
if (this.perPixelTargetFind || this._objects[i].perPixelTargetFind) {
possibleTargets[possibleTargets.length] = this._objects[i];
}
else {
target = this._objects[i];
this.relatedTarget = target;
break;
}
}
}
for (var i = 0, len = possibleTargets.length; i < len; i++) {
var pointer = this.getPointer(e);
var isTransparent = this._isTargetTransparent(possibleTargets[i], pointer.x, pointer.y);
if (!isTransparent) {
target = possibleTargets[i];
this.relatedTarget = target;
break;
}
}
if (target && target.selectable) {
return target;
}
}
|
javascript
|
function (e, skipGroup) {
var target,
pointer = this.getPointer(e);
// first check current group (if one exists)
var activeGroup = this.getActiveGroup();
if (activeGroup && !skipGroup && this.containsPoint(e, activeGroup)) {
target = activeGroup;
return target;
}
// then check all of the objects on canvas
// Cache all targets where their bounding box contains point.
var possibleTargets = [];
for (var i = this._objects.length; i--; ) {
if (this._objects[i] && this.containsPoint(e, this._objects[i])) {
if (this.perPixelTargetFind || this._objects[i].perPixelTargetFind) {
possibleTargets[possibleTargets.length] = this._objects[i];
}
else {
target = this._objects[i];
this.relatedTarget = target;
break;
}
}
}
for (var i = 0, len = possibleTargets.length; i < len; i++) {
var pointer = this.getPointer(e);
var isTransparent = this._isTargetTransparent(possibleTargets[i], pointer.x, pointer.y);
if (!isTransparent) {
target = possibleTargets[i];
this.relatedTarget = target;
break;
}
}
if (target && target.selectable) {
return target;
}
}
|
[
"function",
"(",
"e",
",",
"skipGroup",
")",
"{",
"var",
"target",
",",
"pointer",
"=",
"this",
".",
"getPointer",
"(",
"e",
")",
";",
"// first check current group (if one exists)",
"var",
"activeGroup",
"=",
"this",
".",
"getActiveGroup",
"(",
")",
";",
"if",
"(",
"activeGroup",
"&&",
"!",
"skipGroup",
"&&",
"this",
".",
"containsPoint",
"(",
"e",
",",
"activeGroup",
")",
")",
"{",
"target",
"=",
"activeGroup",
";",
"return",
"target",
";",
"}",
"// then check all of the objects on canvas",
"// Cache all targets where their bounding box contains point.",
"var",
"possibleTargets",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"this",
".",
"_objects",
".",
"length",
";",
"i",
"--",
";",
")",
"{",
"if",
"(",
"this",
".",
"_objects",
"[",
"i",
"]",
"&&",
"this",
".",
"containsPoint",
"(",
"e",
",",
"this",
".",
"_objects",
"[",
"i",
"]",
")",
")",
"{",
"if",
"(",
"this",
".",
"perPixelTargetFind",
"||",
"this",
".",
"_objects",
"[",
"i",
"]",
".",
"perPixelTargetFind",
")",
"{",
"possibleTargets",
"[",
"possibleTargets",
".",
"length",
"]",
"=",
"this",
".",
"_objects",
"[",
"i",
"]",
";",
"}",
"else",
"{",
"target",
"=",
"this",
".",
"_objects",
"[",
"i",
"]",
";",
"this",
".",
"relatedTarget",
"=",
"target",
";",
"break",
";",
"}",
"}",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"possibleTargets",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"var",
"pointer",
"=",
"this",
".",
"getPointer",
"(",
"e",
")",
";",
"var",
"isTransparent",
"=",
"this",
".",
"_isTargetTransparent",
"(",
"possibleTargets",
"[",
"i",
"]",
",",
"pointer",
".",
"x",
",",
"pointer",
".",
"y",
")",
";",
"if",
"(",
"!",
"isTransparent",
")",
"{",
"target",
"=",
"possibleTargets",
"[",
"i",
"]",
";",
"this",
".",
"relatedTarget",
"=",
"target",
";",
"break",
";",
"}",
"}",
"if",
"(",
"target",
"&&",
"target",
".",
"selectable",
")",
"{",
"return",
"target",
";",
"}",
"}"
] |
Method that determines what object we are clicking on
@method findTarget
@param {Event} e mouse event
@param {Boolean} skipGroup when true, group is skipped and only objects are traversed through
|
[
"Method",
"that",
"determines",
"what",
"object",
"we",
"are",
"clicking",
"on"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L6936-L6976
|
|
11,417
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function (e) {
var pointer = getPointer(e);
return {
x: pointer.x - this._offset.left,
y: pointer.y - this._offset.top
};
}
|
javascript
|
function (e) {
var pointer = getPointer(e);
return {
x: pointer.x - this._offset.left,
y: pointer.y - this._offset.top
};
}
|
[
"function",
"(",
"e",
")",
"{",
"var",
"pointer",
"=",
"getPointer",
"(",
"e",
")",
";",
"return",
"{",
"x",
":",
"pointer",
".",
"x",
"-",
"this",
".",
"_offset",
".",
"left",
",",
"y",
":",
"pointer",
".",
"y",
"-",
"this",
".",
"_offset",
".",
"top",
"}",
";",
"}"
] |
Returns pointer coordinates relative to canvas.
@method getPointer
@return {Object} object with "x" and "y" number values
|
[
"Returns",
"pointer",
"coordinates",
"relative",
"to",
"canvas",
"."
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L6983-L6989
|
|
11,418
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function (object, e) {
if (this._activeObject) {
this._activeObject.setActive(false);
}
this._activeObject = object;
object.setActive(true);
this.renderAll();
this.fire('object:selected', { target: object, e: e });
object.fire('selected', { e: e });
return this;
}
|
javascript
|
function (object, e) {
if (this._activeObject) {
this._activeObject.setActive(false);
}
this._activeObject = object;
object.setActive(true);
this.renderAll();
this.fire('object:selected', { target: object, e: e });
object.fire('selected', { e: e });
return this;
}
|
[
"function",
"(",
"object",
",",
"e",
")",
"{",
"if",
"(",
"this",
".",
"_activeObject",
")",
"{",
"this",
".",
"_activeObject",
".",
"setActive",
"(",
"false",
")",
";",
"}",
"this",
".",
"_activeObject",
"=",
"object",
";",
"object",
".",
"setActive",
"(",
"true",
")",
";",
"this",
".",
"renderAll",
"(",
")",
";",
"this",
".",
"fire",
"(",
"'object:selected'",
",",
"{",
"target",
":",
"object",
",",
"e",
":",
"e",
"}",
")",
";",
"object",
".",
"fire",
"(",
"'selected'",
",",
"{",
"e",
":",
"e",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Sets given object as active
@method setActiveObject
@param object {fabric.Object} Object to set as an active one
@return {fabric.Canvas} thisArg
@chainable
|
[
"Sets",
"given",
"object",
"as",
"active"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L7077-L7089
|
|
11,419
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function () {
var activeObject = this.getActiveGroup() || this.getActiveObject();
if (activeObject) {
this.fire('before:selection:cleared', { target: activeObject });
}
this.deactivateAll();
if (activeObject) {
this.fire('selection:cleared');
}
return this;
}
|
javascript
|
function () {
var activeObject = this.getActiveGroup() || this.getActiveObject();
if (activeObject) {
this.fire('before:selection:cleared', { target: activeObject });
}
this.deactivateAll();
if (activeObject) {
this.fire('selection:cleared');
}
return this;
}
|
[
"function",
"(",
")",
"{",
"var",
"activeObject",
"=",
"this",
".",
"getActiveGroup",
"(",
")",
"||",
"this",
".",
"getActiveObject",
"(",
")",
";",
"if",
"(",
"activeObject",
")",
"{",
"this",
".",
"fire",
"(",
"'before:selection:cleared'",
",",
"{",
"target",
":",
"activeObject",
"}",
")",
";",
"}",
"this",
".",
"deactivateAll",
"(",
")",
";",
"if",
"(",
"activeObject",
")",
"{",
"this",
".",
"fire",
"(",
"'selection:cleared'",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Deactivates all objects and dispatches appropriate events
@method deactivateAllWithDispatch
@return {fabric.Canvas} thisArg
|
[
"Deactivates",
"all",
"objects",
"and",
"dispatches",
"appropriate",
"events"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L7171-L7181
|
|
11,420
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function (object, callbacks) {
callbacks = callbacks || { };
var empty = function() { },
onComplete = callbacks.onComplete || empty,
onChange = callbacks.onChange || empty,
_this = this;
fabric.util.animate({
startValue: object.get('left'),
endValue: this.getCenter().left,
duration: this.FX_DURATION,
onChange: function(value) {
object.set('left', value);
_this.renderAll();
onChange();
},
onComplete: function() {
object.setCoords();
onComplete();
}
});
return this;
}
|
javascript
|
function (object, callbacks) {
callbacks = callbacks || { };
var empty = function() { },
onComplete = callbacks.onComplete || empty,
onChange = callbacks.onChange || empty,
_this = this;
fabric.util.animate({
startValue: object.get('left'),
endValue: this.getCenter().left,
duration: this.FX_DURATION,
onChange: function(value) {
object.set('left', value);
_this.renderAll();
onChange();
},
onComplete: function() {
object.setCoords();
onComplete();
}
});
return this;
}
|
[
"function",
"(",
"object",
",",
"callbacks",
")",
"{",
"callbacks",
"=",
"callbacks",
"||",
"{",
"}",
";",
"var",
"empty",
"=",
"function",
"(",
")",
"{",
"}",
",",
"onComplete",
"=",
"callbacks",
".",
"onComplete",
"||",
"empty",
",",
"onChange",
"=",
"callbacks",
".",
"onChange",
"||",
"empty",
",",
"_this",
"=",
"this",
";",
"fabric",
".",
"util",
".",
"animate",
"(",
"{",
"startValue",
":",
"object",
".",
"get",
"(",
"'left'",
")",
",",
"endValue",
":",
"this",
".",
"getCenter",
"(",
")",
".",
"left",
",",
"duration",
":",
"this",
".",
"FX_DURATION",
",",
"onChange",
":",
"function",
"(",
"value",
")",
"{",
"object",
".",
"set",
"(",
"'left'",
",",
"value",
")",
";",
"_this",
".",
"renderAll",
"(",
")",
";",
"onChange",
"(",
")",
";",
"}",
",",
"onComplete",
":",
"function",
"(",
")",
"{",
"object",
".",
"setCoords",
"(",
")",
";",
"onComplete",
"(",
")",
";",
"}",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Centers object horizontally with animation.
@method fxCenterObjectH
@param {fabric.Object} object Object to center
@param {Object} [callbacks] Callbacks object with optional "onComplete" and/or "onChange" properties
@return {fabric.Canvas} thisArg
@chainable
|
[
"Centers",
"object",
"horizontally",
"with",
"animation",
"."
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L7219-L7243
|
|
11,421
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function (callback) {
var data = JSON.stringify(this);
this.cloneWithoutData(function(clone) {
clone.loadFromJSON(data, function() {
callback && callback(clone);
});
});
}
|
javascript
|
function (callback) {
var data = JSON.stringify(this);
this.cloneWithoutData(function(clone) {
clone.loadFromJSON(data, function() {
callback && callback(clone);
});
});
}
|
[
"function",
"(",
"callback",
")",
"{",
"var",
"data",
"=",
"JSON",
".",
"stringify",
"(",
"this",
")",
";",
"this",
".",
"cloneWithoutData",
"(",
"function",
"(",
"clone",
")",
"{",
"clone",
".",
"loadFromJSON",
"(",
"data",
",",
"function",
"(",
")",
"{",
"callback",
"&&",
"callback",
"(",
"clone",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Clones canvas instance
@method clone
@param {Object} [callback] Receives cloned instance as a first argument
|
[
"Clones",
"canvas",
"instance"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L7546-L7553
|
|
11,422
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function() {
var NUM_FRACTION_DIGITS = fabric.Object.NUM_FRACTION_DIGITS;
var object = {
type: this.type,
left: toFixed(this.left, NUM_FRACTION_DIGITS),
top: toFixed(this.top, NUM_FRACTION_DIGITS),
width: toFixed(this.width, NUM_FRACTION_DIGITS),
height: toFixed(this.height, NUM_FRACTION_DIGITS),
fill: (this.fill && this.fill.toObject) ? this.fill.toObject() : this.fill,
overlayFill: this.overlayFill,
stroke: this.stroke,
strokeWidth: this.strokeWidth,
strokeDashArray: this.strokeDashArray,
scaleX: toFixed(this.scaleX, NUM_FRACTION_DIGITS),
scaleY: toFixed(this.scaleY, NUM_FRACTION_DIGITS),
angle: toFixed(this.getAngle(), NUM_FRACTION_DIGITS),
flipX: this.flipX,
flipY: this.flipY,
opacity: toFixed(this.opacity, NUM_FRACTION_DIGITS),
selectable: this.selectable,
hasControls: this.hasControls,
hasBorders: this.hasBorders,
hasRotatingPoint: this.hasRotatingPoint,
transparentCorners: this.transparentCorners,
perPixelTargetFind: this.perPixelTargetFind
};
if (!this.includeDefaultValues) {
object = this._removeDefaultValues(object);
}
return object;
}
|
javascript
|
function() {
var NUM_FRACTION_DIGITS = fabric.Object.NUM_FRACTION_DIGITS;
var object = {
type: this.type,
left: toFixed(this.left, NUM_FRACTION_DIGITS),
top: toFixed(this.top, NUM_FRACTION_DIGITS),
width: toFixed(this.width, NUM_FRACTION_DIGITS),
height: toFixed(this.height, NUM_FRACTION_DIGITS),
fill: (this.fill && this.fill.toObject) ? this.fill.toObject() : this.fill,
overlayFill: this.overlayFill,
stroke: this.stroke,
strokeWidth: this.strokeWidth,
strokeDashArray: this.strokeDashArray,
scaleX: toFixed(this.scaleX, NUM_FRACTION_DIGITS),
scaleY: toFixed(this.scaleY, NUM_FRACTION_DIGITS),
angle: toFixed(this.getAngle(), NUM_FRACTION_DIGITS),
flipX: this.flipX,
flipY: this.flipY,
opacity: toFixed(this.opacity, NUM_FRACTION_DIGITS),
selectable: this.selectable,
hasControls: this.hasControls,
hasBorders: this.hasBorders,
hasRotatingPoint: this.hasRotatingPoint,
transparentCorners: this.transparentCorners,
perPixelTargetFind: this.perPixelTargetFind
};
if (!this.includeDefaultValues) {
object = this._removeDefaultValues(object);
}
return object;
}
|
[
"function",
"(",
")",
"{",
"var",
"NUM_FRACTION_DIGITS",
"=",
"fabric",
".",
"Object",
".",
"NUM_FRACTION_DIGITS",
";",
"var",
"object",
"=",
"{",
"type",
":",
"this",
".",
"type",
",",
"left",
":",
"toFixed",
"(",
"this",
".",
"left",
",",
"NUM_FRACTION_DIGITS",
")",
",",
"top",
":",
"toFixed",
"(",
"this",
".",
"top",
",",
"NUM_FRACTION_DIGITS",
")",
",",
"width",
":",
"toFixed",
"(",
"this",
".",
"width",
",",
"NUM_FRACTION_DIGITS",
")",
",",
"height",
":",
"toFixed",
"(",
"this",
".",
"height",
",",
"NUM_FRACTION_DIGITS",
")",
",",
"fill",
":",
"(",
"this",
".",
"fill",
"&&",
"this",
".",
"fill",
".",
"toObject",
")",
"?",
"this",
".",
"fill",
".",
"toObject",
"(",
")",
":",
"this",
".",
"fill",
",",
"overlayFill",
":",
"this",
".",
"overlayFill",
",",
"stroke",
":",
"this",
".",
"stroke",
",",
"strokeWidth",
":",
"this",
".",
"strokeWidth",
",",
"strokeDashArray",
":",
"this",
".",
"strokeDashArray",
",",
"scaleX",
":",
"toFixed",
"(",
"this",
".",
"scaleX",
",",
"NUM_FRACTION_DIGITS",
")",
",",
"scaleY",
":",
"toFixed",
"(",
"this",
".",
"scaleY",
",",
"NUM_FRACTION_DIGITS",
")",
",",
"angle",
":",
"toFixed",
"(",
"this",
".",
"getAngle",
"(",
")",
",",
"NUM_FRACTION_DIGITS",
")",
",",
"flipX",
":",
"this",
".",
"flipX",
",",
"flipY",
":",
"this",
".",
"flipY",
",",
"opacity",
":",
"toFixed",
"(",
"this",
".",
"opacity",
",",
"NUM_FRACTION_DIGITS",
")",
",",
"selectable",
":",
"this",
".",
"selectable",
",",
"hasControls",
":",
"this",
".",
"hasControls",
",",
"hasBorders",
":",
"this",
".",
"hasBorders",
",",
"hasRotatingPoint",
":",
"this",
".",
"hasRotatingPoint",
",",
"transparentCorners",
":",
"this",
".",
"transparentCorners",
",",
"perPixelTargetFind",
":",
"this",
".",
"perPixelTargetFind",
"}",
";",
"if",
"(",
"!",
"this",
".",
"includeDefaultValues",
")",
"{",
"object",
"=",
"this",
".",
"_removeDefaultValues",
"(",
"object",
")",
";",
"}",
"return",
"object",
";",
"}"
] |
Returns an object representation of an instance
@method toObject
@return {Object}
|
[
"Returns",
"an",
"object",
"representation",
"of",
"an",
"instance"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L7882-L7916
|
|
11,423
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function() {
return [
"stroke: ", (this.stroke ? this.stroke : 'none'), "; ",
"stroke-width: ", (this.strokeWidth ? this.strokeWidth : '0'), "; ",
"stroke-dasharray: ", (this.strokeDashArray ? this.strokeDashArray.join(' ') : "; "),
"fill: ", (this.fill ? this.fill : 'none'), "; ",
"opacity: ", (this.opacity ? this.opacity : '1'), ";"
].join("");
}
|
javascript
|
function() {
return [
"stroke: ", (this.stroke ? this.stroke : 'none'), "; ",
"stroke-width: ", (this.strokeWidth ? this.strokeWidth : '0'), "; ",
"stroke-dasharray: ", (this.strokeDashArray ? this.strokeDashArray.join(' ') : "; "),
"fill: ", (this.fill ? this.fill : 'none'), "; ",
"opacity: ", (this.opacity ? this.opacity : '1'), ";"
].join("");
}
|
[
"function",
"(",
")",
"{",
"return",
"[",
"\"stroke: \"",
",",
"(",
"this",
".",
"stroke",
"?",
"this",
".",
"stroke",
":",
"'none'",
")",
",",
"\"; \"",
",",
"\"stroke-width: \"",
",",
"(",
"this",
".",
"strokeWidth",
"?",
"this",
".",
"strokeWidth",
":",
"'0'",
")",
",",
"\"; \"",
",",
"\"stroke-dasharray: \"",
",",
"(",
"this",
".",
"strokeDashArray",
"?",
"this",
".",
"strokeDashArray",
".",
"join",
"(",
"' '",
")",
":",
"\"; \"",
")",
",",
"\"fill: \"",
",",
"(",
"this",
".",
"fill",
"?",
"this",
".",
"fill",
":",
"'none'",
")",
",",
"\"; \"",
",",
"\"opacity: \"",
",",
"(",
"this",
".",
"opacity",
"?",
"this",
".",
"opacity",
":",
"'1'",
")",
",",
"\";\"",
"]",
".",
"join",
"(",
"\"\"",
")",
";",
"}"
] |
Returns styles-string for svg-export
@method getSvgStyles
@return {string}
|
[
"Returns",
"styles",
"-",
"string",
"for",
"svg",
"-",
"export"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L7932-L7940
|
|
11,424
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function() {
var angle = this.getAngle();
return [
"translate(", toFixed(this.left, 2), " ", toFixed(this.top, 2), ")",
angle !== 0 ? (" rotate(" + toFixed(angle, 2) + ")") : '',
(this.scaleX === 1 && this.scaleY === 1) ? '' : (" scale(" + toFixed(this.scaleX, 2) + " " + toFixed(this.scaleY, 2) + ")")
].join('');
}
|
javascript
|
function() {
var angle = this.getAngle();
return [
"translate(", toFixed(this.left, 2), " ", toFixed(this.top, 2), ")",
angle !== 0 ? (" rotate(" + toFixed(angle, 2) + ")") : '',
(this.scaleX === 1 && this.scaleY === 1) ? '' : (" scale(" + toFixed(this.scaleX, 2) + " " + toFixed(this.scaleY, 2) + ")")
].join('');
}
|
[
"function",
"(",
")",
"{",
"var",
"angle",
"=",
"this",
".",
"getAngle",
"(",
")",
";",
"return",
"[",
"\"translate(\"",
",",
"toFixed",
"(",
"this",
".",
"left",
",",
"2",
")",
",",
"\" \"",
",",
"toFixed",
"(",
"this",
".",
"top",
",",
"2",
")",
",",
"\")\"",
",",
"angle",
"!==",
"0",
"?",
"(",
"\" rotate(\"",
"+",
"toFixed",
"(",
"angle",
",",
"2",
")",
"+",
"\")\"",
")",
":",
"''",
",",
"(",
"this",
".",
"scaleX",
"===",
"1",
"&&",
"this",
".",
"scaleY",
"===",
"1",
")",
"?",
"''",
":",
"(",
"\" scale(\"",
"+",
"toFixed",
"(",
"this",
".",
"scaleX",
",",
"2",
")",
"+",
"\" \"",
"+",
"toFixed",
"(",
"this",
".",
"scaleY",
",",
"2",
")",
"+",
"\")\"",
")",
"]",
".",
"join",
"(",
"''",
")",
";",
"}"
] |
Returns transform-string for svg-export
@method getSvgTransform
@return {string}
|
[
"Returns",
"transform",
"-",
"string",
"for",
"svg",
"-",
"export"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L7947-L7954
|
|
11,425
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(key, value) {
if (typeof key === 'object') {
for (var prop in key) {
this._set(prop, key[prop]);
}
}
else {
if (typeof value === 'function') {
this._set(key, value(this.get(key)));
}
else {
this._set(key, value);
}
}
return this;
}
|
javascript
|
function(key, value) {
if (typeof key === 'object') {
for (var prop in key) {
this._set(prop, key[prop]);
}
}
else {
if (typeof value === 'function') {
this._set(key, value(this.get(key)));
}
else {
this._set(key, value);
}
}
return this;
}
|
[
"function",
"(",
"key",
",",
"value",
")",
"{",
"if",
"(",
"typeof",
"key",
"===",
"'object'",
")",
"{",
"for",
"(",
"var",
"prop",
"in",
"key",
")",
"{",
"this",
".",
"_set",
"(",
"prop",
",",
"key",
"[",
"prop",
"]",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"typeof",
"value",
"===",
"'function'",
")",
"{",
"this",
".",
"_set",
"(",
"key",
",",
"value",
"(",
"this",
".",
"get",
"(",
"key",
")",
")",
")",
";",
"}",
"else",
"{",
"this",
".",
"_set",
"(",
"key",
",",
"value",
")",
";",
"}",
"}",
"return",
"this",
";",
"}"
] |
Sets property to a given value
@method set
@param {String} name
@param {Object|Function} value
@return {fabric.Group} thisArg
@chainable
|
[
"Sets",
"property",
"to",
"a",
"given",
"value"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L8007-L8022
|
|
11,426
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function() {
this.oCoords || this.setCoords();
var xCoords = [this.oCoords.tl.x, this.oCoords.tr.x, this.oCoords.br.x, this.oCoords.bl.x];
var minX = fabric.util.array.min(xCoords);
var maxX = fabric.util.array.max(xCoords);
return Math.abs(minX - maxX);
}
|
javascript
|
function() {
this.oCoords || this.setCoords();
var xCoords = [this.oCoords.tl.x, this.oCoords.tr.x, this.oCoords.br.x, this.oCoords.bl.x];
var minX = fabric.util.array.min(xCoords);
var maxX = fabric.util.array.max(xCoords);
return Math.abs(minX - maxX);
}
|
[
"function",
"(",
")",
"{",
"this",
".",
"oCoords",
"||",
"this",
".",
"setCoords",
"(",
")",
";",
"var",
"xCoords",
"=",
"[",
"this",
".",
"oCoords",
".",
"tl",
".",
"x",
",",
"this",
".",
"oCoords",
".",
"tr",
".",
"x",
",",
"this",
".",
"oCoords",
".",
"br",
".",
"x",
",",
"this",
".",
"oCoords",
".",
"bl",
".",
"x",
"]",
";",
"var",
"minX",
"=",
"fabric",
".",
"util",
".",
"array",
".",
"min",
"(",
"xCoords",
")",
";",
"var",
"maxX",
"=",
"fabric",
".",
"util",
".",
"array",
".",
"max",
"(",
"xCoords",
")",
";",
"return",
"Math",
".",
"abs",
"(",
"minX",
"-",
"maxX",
")",
";",
"}"
] |
Returns width of an object's bounding rectangle
@method getBoundingRectWidth
@return {Number} width value
|
[
"Returns",
"width",
"of",
"an",
"object",
"s",
"bounding",
"rectangle"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L8309-L8315
|
|
11,427
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function() {
this.oCoords || this.setCoords();
var yCoords = [this.oCoords.tl.y, this.oCoords.tr.y, this.oCoords.br.y, this.oCoords.bl.y];
var minY = fabric.util.array.min(yCoords);
var maxY = fabric.util.array.max(yCoords);
return Math.abs(minY - maxY);
}
|
javascript
|
function() {
this.oCoords || this.setCoords();
var yCoords = [this.oCoords.tl.y, this.oCoords.tr.y, this.oCoords.br.y, this.oCoords.bl.y];
var minY = fabric.util.array.min(yCoords);
var maxY = fabric.util.array.max(yCoords);
return Math.abs(minY - maxY);
}
|
[
"function",
"(",
")",
"{",
"this",
".",
"oCoords",
"||",
"this",
".",
"setCoords",
"(",
")",
";",
"var",
"yCoords",
"=",
"[",
"this",
".",
"oCoords",
".",
"tl",
".",
"y",
",",
"this",
".",
"oCoords",
".",
"tr",
".",
"y",
",",
"this",
".",
"oCoords",
".",
"br",
".",
"y",
",",
"this",
".",
"oCoords",
".",
"bl",
".",
"y",
"]",
";",
"var",
"minY",
"=",
"fabric",
".",
"util",
".",
"array",
".",
"min",
"(",
"yCoords",
")",
";",
"var",
"maxY",
"=",
"fabric",
".",
"util",
".",
"array",
".",
"max",
"(",
"yCoords",
")",
";",
"return",
"Math",
".",
"abs",
"(",
"minY",
"-",
"maxY",
")",
";",
"}"
] |
Returns height of an object's bounding rectangle
@method getBoundingRectHeight
@return {Number} height value
|
[
"Returns",
"height",
"of",
"an",
"object",
"s",
"bounding",
"rectangle"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L8322-L8328
|
|
11,428
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(options) {
if (this.constructor.fromObject) {
return this.constructor.fromObject(this.toObject(), options);
}
return new fabric.Object(this.toObject());
}
|
javascript
|
function(options) {
if (this.constructor.fromObject) {
return this.constructor.fromObject(this.toObject(), options);
}
return new fabric.Object(this.toObject());
}
|
[
"function",
"(",
"options",
")",
"{",
"if",
"(",
"this",
".",
"constructor",
".",
"fromObject",
")",
"{",
"return",
"this",
".",
"constructor",
".",
"fromObject",
"(",
"this",
".",
"toObject",
"(",
")",
",",
"options",
")",
";",
"}",
"return",
"new",
"fabric",
".",
"Object",
"(",
"this",
".",
"toObject",
"(",
")",
")",
";",
"}"
] |
Clones an instance
@method clone
@param {Object} options object
@return {fabric.Object} clone of an instance
|
[
"Clones",
"an",
"instance"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L8567-L8572
|
|
11,429
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(callback) {
if (fabric.Image) {
var i = new Image();
/** @ignore */
i.onload = function() {
if (callback) {
callback(new fabric.Image(i), orig);
}
i = i.onload = null;
};
var orig = {
angle: this.get('angle'),
flipX: this.get('flipX'),
flipY: this.get('flipY')
};
// normalize angle
this.set('angle', 0).set('flipX', false).set('flipY', false);
this.toDataURL(function(dataURL) {
i.src = dataURL;
});
}
return this;
}
|
javascript
|
function(callback) {
if (fabric.Image) {
var i = new Image();
/** @ignore */
i.onload = function() {
if (callback) {
callback(new fabric.Image(i), orig);
}
i = i.onload = null;
};
var orig = {
angle: this.get('angle'),
flipX: this.get('flipX'),
flipY: this.get('flipY')
};
// normalize angle
this.set('angle', 0).set('flipX', false).set('flipY', false);
this.toDataURL(function(dataURL) {
i.src = dataURL;
});
}
return this;
}
|
[
"function",
"(",
"callback",
")",
"{",
"if",
"(",
"fabric",
".",
"Image",
")",
"{",
"var",
"i",
"=",
"new",
"Image",
"(",
")",
";",
"/** @ignore */",
"i",
".",
"onload",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"callback",
")",
"{",
"callback",
"(",
"new",
"fabric",
".",
"Image",
"(",
"i",
")",
",",
"orig",
")",
";",
"}",
"i",
"=",
"i",
".",
"onload",
"=",
"null",
";",
"}",
";",
"var",
"orig",
"=",
"{",
"angle",
":",
"this",
".",
"get",
"(",
"'angle'",
")",
",",
"flipX",
":",
"this",
".",
"get",
"(",
"'flipX'",
")",
",",
"flipY",
":",
"this",
".",
"get",
"(",
"'flipY'",
")",
"}",
";",
"// normalize angle",
"this",
".",
"set",
"(",
"'angle'",
",",
"0",
")",
".",
"set",
"(",
"'flipX'",
",",
"false",
")",
".",
"set",
"(",
"'flipY'",
",",
"false",
")",
";",
"this",
".",
"toDataURL",
"(",
"function",
"(",
"dataURL",
")",
"{",
"i",
".",
"src",
"=",
"dataURL",
";",
"}",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Creates an instance of fabric.Image out of an object
@method cloneAsImage
@param callback {Function} callback, invoked with an instance as a first argument
@return {fabric.Object} thisArg
@chainable
|
[
"Creates",
"an",
"instance",
"of",
"fabric",
".",
"Image",
"out",
"of",
"an",
"object"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L8581-L8606
|
|
11,430
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(callback) {
var el = fabric.document.createElement('canvas');
if (!el.getContext && typeof G_vmlCanvasManager != 'undefined') {
G_vmlCanvasManager.initElement(el);
}
el.width = this.getBoundingRectWidth();
el.height = this.getBoundingRectHeight();
fabric.util.wrapElement(el, 'div');
var canvas = new fabric.Canvas(el);
canvas.backgroundColor = 'transparent';
canvas.renderAll();
if (this.constructor.async) {
this.clone(proceed);
}
else {
proceed(this.clone());
}
function proceed(clone) {
clone.left = el.width / 2;
clone.top = el.height / 2;
clone.setActive(false);
canvas.add(clone);
var data = canvas.toDataURL('png');
canvas.dispose();
canvas = clone = null;
callback && callback(data);
}
}
|
javascript
|
function(callback) {
var el = fabric.document.createElement('canvas');
if (!el.getContext && typeof G_vmlCanvasManager != 'undefined') {
G_vmlCanvasManager.initElement(el);
}
el.width = this.getBoundingRectWidth();
el.height = this.getBoundingRectHeight();
fabric.util.wrapElement(el, 'div');
var canvas = new fabric.Canvas(el);
canvas.backgroundColor = 'transparent';
canvas.renderAll();
if (this.constructor.async) {
this.clone(proceed);
}
else {
proceed(this.clone());
}
function proceed(clone) {
clone.left = el.width / 2;
clone.top = el.height / 2;
clone.setActive(false);
canvas.add(clone);
var data = canvas.toDataURL('png');
canvas.dispose();
canvas = clone = null;
callback && callback(data);
}
}
|
[
"function",
"(",
"callback",
")",
"{",
"var",
"el",
"=",
"fabric",
".",
"document",
".",
"createElement",
"(",
"'canvas'",
")",
";",
"if",
"(",
"!",
"el",
".",
"getContext",
"&&",
"typeof",
"G_vmlCanvasManager",
"!=",
"'undefined'",
")",
"{",
"G_vmlCanvasManager",
".",
"initElement",
"(",
"el",
")",
";",
"}",
"el",
".",
"width",
"=",
"this",
".",
"getBoundingRectWidth",
"(",
")",
";",
"el",
".",
"height",
"=",
"this",
".",
"getBoundingRectHeight",
"(",
")",
";",
"fabric",
".",
"util",
".",
"wrapElement",
"(",
"el",
",",
"'div'",
")",
";",
"var",
"canvas",
"=",
"new",
"fabric",
".",
"Canvas",
"(",
"el",
")",
";",
"canvas",
".",
"backgroundColor",
"=",
"'transparent'",
";",
"canvas",
".",
"renderAll",
"(",
")",
";",
"if",
"(",
"this",
".",
"constructor",
".",
"async",
")",
"{",
"this",
".",
"clone",
"(",
"proceed",
")",
";",
"}",
"else",
"{",
"proceed",
"(",
"this",
".",
"clone",
"(",
")",
")",
";",
"}",
"function",
"proceed",
"(",
"clone",
")",
"{",
"clone",
".",
"left",
"=",
"el",
".",
"width",
"/",
"2",
";",
"clone",
".",
"top",
"=",
"el",
".",
"height",
"/",
"2",
";",
"clone",
".",
"setActive",
"(",
"false",
")",
";",
"canvas",
".",
"add",
"(",
"clone",
")",
";",
"var",
"data",
"=",
"canvas",
".",
"toDataURL",
"(",
"'png'",
")",
";",
"canvas",
".",
"dispose",
"(",
")",
";",
"canvas",
"=",
"clone",
"=",
"null",
";",
"callback",
"&&",
"callback",
"(",
"data",
")",
";",
"}",
"}"
] |
Converts an object into a data-url-like string
@method toDataURL
@return {String} string of data
|
[
"Converts",
"an",
"object",
"into",
"a",
"data",
"-",
"url",
"-",
"like",
"string"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L8613-L8649
|
|
11,431
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(selectionTL, selectionBR) {
var oCoords = this.oCoords,
tl = new fabric.Point(oCoords.tl.x, oCoords.tl.y),
tr = new fabric.Point(oCoords.tr.x, oCoords.tr.y),
bl = new fabric.Point(oCoords.bl.x, oCoords.bl.y),
br = new fabric.Point(oCoords.br.x, oCoords.br.y);
var intersection = fabric.Intersection.intersectPolygonRectangle(
[tl, tr, br, bl],
selectionTL,
selectionBR
);
return (intersection.status === 'Intersection');
}
|
javascript
|
function(selectionTL, selectionBR) {
var oCoords = this.oCoords,
tl = new fabric.Point(oCoords.tl.x, oCoords.tl.y),
tr = new fabric.Point(oCoords.tr.x, oCoords.tr.y),
bl = new fabric.Point(oCoords.bl.x, oCoords.bl.y),
br = new fabric.Point(oCoords.br.x, oCoords.br.y);
var intersection = fabric.Intersection.intersectPolygonRectangle(
[tl, tr, br, bl],
selectionTL,
selectionBR
);
return (intersection.status === 'Intersection');
}
|
[
"function",
"(",
"selectionTL",
",",
"selectionBR",
")",
"{",
"var",
"oCoords",
"=",
"this",
".",
"oCoords",
",",
"tl",
"=",
"new",
"fabric",
".",
"Point",
"(",
"oCoords",
".",
"tl",
".",
"x",
",",
"oCoords",
".",
"tl",
".",
"y",
")",
",",
"tr",
"=",
"new",
"fabric",
".",
"Point",
"(",
"oCoords",
".",
"tr",
".",
"x",
",",
"oCoords",
".",
"tr",
".",
"y",
")",
",",
"bl",
"=",
"new",
"fabric",
".",
"Point",
"(",
"oCoords",
".",
"bl",
".",
"x",
",",
"oCoords",
".",
"bl",
".",
"y",
")",
",",
"br",
"=",
"new",
"fabric",
".",
"Point",
"(",
"oCoords",
".",
"br",
".",
"x",
",",
"oCoords",
".",
"br",
".",
"y",
")",
";",
"var",
"intersection",
"=",
"fabric",
".",
"Intersection",
".",
"intersectPolygonRectangle",
"(",
"[",
"tl",
",",
"tr",
",",
"br",
",",
"bl",
"]",
",",
"selectionTL",
",",
"selectionBR",
")",
";",
"return",
"(",
"intersection",
".",
"status",
"===",
"'Intersection'",
")",
";",
"}"
] |
Returns true if object intersects with an area formed by 2 points
@method intersectsWithRect
@param {Object} selectionTL
@param {Object} selectionBR
@return {Boolean}
|
[
"Returns",
"true",
"if",
"object",
"intersects",
"with",
"an",
"area",
"formed",
"by",
"2",
"points"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L8688-L8701
|
|
11,432
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(other) {
// extracts coords
function getCoords(oCoords) {
return {
tl: new fabric.Point(oCoords.tl.x, oCoords.tl.y),
tr: new fabric.Point(oCoords.tr.x, oCoords.tr.y),
bl: new fabric.Point(oCoords.bl.x, oCoords.bl.y),
br: new fabric.Point(oCoords.br.x, oCoords.br.y)
}
}
var thisCoords = getCoords(this.oCoords),
otherCoords = getCoords(other.oCoords);
var intersection = fabric.Intersection.intersectPolygonPolygon(
[thisCoords.tl, thisCoords.tr, thisCoords.br, thisCoords.bl],
[otherCoords.tl, otherCoords.tr, otherCoords.br, otherCoords.bl]
);
return (intersection.status === 'Intersection');
}
|
javascript
|
function(other) {
// extracts coords
function getCoords(oCoords) {
return {
tl: new fabric.Point(oCoords.tl.x, oCoords.tl.y),
tr: new fabric.Point(oCoords.tr.x, oCoords.tr.y),
bl: new fabric.Point(oCoords.bl.x, oCoords.bl.y),
br: new fabric.Point(oCoords.br.x, oCoords.br.y)
}
}
var thisCoords = getCoords(this.oCoords),
otherCoords = getCoords(other.oCoords);
var intersection = fabric.Intersection.intersectPolygonPolygon(
[thisCoords.tl, thisCoords.tr, thisCoords.br, thisCoords.bl],
[otherCoords.tl, otherCoords.tr, otherCoords.br, otherCoords.bl]
);
return (intersection.status === 'Intersection');
}
|
[
"function",
"(",
"other",
")",
"{",
"// extracts coords",
"function",
"getCoords",
"(",
"oCoords",
")",
"{",
"return",
"{",
"tl",
":",
"new",
"fabric",
".",
"Point",
"(",
"oCoords",
".",
"tl",
".",
"x",
",",
"oCoords",
".",
"tl",
".",
"y",
")",
",",
"tr",
":",
"new",
"fabric",
".",
"Point",
"(",
"oCoords",
".",
"tr",
".",
"x",
",",
"oCoords",
".",
"tr",
".",
"y",
")",
",",
"bl",
":",
"new",
"fabric",
".",
"Point",
"(",
"oCoords",
".",
"bl",
".",
"x",
",",
"oCoords",
".",
"bl",
".",
"y",
")",
",",
"br",
":",
"new",
"fabric",
".",
"Point",
"(",
"oCoords",
".",
"br",
".",
"x",
",",
"oCoords",
".",
"br",
".",
"y",
")",
"}",
"}",
"var",
"thisCoords",
"=",
"getCoords",
"(",
"this",
".",
"oCoords",
")",
",",
"otherCoords",
"=",
"getCoords",
"(",
"other",
".",
"oCoords",
")",
";",
"var",
"intersection",
"=",
"fabric",
".",
"Intersection",
".",
"intersectPolygonPolygon",
"(",
"[",
"thisCoords",
".",
"tl",
",",
"thisCoords",
".",
"tr",
",",
"thisCoords",
".",
"br",
",",
"thisCoords",
".",
"bl",
"]",
",",
"[",
"otherCoords",
".",
"tl",
",",
"otherCoords",
".",
"tr",
",",
"otherCoords",
".",
"br",
",",
"otherCoords",
".",
"bl",
"]",
")",
";",
"return",
"(",
"intersection",
".",
"status",
"===",
"'Intersection'",
")",
";",
"}"
] |
Returns true if object intersects with another object
@method intersectsWithObject
@param {Object} other Object to test
@return {Boolean}
|
[
"Returns",
"true",
"if",
"object",
"intersects",
"with",
"another",
"object"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L8709-L8728
|
|
11,433
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(selectionTL, selectionBR) {
var oCoords = this.oCoords,
tl = new fabric.Point(oCoords.tl.x, oCoords.tl.y),
tr = new fabric.Point(oCoords.tr.x, oCoords.tr.y),
bl = new fabric.Point(oCoords.bl.x, oCoords.bl.y),
br = new fabric.Point(oCoords.br.x, oCoords.br.y);
return tl.x > selectionTL.x
&& tr.x < selectionBR.x
&& tl.y > selectionTL.y
&& bl.y < selectionBR.y;
}
|
javascript
|
function(selectionTL, selectionBR) {
var oCoords = this.oCoords,
tl = new fabric.Point(oCoords.tl.x, oCoords.tl.y),
tr = new fabric.Point(oCoords.tr.x, oCoords.tr.y),
bl = new fabric.Point(oCoords.bl.x, oCoords.bl.y),
br = new fabric.Point(oCoords.br.x, oCoords.br.y);
return tl.x > selectionTL.x
&& tr.x < selectionBR.x
&& tl.y > selectionTL.y
&& bl.y < selectionBR.y;
}
|
[
"function",
"(",
"selectionTL",
",",
"selectionBR",
")",
"{",
"var",
"oCoords",
"=",
"this",
".",
"oCoords",
",",
"tl",
"=",
"new",
"fabric",
".",
"Point",
"(",
"oCoords",
".",
"tl",
".",
"x",
",",
"oCoords",
".",
"tl",
".",
"y",
")",
",",
"tr",
"=",
"new",
"fabric",
".",
"Point",
"(",
"oCoords",
".",
"tr",
".",
"x",
",",
"oCoords",
".",
"tr",
".",
"y",
")",
",",
"bl",
"=",
"new",
"fabric",
".",
"Point",
"(",
"oCoords",
".",
"bl",
".",
"x",
",",
"oCoords",
".",
"bl",
".",
"y",
")",
",",
"br",
"=",
"new",
"fabric",
".",
"Point",
"(",
"oCoords",
".",
"br",
".",
"x",
",",
"oCoords",
".",
"br",
".",
"y",
")",
";",
"return",
"tl",
".",
"x",
">",
"selectionTL",
".",
"x",
"&&",
"tr",
".",
"x",
"<",
"selectionBR",
".",
"x",
"&&",
"tl",
".",
"y",
">",
"selectionTL",
".",
"y",
"&&",
"bl",
".",
"y",
"<",
"selectionBR",
".",
"y",
";",
"}"
] |
Returns true if object is fully contained within area formed by 2 points
@method isContainedWithinRect
@param {Object} selectionTL
@param {Object} selectionBR
@return {Boolean}
|
[
"Returns",
"true",
"if",
"object",
"is",
"fully",
"contained",
"within",
"area",
"formed",
"by",
"2",
"points"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L8747-L8758
|
|
11,434
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(e, offset) {
if (!this.hasControls || !this.active) return false;
var pointer = getPointer(e),
ex = pointer.x - offset.left,
ey = pointer.y - offset.top,
xpoints,
lines;
for (var i in this.oCoords) {
if (i === 'mtr' && !this.hasRotatingPoint) {
continue;
}
if (this.lockUniScaling && (i === 'mt' || i === 'mr' || i === 'mb' || i === 'ml')) {
continue;
}
lines = this._getImageLines(this.oCoords[i].corner, i);
// debugging
// canvas.contextTop.fillRect(lines.bottomline.d.x, lines.bottomline.d.y, 2, 2);
// canvas.contextTop.fillRect(lines.bottomline.o.x, lines.bottomline.o.y, 2, 2);
// canvas.contextTop.fillRect(lines.leftline.d.x, lines.leftline.d.y, 2, 2);
// canvas.contextTop.fillRect(lines.leftline.o.x, lines.leftline.o.y, 2, 2);
// canvas.contextTop.fillRect(lines.topline.d.x, lines.topline.d.y, 2, 2);
// canvas.contextTop.fillRect(lines.topline.o.x, lines.topline.o.y, 2, 2);
// canvas.contextTop.fillRect(lines.rightline.d.x, lines.rightline.d.y, 2, 2);
// canvas.contextTop.fillRect(lines.rightline.o.x, lines.rightline.o.y, 2, 2);
xpoints = this._findCrossPoints(ex, ey, lines);
if (xpoints % 2 == 1 && xpoints != 0) {
this.__corner = i;
return i;
}
}
return false;
}
|
javascript
|
function(e, offset) {
if (!this.hasControls || !this.active) return false;
var pointer = getPointer(e),
ex = pointer.x - offset.left,
ey = pointer.y - offset.top,
xpoints,
lines;
for (var i in this.oCoords) {
if (i === 'mtr' && !this.hasRotatingPoint) {
continue;
}
if (this.lockUniScaling && (i === 'mt' || i === 'mr' || i === 'mb' || i === 'ml')) {
continue;
}
lines = this._getImageLines(this.oCoords[i].corner, i);
// debugging
// canvas.contextTop.fillRect(lines.bottomline.d.x, lines.bottomline.d.y, 2, 2);
// canvas.contextTop.fillRect(lines.bottomline.o.x, lines.bottomline.o.y, 2, 2);
// canvas.contextTop.fillRect(lines.leftline.d.x, lines.leftline.d.y, 2, 2);
// canvas.contextTop.fillRect(lines.leftline.o.x, lines.leftline.o.y, 2, 2);
// canvas.contextTop.fillRect(lines.topline.d.x, lines.topline.d.y, 2, 2);
// canvas.contextTop.fillRect(lines.topline.o.x, lines.topline.o.y, 2, 2);
// canvas.contextTop.fillRect(lines.rightline.d.x, lines.rightline.d.y, 2, 2);
// canvas.contextTop.fillRect(lines.rightline.o.x, lines.rightline.o.y, 2, 2);
xpoints = this._findCrossPoints(ex, ey, lines);
if (xpoints % 2 == 1 && xpoints != 0) {
this.__corner = i;
return i;
}
}
return false;
}
|
[
"function",
"(",
"e",
",",
"offset",
")",
"{",
"if",
"(",
"!",
"this",
".",
"hasControls",
"||",
"!",
"this",
".",
"active",
")",
"return",
"false",
";",
"var",
"pointer",
"=",
"getPointer",
"(",
"e",
")",
",",
"ex",
"=",
"pointer",
".",
"x",
"-",
"offset",
".",
"left",
",",
"ey",
"=",
"pointer",
".",
"y",
"-",
"offset",
".",
"top",
",",
"xpoints",
",",
"lines",
";",
"for",
"(",
"var",
"i",
"in",
"this",
".",
"oCoords",
")",
"{",
"if",
"(",
"i",
"===",
"'mtr'",
"&&",
"!",
"this",
".",
"hasRotatingPoint",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"this",
".",
"lockUniScaling",
"&&",
"(",
"i",
"===",
"'mt'",
"||",
"i",
"===",
"'mr'",
"||",
"i",
"===",
"'mb'",
"||",
"i",
"===",
"'ml'",
")",
")",
"{",
"continue",
";",
"}",
"lines",
"=",
"this",
".",
"_getImageLines",
"(",
"this",
".",
"oCoords",
"[",
"i",
"]",
".",
"corner",
",",
"i",
")",
";",
"// debugging",
"// canvas.contextTop.fillRect(lines.bottomline.d.x, lines.bottomline.d.y, 2, 2);",
"// canvas.contextTop.fillRect(lines.bottomline.o.x, lines.bottomline.o.y, 2, 2);",
"// canvas.contextTop.fillRect(lines.leftline.d.x, lines.leftline.d.y, 2, 2);",
"// canvas.contextTop.fillRect(lines.leftline.o.x, lines.leftline.o.y, 2, 2);",
"// canvas.contextTop.fillRect(lines.topline.d.x, lines.topline.d.y, 2, 2);",
"// canvas.contextTop.fillRect(lines.topline.o.x, lines.topline.o.y, 2, 2);",
"// canvas.contextTop.fillRect(lines.rightline.d.x, lines.rightline.d.y, 2, 2);",
"// canvas.contextTop.fillRect(lines.rightline.o.x, lines.rightline.o.y, 2, 2);",
"xpoints",
"=",
"this",
".",
"_findCrossPoints",
"(",
"ex",
",",
"ey",
",",
"lines",
")",
";",
"if",
"(",
"xpoints",
"%",
"2",
"==",
"1",
"&&",
"xpoints",
"!=",
"0",
")",
"{",
"this",
".",
"__corner",
"=",
"i",
";",
"return",
"i",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Determines which one of the four corners has been clicked
@method _findTargetCorner
@private
@param e {Event} event object
@param offset {Object} canvas offset
@return {String|Boolean} corner code (tl, tr, bl, br, etc.), or false if nothing is found
|
[
"Determines",
"which",
"one",
"of",
"the",
"four",
"corners",
"has",
"been",
"clicked"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L8777-L8819
|
|
11,435
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(ex, ey, oCoords) {
var b1, b2, a1, a2, xi, yi,
xcount = 0,
iLine;
for (var lineKey in oCoords) {
iLine = oCoords[lineKey];
// optimisation 1: line below dot. no cross
if ((iLine.o.y < ey) && (iLine.d.y < ey)) {
continue;
}
// optimisation 2: line above dot. no cross
if ((iLine.o.y >= ey) && (iLine.d.y >= ey)) {
continue;
}
// optimisation 3: vertical line case
if ((iLine.o.x == iLine.d.x) && (iLine.o.x >= ex)) {
xi = iLine.o.x;
yi = ey;
}
// calculate the intersection point
else {
b1 = 0;
b2 = (iLine.d.y-iLine.o.y)/(iLine.d.x-iLine.o.x);
a1 = ey-b1*ex;
a2 = iLine.o.y-b2*iLine.o.x;
xi = - (a1-a2)/(b1-b2);
yi = a1+b1*xi;
}
// dont count xi < ex cases
if (xi >= ex) {
xcount += 1;
}
// optimisation 4: specific for square images
if (xcount == 2) {
break;
}
}
return xcount;
}
|
javascript
|
function(ex, ey, oCoords) {
var b1, b2, a1, a2, xi, yi,
xcount = 0,
iLine;
for (var lineKey in oCoords) {
iLine = oCoords[lineKey];
// optimisation 1: line below dot. no cross
if ((iLine.o.y < ey) && (iLine.d.y < ey)) {
continue;
}
// optimisation 2: line above dot. no cross
if ((iLine.o.y >= ey) && (iLine.d.y >= ey)) {
continue;
}
// optimisation 3: vertical line case
if ((iLine.o.x == iLine.d.x) && (iLine.o.x >= ex)) {
xi = iLine.o.x;
yi = ey;
}
// calculate the intersection point
else {
b1 = 0;
b2 = (iLine.d.y-iLine.o.y)/(iLine.d.x-iLine.o.x);
a1 = ey-b1*ex;
a2 = iLine.o.y-b2*iLine.o.x;
xi = - (a1-a2)/(b1-b2);
yi = a1+b1*xi;
}
// dont count xi < ex cases
if (xi >= ex) {
xcount += 1;
}
// optimisation 4: specific for square images
if (xcount == 2) {
break;
}
}
return xcount;
}
|
[
"function",
"(",
"ex",
",",
"ey",
",",
"oCoords",
")",
"{",
"var",
"b1",
",",
"b2",
",",
"a1",
",",
"a2",
",",
"xi",
",",
"yi",
",",
"xcount",
"=",
"0",
",",
"iLine",
";",
"for",
"(",
"var",
"lineKey",
"in",
"oCoords",
")",
"{",
"iLine",
"=",
"oCoords",
"[",
"lineKey",
"]",
";",
"// optimisation 1: line below dot. no cross",
"if",
"(",
"(",
"iLine",
".",
"o",
".",
"y",
"<",
"ey",
")",
"&&",
"(",
"iLine",
".",
"d",
".",
"y",
"<",
"ey",
")",
")",
"{",
"continue",
";",
"}",
"// optimisation 2: line above dot. no cross",
"if",
"(",
"(",
"iLine",
".",
"o",
".",
"y",
">=",
"ey",
")",
"&&",
"(",
"iLine",
".",
"d",
".",
"y",
">=",
"ey",
")",
")",
"{",
"continue",
";",
"}",
"// optimisation 3: vertical line case",
"if",
"(",
"(",
"iLine",
".",
"o",
".",
"x",
"==",
"iLine",
".",
"d",
".",
"x",
")",
"&&",
"(",
"iLine",
".",
"o",
".",
"x",
">=",
"ex",
")",
")",
"{",
"xi",
"=",
"iLine",
".",
"o",
".",
"x",
";",
"yi",
"=",
"ey",
";",
"}",
"// calculate the intersection point",
"else",
"{",
"b1",
"=",
"0",
";",
"b2",
"=",
"(",
"iLine",
".",
"d",
".",
"y",
"-",
"iLine",
".",
"o",
".",
"y",
")",
"/",
"(",
"iLine",
".",
"d",
".",
"x",
"-",
"iLine",
".",
"o",
".",
"x",
")",
";",
"a1",
"=",
"ey",
"-",
"b1",
"*",
"ex",
";",
"a2",
"=",
"iLine",
".",
"o",
".",
"y",
"-",
"b2",
"*",
"iLine",
".",
"o",
".",
"x",
";",
"xi",
"=",
"-",
"(",
"a1",
"-",
"a2",
")",
"/",
"(",
"b1",
"-",
"b2",
")",
";",
"yi",
"=",
"a1",
"+",
"b1",
"*",
"xi",
";",
"}",
"// dont count xi < ex cases",
"if",
"(",
"xi",
">=",
"ex",
")",
"{",
"xcount",
"+=",
"1",
";",
"}",
"// optimisation 4: specific for square images",
"if",
"(",
"xcount",
"==",
"2",
")",
"{",
"break",
";",
"}",
"}",
"return",
"xcount",
";",
"}"
] |
Helper method to determine how many cross points are between the 4 image edges
and the horizontal line determined by the position of our mouse when clicked on canvas
@method _findCrossPoints
@private
@param ex {Number} x coordinate of the mouse
@param ey {Number} y coordinate of the mouse
@param oCoords {Object} Coordinates of the image being evaluated
|
[
"Helper",
"method",
"to",
"determine",
"how",
"many",
"cross",
"points",
"are",
"between",
"the",
"4",
"image",
"edges",
"and",
"the",
"horizontal",
"line",
"determined",
"by",
"the",
"position",
"of",
"our",
"mouse",
"when",
"clicked",
"on",
"canvas"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L8830-L8870
|
|
11,436
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(oCoords, i) {
return {
topline: {
o: oCoords.tl,
d: oCoords.tr
},
rightline: {
o: oCoords.tr,
d: oCoords.br
},
bottomline: {
o: oCoords.br,
d: oCoords.bl
},
leftline: {
o: oCoords.bl,
d: oCoords.tl
}
}
}
|
javascript
|
function(oCoords, i) {
return {
topline: {
o: oCoords.tl,
d: oCoords.tr
},
rightline: {
o: oCoords.tr,
d: oCoords.br
},
bottomline: {
o: oCoords.br,
d: oCoords.bl
},
leftline: {
o: oCoords.bl,
d: oCoords.tl
}
}
}
|
[
"function",
"(",
"oCoords",
",",
"i",
")",
"{",
"return",
"{",
"topline",
":",
"{",
"o",
":",
"oCoords",
".",
"tl",
",",
"d",
":",
"oCoords",
".",
"tr",
"}",
",",
"rightline",
":",
"{",
"o",
":",
"oCoords",
".",
"tr",
",",
"d",
":",
"oCoords",
".",
"br",
"}",
",",
"bottomline",
":",
"{",
"o",
":",
"oCoords",
".",
"br",
",",
"d",
":",
"oCoords",
".",
"bl",
"}",
",",
"leftline",
":",
"{",
"o",
":",
"oCoords",
".",
"bl",
",",
"d",
":",
"oCoords",
".",
"tl",
"}",
"}",
"}"
] |
Method that returns an object with the image lines in it given the coordinates of the corners
@method _getImageLines
@private
@param oCoords {Object} coordinates of the image corners
|
[
"Method",
"that",
"returns",
"an",
"object",
"with",
"the",
"image",
"lines",
"in",
"it",
"given",
"the",
"coordinates",
"of",
"the",
"corners"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L8878-L8897
|
|
11,437
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(parsedAttributes) {
if (parsedAttributes.left) {
this.set('left', parsedAttributes.left + this.getWidth() / 2);
}
this.set('x', parsedAttributes.left || 0);
if (parsedAttributes.top) {
this.set('top', parsedAttributes.top + this.getHeight() / 2);
}
this.set('y', parsedAttributes.top || 0);
return this;
}
|
javascript
|
function(parsedAttributes) {
if (parsedAttributes.left) {
this.set('left', parsedAttributes.left + this.getWidth() / 2);
}
this.set('x', parsedAttributes.left || 0);
if (parsedAttributes.top) {
this.set('top', parsedAttributes.top + this.getHeight() / 2);
}
this.set('y', parsedAttributes.top || 0);
return this;
}
|
[
"function",
"(",
"parsedAttributes",
")",
"{",
"if",
"(",
"parsedAttributes",
".",
"left",
")",
"{",
"this",
".",
"set",
"(",
"'left'",
",",
"parsedAttributes",
".",
"left",
"+",
"this",
".",
"getWidth",
"(",
")",
"/",
"2",
")",
";",
"}",
"this",
".",
"set",
"(",
"'x'",
",",
"parsedAttributes",
".",
"left",
"||",
"0",
")",
";",
"if",
"(",
"parsedAttributes",
".",
"top",
")",
"{",
"this",
".",
"set",
"(",
"'top'",
",",
"parsedAttributes",
".",
"top",
"+",
"this",
".",
"getHeight",
"(",
")",
"/",
"2",
")",
";",
"}",
"this",
".",
"set",
"(",
"'y'",
",",
"parsedAttributes",
".",
"top",
"||",
"0",
")",
";",
"return",
"this",
";",
"}"
] |
since our coordinate system differs from that of SVG
|
[
"since",
"our",
"coordinate",
"system",
"differs",
"from",
"that",
"of",
"SVG"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L10067-L10077
|
|
11,438
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(ctx, noTransform) {
ctx.save();
var m = this.transformMatrix;
if (m) {
ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
}
if (!noTransform) {
this.transform(ctx);
}
// ctx.globalCompositeOperation = this.fillRule;
if (this.overlayFill) {
ctx.fillStyle = this.overlayFill;
}
else if (this.fill) {
ctx.fillStyle = this.fill.toLiveGradient
? this.fill.toLiveGradient(ctx)
: this.fill;
}
if (this.stroke) {
ctx.strokeStyle = this.stroke;
}
ctx.beginPath();
this._render(ctx);
if (this.fill) {
ctx.fill();
}
if (this.stroke) {
ctx.strokeStyle = this.stroke;
ctx.lineWidth = this.strokeWidth;
ctx.lineCap = ctx.lineJoin = 'round';
ctx.stroke();
}
if (!noTransform && this.active) {
this.drawBorders(ctx);
this.hideCorners || this.drawCorners(ctx);
}
ctx.restore();
}
|
javascript
|
function(ctx, noTransform) {
ctx.save();
var m = this.transformMatrix;
if (m) {
ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
}
if (!noTransform) {
this.transform(ctx);
}
// ctx.globalCompositeOperation = this.fillRule;
if (this.overlayFill) {
ctx.fillStyle = this.overlayFill;
}
else if (this.fill) {
ctx.fillStyle = this.fill.toLiveGradient
? this.fill.toLiveGradient(ctx)
: this.fill;
}
if (this.stroke) {
ctx.strokeStyle = this.stroke;
}
ctx.beginPath();
this._render(ctx);
if (this.fill) {
ctx.fill();
}
if (this.stroke) {
ctx.strokeStyle = this.stroke;
ctx.lineWidth = this.strokeWidth;
ctx.lineCap = ctx.lineJoin = 'round';
ctx.stroke();
}
if (!noTransform && this.active) {
this.drawBorders(ctx);
this.hideCorners || this.drawCorners(ctx);
}
ctx.restore();
}
|
[
"function",
"(",
"ctx",
",",
"noTransform",
")",
"{",
"ctx",
".",
"save",
"(",
")",
";",
"var",
"m",
"=",
"this",
".",
"transformMatrix",
";",
"if",
"(",
"m",
")",
"{",
"ctx",
".",
"transform",
"(",
"m",
"[",
"0",
"]",
",",
"m",
"[",
"1",
"]",
",",
"m",
"[",
"2",
"]",
",",
"m",
"[",
"3",
"]",
",",
"m",
"[",
"4",
"]",
",",
"m",
"[",
"5",
"]",
")",
";",
"}",
"if",
"(",
"!",
"noTransform",
")",
"{",
"this",
".",
"transform",
"(",
"ctx",
")",
";",
"}",
"// ctx.globalCompositeOperation = this.fillRule;",
"if",
"(",
"this",
".",
"overlayFill",
")",
"{",
"ctx",
".",
"fillStyle",
"=",
"this",
".",
"overlayFill",
";",
"}",
"else",
"if",
"(",
"this",
".",
"fill",
")",
"{",
"ctx",
".",
"fillStyle",
"=",
"this",
".",
"fill",
".",
"toLiveGradient",
"?",
"this",
".",
"fill",
".",
"toLiveGradient",
"(",
"ctx",
")",
":",
"this",
".",
"fill",
";",
"}",
"if",
"(",
"this",
".",
"stroke",
")",
"{",
"ctx",
".",
"strokeStyle",
"=",
"this",
".",
"stroke",
";",
"}",
"ctx",
".",
"beginPath",
"(",
")",
";",
"this",
".",
"_render",
"(",
"ctx",
")",
";",
"if",
"(",
"this",
".",
"fill",
")",
"{",
"ctx",
".",
"fill",
"(",
")",
";",
"}",
"if",
"(",
"this",
".",
"stroke",
")",
"{",
"ctx",
".",
"strokeStyle",
"=",
"this",
".",
"stroke",
";",
"ctx",
".",
"lineWidth",
"=",
"this",
".",
"strokeWidth",
";",
"ctx",
".",
"lineCap",
"=",
"ctx",
".",
"lineJoin",
"=",
"'round'",
";",
"ctx",
".",
"stroke",
"(",
")",
";",
"}",
"if",
"(",
"!",
"noTransform",
"&&",
"this",
".",
"active",
")",
"{",
"this",
".",
"drawBorders",
"(",
"ctx",
")",
";",
"this",
".",
"hideCorners",
"||",
"this",
".",
"drawCorners",
"(",
"ctx",
")",
";",
"}",
"ctx",
".",
"restore",
"(",
")",
";",
"}"
] |
Renders path on a specified context
@method render
@param {CanvasRenderingContext2D} ctx context to render path on
@param {Boolean} noTransform When true, context is not transformed
|
[
"Renders",
"path",
"on",
"a",
"specified",
"context"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L10995-L11036
|
|
11,439
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(ctx) {
ctx.save();
var m = this.transformMatrix;
if (m) {
ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
}
this.transform(ctx);
for (var i = 0, l = this.paths.length; i < l; ++i) {
this.paths[i].render(ctx, true);
}
if (this.active) {
this.drawBorders(ctx);
this.hideCorners || this.drawCorners(ctx);
}
ctx.restore();
}
|
javascript
|
function(ctx) {
ctx.save();
var m = this.transformMatrix;
if (m) {
ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
}
this.transform(ctx);
for (var i = 0, l = this.paths.length; i < l; ++i) {
this.paths[i].render(ctx, true);
}
if (this.active) {
this.drawBorders(ctx);
this.hideCorners || this.drawCorners(ctx);
}
ctx.restore();
}
|
[
"function",
"(",
"ctx",
")",
"{",
"ctx",
".",
"save",
"(",
")",
";",
"var",
"m",
"=",
"this",
".",
"transformMatrix",
";",
"if",
"(",
"m",
")",
"{",
"ctx",
".",
"transform",
"(",
"m",
"[",
"0",
"]",
",",
"m",
"[",
"1",
"]",
",",
"m",
"[",
"2",
"]",
",",
"m",
"[",
"3",
"]",
",",
"m",
"[",
"4",
"]",
",",
"m",
"[",
"5",
"]",
")",
";",
"}",
"this",
".",
"transform",
"(",
"ctx",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"this",
".",
"paths",
".",
"length",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"this",
".",
"paths",
"[",
"i",
"]",
".",
"render",
"(",
"ctx",
",",
"true",
")",
";",
"}",
"if",
"(",
"this",
".",
"active",
")",
"{",
"this",
".",
"drawBorders",
"(",
"ctx",
")",
";",
"this",
".",
"hideCorners",
"||",
"this",
".",
"drawCorners",
"(",
"ctx",
")",
";",
"}",
"ctx",
".",
"restore",
"(",
")",
";",
"}"
] |
Renders this group on a specified context
@method render
@param {CanvasRenderingContext2D} ctx Context to render this instance on
|
[
"Renders",
"this",
"group",
"on",
"a",
"specified",
"context"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L11321-L11338
|
|
11,440
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(prop, value) {
if ((prop === 'fill' || prop === 'overlayFill') && value && this.isSameColor()) {
var i = this.paths.length;
while (i--) {
this.paths[i]._set(prop, value);
}
}
return this.callSuper('_set', prop, value);
}
|
javascript
|
function(prop, value) {
if ((prop === 'fill' || prop === 'overlayFill') && value && this.isSameColor()) {
var i = this.paths.length;
while (i--) {
this.paths[i]._set(prop, value);
}
}
return this.callSuper('_set', prop, value);
}
|
[
"function",
"(",
"prop",
",",
"value",
")",
"{",
"if",
"(",
"(",
"prop",
"===",
"'fill'",
"||",
"prop",
"===",
"'overlayFill'",
")",
"&&",
"value",
"&&",
"this",
".",
"isSameColor",
"(",
")",
")",
"{",
"var",
"i",
"=",
"this",
".",
"paths",
".",
"length",
";",
"while",
"(",
"i",
"--",
")",
"{",
"this",
".",
"paths",
"[",
"i",
"]",
".",
"_set",
"(",
"prop",
",",
"value",
")",
";",
"}",
"}",
"return",
"this",
".",
"callSuper",
"(",
"'_set'",
",",
"prop",
",",
"value",
")",
";",
"}"
] |
Sets certain property to a certain value
@method _set
@param {String} prop
@param {Any} value
@return {fabric.PathGroup} thisArg
|
[
"Sets",
"certain",
"property",
"to",
"a",
"certain",
"value"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L11347-L11357
|
|
11,441
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function() {
return this.paths.reduce(function(total, path) {
return total + ((path && path.complexity) ? path.complexity() : 0);
}, 0);
}
|
javascript
|
function() {
return this.paths.reduce(function(total, path) {
return total + ((path && path.complexity) ? path.complexity() : 0);
}, 0);
}
|
[
"function",
"(",
")",
"{",
"return",
"this",
".",
"paths",
".",
"reduce",
"(",
"function",
"(",
"total",
",",
"path",
")",
"{",
"return",
"total",
"+",
"(",
"(",
"path",
"&&",
"path",
".",
"complexity",
")",
"?",
"path",
".",
"complexity",
"(",
")",
":",
"0",
")",
";",
"}",
",",
"0",
")",
";",
"}"
] |
Returns number representation of object's complexity
@method complexity
@return {Number} complexity
|
[
"Returns",
"number",
"representation",
"of",
"object",
"s",
"complexity"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L11435-L11439
|
|
11,442
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(object) {
this._restoreObjectsState();
removeFromArray(this.objects, object);
object.setActive(false);
this._calcBounds();
this._updateObjectsCoords();
return this;
}
|
javascript
|
function(object) {
this._restoreObjectsState();
removeFromArray(this.objects, object);
object.setActive(false);
this._calcBounds();
this._updateObjectsCoords();
return this;
}
|
[
"function",
"(",
"object",
")",
"{",
"this",
".",
"_restoreObjectsState",
"(",
")",
";",
"removeFromArray",
"(",
"this",
".",
"objects",
",",
"object",
")",
";",
"object",
".",
"setActive",
"(",
"false",
")",
";",
"this",
".",
"_calcBounds",
"(",
")",
";",
"this",
".",
"_updateObjectsCoords",
"(",
")",
";",
"return",
"this",
";",
"}"
] |
Removes an object from a group; Then recalculates group's dimension, position.
@method removeWithUpdate
@param {Object} object
@return {fabric.Group} thisArg
@chainable
|
[
"Removes",
"an",
"object",
"from",
"a",
"group",
";",
"Then",
"recalculates",
"group",
"s",
"dimension",
"position",
"."
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L11612-L11619
|
|
11,443
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(ctx, noTransform) {
ctx.save();
this.transform(ctx);
var groupScaleFactor = Math.max(this.scaleX, this.scaleY);
for (var i = 0, len = this.objects.length, object; object = this.objects[i]; i++) {
var originalScaleFactor = object.borderScaleFactor;
object.borderScaleFactor = groupScaleFactor;
object.render(ctx);
object.borderScaleFactor = originalScaleFactor;
}
if (!noTransform && this.active) {
this.drawBorders(ctx);
this.hideCorners || this.drawCorners(ctx);
}
ctx.restore();
this.setCoords();
}
|
javascript
|
function(ctx, noTransform) {
ctx.save();
this.transform(ctx);
var groupScaleFactor = Math.max(this.scaleX, this.scaleY);
for (var i = 0, len = this.objects.length, object; object = this.objects[i]; i++) {
var originalScaleFactor = object.borderScaleFactor;
object.borderScaleFactor = groupScaleFactor;
object.render(ctx);
object.borderScaleFactor = originalScaleFactor;
}
if (!noTransform && this.active) {
this.drawBorders(ctx);
this.hideCorners || this.drawCorners(ctx);
}
ctx.restore();
this.setCoords();
}
|
[
"function",
"(",
"ctx",
",",
"noTransform",
")",
"{",
"ctx",
".",
"save",
"(",
")",
";",
"this",
".",
"transform",
"(",
"ctx",
")",
";",
"var",
"groupScaleFactor",
"=",
"Math",
".",
"max",
"(",
"this",
".",
"scaleX",
",",
"this",
".",
"scaleY",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"this",
".",
"objects",
".",
"length",
",",
"object",
";",
"object",
"=",
"this",
".",
"objects",
"[",
"i",
"]",
";",
"i",
"++",
")",
"{",
"var",
"originalScaleFactor",
"=",
"object",
".",
"borderScaleFactor",
";",
"object",
".",
"borderScaleFactor",
"=",
"groupScaleFactor",
";",
"object",
".",
"render",
"(",
"ctx",
")",
";",
"object",
".",
"borderScaleFactor",
"=",
"originalScaleFactor",
";",
"}",
"if",
"(",
"!",
"noTransform",
"&&",
"this",
".",
"active",
")",
"{",
"this",
".",
"drawBorders",
"(",
"ctx",
")",
";",
"this",
".",
"hideCorners",
"||",
"this",
".",
"drawCorners",
"(",
"ctx",
")",
";",
"}",
"ctx",
".",
"restore",
"(",
")",
";",
"this",
".",
"setCoords",
"(",
")",
";",
"}"
] |
Renders instance on a given context
@method render
@param {CanvasRenderingContext2D} ctx context to render instance on
|
[
"Renders",
"instance",
"on",
"a",
"given",
"context"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L11695-L11713
|
|
11,444
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function() {
return this.getObjects().reduce(function(total, object) {
total += (typeof object.complexity == 'function') ? object.complexity() : 0;
return total;
}, 0);
}
|
javascript
|
function() {
return this.getObjects().reduce(function(total, object) {
total += (typeof object.complexity == 'function') ? object.complexity() : 0;
return total;
}, 0);
}
|
[
"function",
"(",
")",
"{",
"return",
"this",
".",
"getObjects",
"(",
")",
".",
"reduce",
"(",
"function",
"(",
"total",
",",
"object",
")",
"{",
"total",
"+=",
"(",
"typeof",
"object",
".",
"complexity",
"==",
"'function'",
")",
"?",
"object",
".",
"complexity",
"(",
")",
":",
"0",
";",
"return",
"total",
";",
"}",
",",
"0",
")",
";",
"}"
] |
Returns complexity of an instance
@method complexity
@return {Number} complexity
|
[
"Returns",
"complexity",
"of",
"an",
"instance"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L11730-L11735
|
|
11,445
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(object) {
var groupLeft = this.get('left'),
groupTop = this.get('top'),
groupAngle = this.getAngle() * (Math.PI / 180),
objectLeft = object.get('originalLeft'),
objectTop = object.get('originalTop'),
rotatedTop = Math.cos(groupAngle) * object.get('top') + Math.sin(groupAngle) * object.get('left'),
rotatedLeft = -Math.sin(groupAngle) * object.get('top') + Math.cos(groupAngle) * object.get('left');
object.setAngle(object.getAngle() + this.getAngle());
object.set('left', groupLeft + rotatedLeft * this.get('scaleX'));
object.set('top', groupTop + rotatedTop * this.get('scaleY'));
object.set('scaleX', object.get('scaleX') * this.get('scaleX'));
object.set('scaleY', object.get('scaleY') * this.get('scaleY'));
object.setCoords();
object.hideCorners = false;
object.setActive(false);
object.setCoords();
return this;
}
|
javascript
|
function(object) {
var groupLeft = this.get('left'),
groupTop = this.get('top'),
groupAngle = this.getAngle() * (Math.PI / 180),
objectLeft = object.get('originalLeft'),
objectTop = object.get('originalTop'),
rotatedTop = Math.cos(groupAngle) * object.get('top') + Math.sin(groupAngle) * object.get('left'),
rotatedLeft = -Math.sin(groupAngle) * object.get('top') + Math.cos(groupAngle) * object.get('left');
object.setAngle(object.getAngle() + this.getAngle());
object.set('left', groupLeft + rotatedLeft * this.get('scaleX'));
object.set('top', groupTop + rotatedTop * this.get('scaleY'));
object.set('scaleX', object.get('scaleX') * this.get('scaleX'));
object.set('scaleY', object.get('scaleY') * this.get('scaleY'));
object.setCoords();
object.hideCorners = false;
object.setActive(false);
object.setCoords();
return this;
}
|
[
"function",
"(",
"object",
")",
"{",
"var",
"groupLeft",
"=",
"this",
".",
"get",
"(",
"'left'",
")",
",",
"groupTop",
"=",
"this",
".",
"get",
"(",
"'top'",
")",
",",
"groupAngle",
"=",
"this",
".",
"getAngle",
"(",
")",
"*",
"(",
"Math",
".",
"PI",
"/",
"180",
")",
",",
"objectLeft",
"=",
"object",
".",
"get",
"(",
"'originalLeft'",
")",
",",
"objectTop",
"=",
"object",
".",
"get",
"(",
"'originalTop'",
")",
",",
"rotatedTop",
"=",
"Math",
".",
"cos",
"(",
"groupAngle",
")",
"*",
"object",
".",
"get",
"(",
"'top'",
")",
"+",
"Math",
".",
"sin",
"(",
"groupAngle",
")",
"*",
"object",
".",
"get",
"(",
"'left'",
")",
",",
"rotatedLeft",
"=",
"-",
"Math",
".",
"sin",
"(",
"groupAngle",
")",
"*",
"object",
".",
"get",
"(",
"'top'",
")",
"+",
"Math",
".",
"cos",
"(",
"groupAngle",
")",
"*",
"object",
".",
"get",
"(",
"'left'",
")",
";",
"object",
".",
"setAngle",
"(",
"object",
".",
"getAngle",
"(",
")",
"+",
"this",
".",
"getAngle",
"(",
")",
")",
";",
"object",
".",
"set",
"(",
"'left'",
",",
"groupLeft",
"+",
"rotatedLeft",
"*",
"this",
".",
"get",
"(",
"'scaleX'",
")",
")",
";",
"object",
".",
"set",
"(",
"'top'",
",",
"groupTop",
"+",
"rotatedTop",
"*",
"this",
".",
"get",
"(",
"'scaleY'",
")",
")",
";",
"object",
".",
"set",
"(",
"'scaleX'",
",",
"object",
".",
"get",
"(",
"'scaleX'",
")",
"*",
"this",
".",
"get",
"(",
"'scaleX'",
")",
")",
";",
"object",
".",
"set",
"(",
"'scaleY'",
",",
"object",
".",
"get",
"(",
"'scaleY'",
")",
"*",
"this",
".",
"get",
"(",
"'scaleY'",
")",
")",
";",
"object",
".",
"setCoords",
"(",
")",
";",
"object",
".",
"hideCorners",
"=",
"false",
";",
"object",
".",
"setActive",
"(",
"false",
")",
";",
"object",
".",
"setCoords",
"(",
")",
";",
"return",
"this",
";",
"}"
] |
Restores original state of a specified object in group
@private
@method _restoreObjectState
@param {fabric.Object} object
@return {fabric.Group} thisArg
|
[
"Restores",
"original",
"state",
"of",
"a",
"specified",
"object",
"in",
"group"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L11756-L11780
|
|
11,446
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(point) {
var halfWidth = this.get('width') / 2,
halfHeight = this.get('height') / 2,
centerX = this.get('left'),
centerY = this.get('top');
return centerX - halfWidth < point.x &&
centerX + halfWidth > point.x &&
centerY - halfHeight < point.y &&
centerY + halfHeight > point.y;
}
|
javascript
|
function(point) {
var halfWidth = this.get('width') / 2,
halfHeight = this.get('height') / 2,
centerX = this.get('left'),
centerY = this.get('top');
return centerX - halfWidth < point.x &&
centerX + halfWidth > point.x &&
centerY - halfHeight < point.y &&
centerY + halfHeight > point.y;
}
|
[
"function",
"(",
"point",
")",
"{",
"var",
"halfWidth",
"=",
"this",
".",
"get",
"(",
"'width'",
")",
"/",
"2",
",",
"halfHeight",
"=",
"this",
".",
"get",
"(",
"'height'",
")",
"/",
"2",
",",
"centerX",
"=",
"this",
".",
"get",
"(",
"'left'",
")",
",",
"centerY",
"=",
"this",
".",
"get",
"(",
"'top'",
")",
";",
"return",
"centerX",
"-",
"halfWidth",
"<",
"point",
".",
"x",
"&&",
"centerX",
"+",
"halfWidth",
">",
"point",
".",
"x",
"&&",
"centerY",
"-",
"halfHeight",
"<",
"point",
".",
"y",
"&&",
"centerY",
"+",
"halfHeight",
">",
"point",
".",
"y",
";",
"}"
] |
Checks if point is contained within the group
@method containsPoint
@param {fabric.Point} point point with `x` and `y` properties
@return {Boolean} true if point is contained within group
|
[
"Checks",
"if",
"point",
"is",
"contained",
"within",
"the",
"group"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L11915-L11926
|
|
11,447
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(ctx, noTransform) {
ctx.save();
var m = this.transformMatrix;
this._resetWidthHeight();
if (this.group) {
ctx.translate(-this.group.width/2 + this.width/2, -this.group.height/2 + this.height/2);
}
if (m) {
ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
}
if (!noTransform) {
this.transform(ctx);
}
this._render(ctx);
if (this.active && !noTransform) {
this.drawBorders(ctx);
this.hideCorners || this.drawCorners(ctx);
}
ctx.restore();
}
|
javascript
|
function(ctx, noTransform) {
ctx.save();
var m = this.transformMatrix;
this._resetWidthHeight();
if (this.group) {
ctx.translate(-this.group.width/2 + this.width/2, -this.group.height/2 + this.height/2);
}
if (m) {
ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
}
if (!noTransform) {
this.transform(ctx);
}
this._render(ctx);
if (this.active && !noTransform) {
this.drawBorders(ctx);
this.hideCorners || this.drawCorners(ctx);
}
ctx.restore();
}
|
[
"function",
"(",
"ctx",
",",
"noTransform",
")",
"{",
"ctx",
".",
"save",
"(",
")",
";",
"var",
"m",
"=",
"this",
".",
"transformMatrix",
";",
"this",
".",
"_resetWidthHeight",
"(",
")",
";",
"if",
"(",
"this",
".",
"group",
")",
"{",
"ctx",
".",
"translate",
"(",
"-",
"this",
".",
"group",
".",
"width",
"/",
"2",
"+",
"this",
".",
"width",
"/",
"2",
",",
"-",
"this",
".",
"group",
".",
"height",
"/",
"2",
"+",
"this",
".",
"height",
"/",
"2",
")",
";",
"}",
"if",
"(",
"m",
")",
"{",
"ctx",
".",
"transform",
"(",
"m",
"[",
"0",
"]",
",",
"m",
"[",
"1",
"]",
",",
"m",
"[",
"2",
"]",
",",
"m",
"[",
"3",
"]",
",",
"m",
"[",
"4",
"]",
",",
"m",
"[",
"5",
"]",
")",
";",
"}",
"if",
"(",
"!",
"noTransform",
")",
"{",
"this",
".",
"transform",
"(",
"ctx",
")",
";",
"}",
"this",
".",
"_render",
"(",
"ctx",
")",
";",
"if",
"(",
"this",
".",
"active",
"&&",
"!",
"noTransform",
")",
"{",
"this",
".",
"drawBorders",
"(",
"ctx",
")",
";",
"this",
".",
"hideCorners",
"||",
"this",
".",
"drawCorners",
"(",
"ctx",
")",
";",
"}",
"ctx",
".",
"restore",
"(",
")",
";",
"}"
] |
Renders image on a specified context
@method render
@param {CanvasRenderingContext2D} ctx Context to render on
|
[
"Renders",
"image",
"on",
"a",
"specified",
"context"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L12106-L12125
|
|
11,448
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(element) {
this.setElement(fabric.util.getById(element));
fabric.util.addClass(this.getElement(), fabric.Image.CSS_CANVAS);
}
|
javascript
|
function(element) {
this.setElement(fabric.util.getById(element));
fabric.util.addClass(this.getElement(), fabric.Image.CSS_CANVAS);
}
|
[
"function",
"(",
"element",
")",
"{",
"this",
".",
"setElement",
"(",
"fabric",
".",
"util",
".",
"getById",
"(",
"element",
")",
")",
";",
"fabric",
".",
"util",
".",
"addClass",
"(",
"this",
".",
"getElement",
"(",
")",
",",
"fabric",
".",
"Image",
".",
"CSS_CANVAS",
")",
";",
"}"
] |
The Image class's initialization method. This method is automatically
called by the constructor.
@method _initElement
@param {HTMLImageElement|String} el The element representing the image
|
[
"The",
"Image",
"class",
"s",
"initialization",
"method",
".",
"This",
"method",
"is",
"automatically",
"called",
"by",
"the",
"constructor",
"."
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L12283-L12286
|
|
11,449
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function() {
var canvasEl = fabric.document.createElement('canvas');
if (!canvasEl.getContext && typeof G_vmlCanvasManager != 'undefined') {
G_vmlCanvasManager.initElement(canvasEl);
}
this._render(canvasEl.getContext('2d'));
}
|
javascript
|
function() {
var canvasEl = fabric.document.createElement('canvas');
if (!canvasEl.getContext && typeof G_vmlCanvasManager != 'undefined') {
G_vmlCanvasManager.initElement(canvasEl);
}
this._render(canvasEl.getContext('2d'));
}
|
[
"function",
"(",
")",
"{",
"var",
"canvasEl",
"=",
"fabric",
".",
"document",
".",
"createElement",
"(",
"'canvas'",
")",
";",
"if",
"(",
"!",
"canvasEl",
".",
"getContext",
"&&",
"typeof",
"G_vmlCanvasManager",
"!=",
"'undefined'",
")",
"{",
"G_vmlCanvasManager",
".",
"initElement",
"(",
"canvasEl",
")",
";",
"}",
"this",
".",
"_render",
"(",
"canvasEl",
".",
"getContext",
"(",
"'2d'",
")",
")",
";",
"}"
] |
Renders text object on offscreen canvas, so that it would get dimensions
@private
@method _initDimensions
|
[
"Renders",
"text",
"object",
"on",
"offscreen",
"canvas",
"so",
"that",
"it",
"would",
"get",
"dimensions"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L13168-L13176
|
|
11,450
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(ctx, noTransform) {
ctx.save();
this._render(ctx);
if (!noTransform && this.active) {
this.drawBorders(ctx);
this.hideCorners || this.drawCorners(ctx);
}
ctx.restore();
}
|
javascript
|
function(ctx, noTransform) {
ctx.save();
this._render(ctx);
if (!noTransform && this.active) {
this.drawBorders(ctx);
this.hideCorners || this.drawCorners(ctx);
}
ctx.restore();
}
|
[
"function",
"(",
"ctx",
",",
"noTransform",
")",
"{",
"ctx",
".",
"save",
"(",
")",
";",
"this",
".",
"_render",
"(",
"ctx",
")",
";",
"if",
"(",
"!",
"noTransform",
"&&",
"this",
".",
"active",
")",
"{",
"this",
".",
"drawBorders",
"(",
"ctx",
")",
";",
"this",
".",
"hideCorners",
"||",
"this",
".",
"drawCorners",
"(",
"ctx",
")",
";",
"}",
"ctx",
".",
"restore",
"(",
")",
";",
"}"
] |
Renders text instance on a specified context
@method render
@param ctx {CanvasRenderingContext2D} context to render on
|
[
"Renders",
"text",
"instance",
"on",
"a",
"specified",
"context"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L13554-L13562
|
|
11,451
|
MrSwitch/hello.js
|
demos/Collage/fabric.js
|
function(name, value) {
if (name === 'fontFamily' && this.path) {
this.path = this.path.replace(/(.*?)([^\/]*)(\.font\.js)/, '$1' + value + '$3');
}
this.callSuper('_set', name, value);
}
|
javascript
|
function(name, value) {
if (name === 'fontFamily' && this.path) {
this.path = this.path.replace(/(.*?)([^\/]*)(\.font\.js)/, '$1' + value + '$3');
}
this.callSuper('_set', name, value);
}
|
[
"function",
"(",
"name",
",",
"value",
")",
"{",
"if",
"(",
"name",
"===",
"'fontFamily'",
"&&",
"this",
".",
"path",
")",
"{",
"this",
".",
"path",
"=",
"this",
".",
"path",
".",
"replace",
"(",
"/",
"(.*?)([^\\/]*)(\\.font\\.js)",
"/",
",",
"'$1'",
"+",
"value",
"+",
"'$3'",
")",
";",
"}",
"this",
".",
"callSuper",
"(",
"'_set'",
",",
"name",
",",
"value",
")",
";",
"}"
] |
Sets specified property to a specified value
@method set
@param {String} name
@param {Any} value
@return {fabric.Text} thisArg
@chainable
|
[
"Sets",
"specified",
"property",
"to",
"a",
"specified",
"value"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/Collage/fabric.js#L13776-L13781
|
|
11,452
|
MrSwitch/hello.js
|
assets/knockout/src/subscribables/subscribable.js
|
limitNotifySubscribers
|
function limitNotifySubscribers(value, event) {
if (!event || event === defaultEvent) {
this._limitChange(value);
} else if (event === 'beforeChange') {
this._limitBeforeChange(value);
} else {
this._origNotifySubscribers(value, event);
}
}
|
javascript
|
function limitNotifySubscribers(value, event) {
if (!event || event === defaultEvent) {
this._limitChange(value);
} else if (event === 'beforeChange') {
this._limitBeforeChange(value);
} else {
this._origNotifySubscribers(value, event);
}
}
|
[
"function",
"limitNotifySubscribers",
"(",
"value",
",",
"event",
")",
"{",
"if",
"(",
"!",
"event",
"||",
"event",
"===",
"defaultEvent",
")",
"{",
"this",
".",
"_limitChange",
"(",
"value",
")",
";",
"}",
"else",
"if",
"(",
"event",
"===",
"'beforeChange'",
")",
"{",
"this",
".",
"_limitBeforeChange",
"(",
"value",
")",
";",
"}",
"else",
"{",
"this",
".",
"_origNotifySubscribers",
"(",
"value",
",",
"event",
")",
";",
"}",
"}"
] |
Moved out of "limit" to avoid the extra closure
|
[
"Moved",
"out",
"of",
"limit",
"to",
"avoid",
"the",
"extra",
"closure"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/assets/knockout/src/subscribables/subscribable.js#L22-L30
|
11,453
|
MrSwitch/hello.js
|
assets/knockout/src/binding/bindingAttributeSyntax.js
|
makeAccessorsFromFunction
|
function makeAccessorsFromFunction(callback) {
return ko.utils.objectMap(ko.dependencyDetection.ignore(callback), function(value, key) {
return function() {
return callback()[key];
};
});
}
|
javascript
|
function makeAccessorsFromFunction(callback) {
return ko.utils.objectMap(ko.dependencyDetection.ignore(callback), function(value, key) {
return function() {
return callback()[key];
};
});
}
|
[
"function",
"makeAccessorsFromFunction",
"(",
"callback",
")",
"{",
"return",
"ko",
".",
"utils",
".",
"objectMap",
"(",
"ko",
".",
"dependencyDetection",
".",
"ignore",
"(",
"callback",
")",
",",
"function",
"(",
"value",
",",
"key",
")",
"{",
"return",
"function",
"(",
")",
"{",
"return",
"callback",
"(",
")",
"[",
"key",
"]",
";",
"}",
";",
"}",
")",
";",
"}"
] |
Given a function that returns bindings, create and return a new object that contains binding value-accessors functions. Each accessor function calls the original function so that it always gets the latest value and all dependencies are captured. This is used by ko.applyBindingsToNode and getBindingsAndMakeAccessors.
|
[
"Given",
"a",
"function",
"that",
"returns",
"bindings",
"create",
"and",
"return",
"a",
"new",
"object",
"that",
"contains",
"binding",
"value",
"-",
"accessors",
"functions",
".",
"Each",
"accessor",
"function",
"calls",
"the",
"original",
"function",
"so",
"that",
"it",
"always",
"gets",
"the",
"latest",
"value",
"and",
"all",
"dependencies",
"are",
"captured",
".",
"This",
"is",
"used",
"by",
"ko",
".",
"applyBindingsToNode",
"and",
"getBindingsAndMakeAccessors",
"."
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/assets/knockout/src/binding/bindingAttributeSyntax.js#L158-L164
|
11,454
|
MrSwitch/hello.js
|
assets/css-social-buttons/site/html5slider.js
|
update
|
function update() {
min = isAttrNum(slider.min) ? +slider.min : 0;
max = isAttrNum(slider.max) ? +slider.max : 100;
if (max < min)
max = min > 100 ? min : 100;
step = isAttrNum(slider.step) && slider.step > 0 ? +slider.step : 1;
range = max - min;
draw(true);
}
|
javascript
|
function update() {
min = isAttrNum(slider.min) ? +slider.min : 0;
max = isAttrNum(slider.max) ? +slider.max : 100;
if (max < min)
max = min > 100 ? min : 100;
step = isAttrNum(slider.step) && slider.step > 0 ? +slider.step : 1;
range = max - min;
draw(true);
}
|
[
"function",
"update",
"(",
")",
"{",
"min",
"=",
"isAttrNum",
"(",
"slider",
".",
"min",
")",
"?",
"+",
"slider",
".",
"min",
":",
"0",
";",
"max",
"=",
"isAttrNum",
"(",
"slider",
".",
"max",
")",
"?",
"+",
"slider",
".",
"max",
":",
"100",
";",
"if",
"(",
"max",
"<",
"min",
")",
"max",
"=",
"min",
">",
"100",
"?",
"min",
":",
"100",
";",
"step",
"=",
"isAttrNum",
"(",
"slider",
".",
"step",
")",
"&&",
"slider",
".",
"step",
">",
"0",
"?",
"+",
"slider",
".",
"step",
":",
"1",
";",
"range",
"=",
"max",
"-",
"min",
";",
"draw",
"(",
"true",
")",
";",
"}"
] |
validates min, max, and step attributes and redraws
|
[
"validates",
"min",
"max",
"and",
"step",
"attributes",
"and",
"redraws"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/assets/css-social-buttons/site/html5slider.js#L220-L228
|
11,455
|
MrSwitch/hello.js
|
assets/css-social-buttons/site/html5slider.js
|
calc
|
function calc() {
if (!isValueSet && !areAttrsSet)
value = slider.getAttribute('value');
if (!isAttrNum(value))
value = (min + max) / 2;;
// snap to step intervals (WebKit sometimes does not - bug?)
value = Math.round((value - min) / step) * step + min;
if (value < min)
value = min;
else if (value > max)
value = min + ~~(range / step) * step;
}
|
javascript
|
function calc() {
if (!isValueSet && !areAttrsSet)
value = slider.getAttribute('value');
if (!isAttrNum(value))
value = (min + max) / 2;;
// snap to step intervals (WebKit sometimes does not - bug?)
value = Math.round((value - min) / step) * step + min;
if (value < min)
value = min;
else if (value > max)
value = min + ~~(range / step) * step;
}
|
[
"function",
"calc",
"(",
")",
"{",
"if",
"(",
"!",
"isValueSet",
"&&",
"!",
"areAttrsSet",
")",
"value",
"=",
"slider",
".",
"getAttribute",
"(",
"'value'",
")",
";",
"if",
"(",
"!",
"isAttrNum",
"(",
"value",
")",
")",
"value",
"=",
"(",
"min",
"+",
"max",
")",
"/",
"2",
";",
";",
"// snap to step intervals (WebKit sometimes does not - bug?)",
"value",
"=",
"Math",
".",
"round",
"(",
"(",
"value",
"-",
"min",
")",
"/",
"step",
")",
"*",
"step",
"+",
"min",
";",
"if",
"(",
"value",
"<",
"min",
")",
"value",
"=",
"min",
";",
"else",
"if",
"(",
"value",
">",
"max",
")",
"value",
"=",
"min",
"+",
"~",
"~",
"(",
"range",
"/",
"step",
")",
"*",
"step",
";",
"}"
] |
recalculates value property
|
[
"recalculates",
"value",
"property"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/assets/css-social-buttons/site/html5slider.js#L231-L242
|
11,456
|
MrSwitch/hello.js
|
assets/css-social-buttons/site/html5slider.js
|
draw
|
function draw(attrsModified) {
calc();
if (isChanged && value != prevValue)
slider.dispatchEvent(onChange);
isChanged = false;
if (!attrsModified && value == prevValue)
return;
prevValue = value;
var position = range ? (value - min) / range * 100 : 0;
var bg = '-moz-element(#__sliderthumb__) ' + position + '% no-repeat, ';
style(slider, { background: bg + track });
}
|
javascript
|
function draw(attrsModified) {
calc();
if (isChanged && value != prevValue)
slider.dispatchEvent(onChange);
isChanged = false;
if (!attrsModified && value == prevValue)
return;
prevValue = value;
var position = range ? (value - min) / range * 100 : 0;
var bg = '-moz-element(#__sliderthumb__) ' + position + '% no-repeat, ';
style(slider, { background: bg + track });
}
|
[
"function",
"draw",
"(",
"attrsModified",
")",
"{",
"calc",
"(",
")",
";",
"if",
"(",
"isChanged",
"&&",
"value",
"!=",
"prevValue",
")",
"slider",
".",
"dispatchEvent",
"(",
"onChange",
")",
";",
"isChanged",
"=",
"false",
";",
"if",
"(",
"!",
"attrsModified",
"&&",
"value",
"==",
"prevValue",
")",
"return",
";",
"prevValue",
"=",
"value",
";",
"var",
"position",
"=",
"range",
"?",
"(",
"value",
"-",
"min",
")",
"/",
"range",
"*",
"100",
":",
"0",
";",
"var",
"bg",
"=",
"'-moz-element(#__sliderthumb__) '",
"+",
"position",
"+",
"'% no-repeat, '",
";",
"style",
"(",
"slider",
",",
"{",
"background",
":",
"bg",
"+",
"track",
"}",
")",
";",
"}"
] |
renders slider using CSS background ;)
|
[
"renders",
"slider",
"using",
"CSS",
"background",
";",
")"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/assets/css-social-buttons/site/html5slider.js#L245-L256
|
11,457
|
MrSwitch/hello.js
|
assets/index.js
|
before_photo_post
|
function before_photo_post(test, callback){
hello(test.network)
.api("me/albums")
.then(function(r){
for(var i=0;i<r.data.length;i++){
if(r.data[i].name === "TestAlbum"){
var id = r.data[i].id;
test.data.id = id;
return callback();
}
}
callback("Failed to setup: Could not find the album 'TestAlbum'");
}, function(){
callback("Failed to setup: could not access me/albums");
});
}
|
javascript
|
function before_photo_post(test, callback){
hello(test.network)
.api("me/albums")
.then(function(r){
for(var i=0;i<r.data.length;i++){
if(r.data[i].name === "TestAlbum"){
var id = r.data[i].id;
test.data.id = id;
return callback();
}
}
callback("Failed to setup: Could not find the album 'TestAlbum'");
}, function(){
callback("Failed to setup: could not access me/albums");
});
}
|
[
"function",
"before_photo_post",
"(",
"test",
",",
"callback",
")",
"{",
"hello",
"(",
"test",
".",
"network",
")",
".",
"api",
"(",
"\"me/albums\"",
")",
".",
"then",
"(",
"function",
"(",
"r",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"r",
".",
"data",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"r",
".",
"data",
"[",
"i",
"]",
".",
"name",
"===",
"\"TestAlbum\"",
")",
"{",
"var",
"id",
"=",
"r",
".",
"data",
"[",
"i",
"]",
".",
"id",
";",
"test",
".",
"data",
".",
"id",
"=",
"id",
";",
"return",
"callback",
"(",
")",
";",
"}",
"}",
"callback",
"(",
"\"Failed to setup: Could not find the album 'TestAlbum'\"",
")",
";",
"}",
",",
"function",
"(",
")",
"{",
"callback",
"(",
"\"Failed to setup: could not access me/albums\"",
")",
";",
"}",
")",
";",
"}"
] |
Get the ID of the test album
|
[
"Get",
"the",
"ID",
"of",
"the",
"test",
"album"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/assets/index.js#L772-L787
|
11,458
|
MrSwitch/hello.js
|
assets/index.js
|
DictionaryItem
|
function DictionaryItem(key, value) {
this.key = ko.observable(key);
this.options = [];
if(value instanceof Array){
this.options = value;
value = value[0];
}
this.value = (typeof(value)==='function')? value : ko.observable(value);
}
|
javascript
|
function DictionaryItem(key, value) {
this.key = ko.observable(key);
this.options = [];
if(value instanceof Array){
this.options = value;
value = value[0];
}
this.value = (typeof(value)==='function')? value : ko.observable(value);
}
|
[
"function",
"DictionaryItem",
"(",
"key",
",",
"value",
")",
"{",
"this",
".",
"key",
"=",
"ko",
".",
"observable",
"(",
"key",
")",
";",
"this",
".",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"value",
"instanceof",
"Array",
")",
"{",
"this",
".",
"options",
"=",
"value",
";",
"value",
"=",
"value",
"[",
"0",
"]",
";",
"}",
"this",
".",
"value",
"=",
"(",
"typeof",
"(",
"value",
")",
"===",
"'function'",
")",
"?",
"value",
":",
"ko",
".",
"observable",
"(",
"value",
")",
";",
"}"
] |
Turn an object of Key => Value into mutable stores
|
[
"Turn",
"an",
"object",
"of",
"Key",
"=",
">",
"Value",
"into",
"mutable",
"stores"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/assets/index.js#L1185-L1193
|
11,459
|
MrSwitch/hello.js
|
assets/index.js
|
Dictionary
|
function Dictionary(data) {
this.items = ko.observableArray([]);
for (var field in data) {
if (data.hasOwnProperty(field)) {
this.items.push(new DictionaryItem(field, data[field]));
}
}
this.addItem = function() {
this.items.push(new DictionaryItem());
}.bind(this);
this.removeItem = function(item) {
this.items.remove(item);
}.bind(this);
this.itemsAsObject = ko.dependentObservable(function() {
var result = {};
ko.utils.arrayForEach(this.items(), function(item) {
result[item.key()] = item.value;
});
return result;
}, this);
}
|
javascript
|
function Dictionary(data) {
this.items = ko.observableArray([]);
for (var field in data) {
if (data.hasOwnProperty(field)) {
this.items.push(new DictionaryItem(field, data[field]));
}
}
this.addItem = function() {
this.items.push(new DictionaryItem());
}.bind(this);
this.removeItem = function(item) {
this.items.remove(item);
}.bind(this);
this.itemsAsObject = ko.dependentObservable(function() {
var result = {};
ko.utils.arrayForEach(this.items(), function(item) {
result[item.key()] = item.value;
});
return result;
}, this);
}
|
[
"function",
"Dictionary",
"(",
"data",
")",
"{",
"this",
".",
"items",
"=",
"ko",
".",
"observableArray",
"(",
"[",
"]",
")",
";",
"for",
"(",
"var",
"field",
"in",
"data",
")",
"{",
"if",
"(",
"data",
".",
"hasOwnProperty",
"(",
"field",
")",
")",
"{",
"this",
".",
"items",
".",
"push",
"(",
"new",
"DictionaryItem",
"(",
"field",
",",
"data",
"[",
"field",
"]",
")",
")",
";",
"}",
"}",
"this",
".",
"addItem",
"=",
"function",
"(",
")",
"{",
"this",
".",
"items",
".",
"push",
"(",
"new",
"DictionaryItem",
"(",
")",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"removeItem",
"=",
"function",
"(",
"item",
")",
"{",
"this",
".",
"items",
".",
"remove",
"(",
"item",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"itemsAsObject",
"=",
"ko",
".",
"dependentObservable",
"(",
"function",
"(",
")",
"{",
"var",
"result",
"=",
"{",
"}",
";",
"ko",
".",
"utils",
".",
"arrayForEach",
"(",
"this",
".",
"items",
"(",
")",
",",
"function",
"(",
"item",
")",
"{",
"result",
"[",
"item",
".",
"key",
"(",
")",
"]",
"=",
"item",
".",
"value",
";",
"}",
")",
";",
"return",
"result",
";",
"}",
",",
"this",
")",
";",
"}"
] |
Custom Dictionary observable in Knockout represent the dictionary object
|
[
"Custom",
"Dictionary",
"observable",
"in",
"Knockout",
"represent",
"the",
"dictionary",
"object"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/assets/index.js#L1200-L1224
|
11,460
|
MrSwitch/hello.js
|
assets/index.js
|
_indexOf
|
function _indexOf(a,s){
// Do we need the hack?
if(a.indexOf){
return a.indexOf(s);
}
for(var j=0;j<a.length;j++){
if(a[j]===s){
return j;
}
}
return -1;
}
|
javascript
|
function _indexOf(a,s){
// Do we need the hack?
if(a.indexOf){
return a.indexOf(s);
}
for(var j=0;j<a.length;j++){
if(a[j]===s){
return j;
}
}
return -1;
}
|
[
"function",
"_indexOf",
"(",
"a",
",",
"s",
")",
"{",
"// Do we need the hack?",
"if",
"(",
"a",
".",
"indexOf",
")",
"{",
"return",
"a",
".",
"indexOf",
"(",
"s",
")",
";",
"}",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"a",
".",
"length",
";",
"j",
"++",
")",
"{",
"if",
"(",
"a",
"[",
"j",
"]",
"===",
"s",
")",
"{",
"return",
"j",
";",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] |
indexOf IE hack Array.indexOf doesn't exist prior to IE9
|
[
"indexOf",
"IE",
"hack",
"Array",
".",
"indexOf",
"doesn",
"t",
"exist",
"prior",
"to",
"IE9"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/assets/index.js#L1258-L1270
|
11,461
|
MrSwitch/hello.js
|
assets/expect/index.js
|
every
|
function every (arr, fn, thisObj) {
var scope = thisObj || global;
for (var i = 0, j = arr.length; i < j; ++i) {
if (!fn.call(scope, arr[i], i, arr)) {
return false;
}
}
return true;
}
|
javascript
|
function every (arr, fn, thisObj) {
var scope = thisObj || global;
for (var i = 0, j = arr.length; i < j; ++i) {
if (!fn.call(scope, arr[i], i, arr)) {
return false;
}
}
return true;
}
|
[
"function",
"every",
"(",
"arr",
",",
"fn",
",",
"thisObj",
")",
"{",
"var",
"scope",
"=",
"thisObj",
"||",
"global",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"j",
"=",
"arr",
".",
"length",
";",
"i",
"<",
"j",
";",
"++",
"i",
")",
"{",
"if",
"(",
"!",
"fn",
".",
"call",
"(",
"scope",
",",
"arr",
"[",
"i",
"]",
",",
"i",
",",
"arr",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Array every compatibility
@see bit.ly/5Fq1N2
@api public
|
[
"Array",
"every",
"compatibility"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/assets/expect/index.js#L510-L518
|
11,462
|
MrSwitch/hello.js
|
demos/helper/uiProfile.js
|
img_xhr
|
function img_xhr(img, url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
img.src = window.URL.createObjectURL(this.response);
};
xhr.send();
}
|
javascript
|
function img_xhr(img, url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
img.src = window.URL.createObjectURL(this.response);
};
xhr.send();
}
|
[
"function",
"img_xhr",
"(",
"img",
",",
"url",
")",
"{",
"var",
"xhr",
"=",
"new",
"XMLHttpRequest",
"(",
")",
";",
"xhr",
".",
"open",
"(",
"'GET'",
",",
"url",
",",
"true",
")",
";",
"xhr",
".",
"responseType",
"=",
"'blob'",
";",
"xhr",
".",
"onload",
"=",
"function",
"(",
"e",
")",
"{",
"img",
".",
"src",
"=",
"window",
".",
"URL",
".",
"createObjectURL",
"(",
"this",
".",
"response",
")",
";",
"}",
";",
"xhr",
".",
"send",
"(",
")",
";",
"}"
] |
Utility for loading the thumbnail in chromeapp
|
[
"Utility",
"for",
"loading",
"the",
"thumbnail",
"in",
"chromeapp"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/helper/uiProfile.js#L42-L50
|
11,463
|
MrSwitch/hello.js
|
demos/FilePicker/filePicker.js
|
fileRef
|
function fileRef(item, network, bucket, selected){
this.els = [];
this.selected = false;
this.item = {};
// Item contents change
this.update = function(item){
if(!item){
return this.item;
}
else {
// Merge the two together
this.item = hello.utils.merge(this.item, item);
}
// Loop through the elements and update their content
for(var i=0;i<this.els.length;i++){
this.els[i].getElementsByTagName('span')[0].innerHTML = this.item.name;
if(this.item.thumbnail){
this.els[i].getElementsByTagName('img')[0].src = this.item.thumbnail;
}
}
};
// Create an element in the given bucket,
// adding on click event handlers
this.create = function(bucket){
var item = this.item;
var self = this;
var el = doc.createElement('li');
el.title = item.name;
el.innerHTML = "<img "+(item.thumbnail?"src='"+item.thumbnail+"'":"")+"/>"
+"<span>"+(item.name||'')+"</span>";
el.onclick = function(){
// Is this a folder?
if(item.type==='folder'||item.type==='album'){
getBucket(network+":"+(item.files?item.files:item.id+"/files"), item.name, bucket.id );
}
else {
// Toggle selected
self.toggleSelect();
}
};
// Add to bucket
bucket.appendChild(el);
// Add to local store
this.els.push(el);
return el;
};
this.toggleSelect = function(bool){
if(bool===this.selected){
// nothing
return;
}
// else change
// toggle
this.selected = !this.selected;
// Selected
if(this.selected){
// Does the element exist within the local bucket
var local = false;
for(i=0;i<this.els.length;i++){
if( this.els[i].parentNode === select_el ){
local=true;
break;
}
}
if(!local){
// create it
this.create(select_el);
}
}
// Loop through the elements and update their content
for(i=0;i<this.els.length;i++){
this.els[i].className = this.selected ? "select" : "";
}
// get the number of selected items in ref and update
info_el.innerHTML = ( this.selected ? ++global_counter : --global_counter );
};
// Create the initial element
this.update(item);
this.create(bucket);
// if this is selected
if(selected){
this.toggleSelect();
}
}
|
javascript
|
function fileRef(item, network, bucket, selected){
this.els = [];
this.selected = false;
this.item = {};
// Item contents change
this.update = function(item){
if(!item){
return this.item;
}
else {
// Merge the two together
this.item = hello.utils.merge(this.item, item);
}
// Loop through the elements and update their content
for(var i=0;i<this.els.length;i++){
this.els[i].getElementsByTagName('span')[0].innerHTML = this.item.name;
if(this.item.thumbnail){
this.els[i].getElementsByTagName('img')[0].src = this.item.thumbnail;
}
}
};
// Create an element in the given bucket,
// adding on click event handlers
this.create = function(bucket){
var item = this.item;
var self = this;
var el = doc.createElement('li');
el.title = item.name;
el.innerHTML = "<img "+(item.thumbnail?"src='"+item.thumbnail+"'":"")+"/>"
+"<span>"+(item.name||'')+"</span>";
el.onclick = function(){
// Is this a folder?
if(item.type==='folder'||item.type==='album'){
getBucket(network+":"+(item.files?item.files:item.id+"/files"), item.name, bucket.id );
}
else {
// Toggle selected
self.toggleSelect();
}
};
// Add to bucket
bucket.appendChild(el);
// Add to local store
this.els.push(el);
return el;
};
this.toggleSelect = function(bool){
if(bool===this.selected){
// nothing
return;
}
// else change
// toggle
this.selected = !this.selected;
// Selected
if(this.selected){
// Does the element exist within the local bucket
var local = false;
for(i=0;i<this.els.length;i++){
if( this.els[i].parentNode === select_el ){
local=true;
break;
}
}
if(!local){
// create it
this.create(select_el);
}
}
// Loop through the elements and update their content
for(i=0;i<this.els.length;i++){
this.els[i].className = this.selected ? "select" : "";
}
// get the number of selected items in ref and update
info_el.innerHTML = ( this.selected ? ++global_counter : --global_counter );
};
// Create the initial element
this.update(item);
this.create(bucket);
// if this is selected
if(selected){
this.toggleSelect();
}
}
|
[
"function",
"fileRef",
"(",
"item",
",",
"network",
",",
"bucket",
",",
"selected",
")",
"{",
"this",
".",
"els",
"=",
"[",
"]",
";",
"this",
".",
"selected",
"=",
"false",
";",
"this",
".",
"item",
"=",
"{",
"}",
";",
"// Item contents change",
"this",
".",
"update",
"=",
"function",
"(",
"item",
")",
"{",
"if",
"(",
"!",
"item",
")",
"{",
"return",
"this",
".",
"item",
";",
"}",
"else",
"{",
"// Merge the two together",
"this",
".",
"item",
"=",
"hello",
".",
"utils",
".",
"merge",
"(",
"this",
".",
"item",
",",
"item",
")",
";",
"}",
"// Loop through the elements and update their content",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"els",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"els",
"[",
"i",
"]",
".",
"getElementsByTagName",
"(",
"'span'",
")",
"[",
"0",
"]",
".",
"innerHTML",
"=",
"this",
".",
"item",
".",
"name",
";",
"if",
"(",
"this",
".",
"item",
".",
"thumbnail",
")",
"{",
"this",
".",
"els",
"[",
"i",
"]",
".",
"getElementsByTagName",
"(",
"'img'",
")",
"[",
"0",
"]",
".",
"src",
"=",
"this",
".",
"item",
".",
"thumbnail",
";",
"}",
"}",
"}",
";",
"// Create an element in the given bucket,",
"// adding on click event handlers",
"this",
".",
"create",
"=",
"function",
"(",
"bucket",
")",
"{",
"var",
"item",
"=",
"this",
".",
"item",
";",
"var",
"self",
"=",
"this",
";",
"var",
"el",
"=",
"doc",
".",
"createElement",
"(",
"'li'",
")",
";",
"el",
".",
"title",
"=",
"item",
".",
"name",
";",
"el",
".",
"innerHTML",
"=",
"\"<img \"",
"+",
"(",
"item",
".",
"thumbnail",
"?",
"\"src='\"",
"+",
"item",
".",
"thumbnail",
"+",
"\"'\"",
":",
"\"\"",
")",
"+",
"\"/>\"",
"+",
"\"<span>\"",
"+",
"(",
"item",
".",
"name",
"||",
"''",
")",
"+",
"\"</span>\"",
";",
"el",
".",
"onclick",
"=",
"function",
"(",
")",
"{",
"// Is this a folder?",
"if",
"(",
"item",
".",
"type",
"===",
"'folder'",
"||",
"item",
".",
"type",
"===",
"'album'",
")",
"{",
"getBucket",
"(",
"network",
"+",
"\":\"",
"+",
"(",
"item",
".",
"files",
"?",
"item",
".",
"files",
":",
"item",
".",
"id",
"+",
"\"/files\"",
")",
",",
"item",
".",
"name",
",",
"bucket",
".",
"id",
")",
";",
"}",
"else",
"{",
"// Toggle selected",
"self",
".",
"toggleSelect",
"(",
")",
";",
"}",
"}",
";",
"// Add to bucket",
"bucket",
".",
"appendChild",
"(",
"el",
")",
";",
"// Add to local store",
"this",
".",
"els",
".",
"push",
"(",
"el",
")",
";",
"return",
"el",
";",
"}",
";",
"this",
".",
"toggleSelect",
"=",
"function",
"(",
"bool",
")",
"{",
"if",
"(",
"bool",
"===",
"this",
".",
"selected",
")",
"{",
"// nothing",
"return",
";",
"}",
"// else change",
"// toggle",
"this",
".",
"selected",
"=",
"!",
"this",
".",
"selected",
";",
"// Selected",
"if",
"(",
"this",
".",
"selected",
")",
"{",
"// Does the element exist within the local bucket",
"var",
"local",
"=",
"false",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"els",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"this",
".",
"els",
"[",
"i",
"]",
".",
"parentNode",
"===",
"select_el",
")",
"{",
"local",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"local",
")",
"{",
"// create it",
"this",
".",
"create",
"(",
"select_el",
")",
";",
"}",
"}",
"// Loop through the elements and update their content",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"els",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"els",
"[",
"i",
"]",
".",
"className",
"=",
"this",
".",
"selected",
"?",
"\"select\"",
":",
"\"\"",
";",
"}",
"// get the number of selected items in ref and update",
"info_el",
".",
"innerHTML",
"=",
"(",
"this",
".",
"selected",
"?",
"++",
"global_counter",
":",
"--",
"global_counter",
")",
";",
"}",
";",
"// Create the initial element",
"this",
".",
"update",
"(",
"item",
")",
";",
"this",
".",
"create",
"(",
"bucket",
")",
";",
"// if this is selected",
"if",
"(",
"selected",
")",
"{",
"this",
".",
"toggleSelect",
"(",
")",
";",
"}",
"}"
] |
Each item is stored as a fileRef instance in the ref array This function controls the element which it is applied upon. Controlling when the elements update for generated content
|
[
"Each",
"item",
"is",
"stored",
"as",
"a",
"fileRef",
"instance",
"in",
"the",
"ref",
"array",
"This",
"function",
"controls",
"the",
"element",
"which",
"it",
"is",
"applied",
"upon",
".",
"Controlling",
"when",
"the",
"elements",
"update",
"for",
"generated",
"content"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/FilePicker/filePicker.js#L387-L486
|
11,464
|
MrSwitch/hello.js
|
demos/FilePicker/filePicker.js
|
uploadFileList
|
function uploadFileList(files){
// FileList
if(!("FileList" in window) || (files instanceof File) || (files instanceof Blob)){
// Make an Array
files = [files];
}
var max = 20, len = files.length;
if(len>max){
var bool = confirm("You man only upload "+max+" files at a time");
if(!bool){
return;
}
len = max;
}
// Loop through the array and place the items on the page
for(var i=0;i<len;i++){
createRef(files[i]);
}
}
|
javascript
|
function uploadFileList(files){
// FileList
if(!("FileList" in window) || (files instanceof File) || (files instanceof Blob)){
// Make an Array
files = [files];
}
var max = 20, len = files.length;
if(len>max){
var bool = confirm("You man only upload "+max+" files at a time");
if(!bool){
return;
}
len = max;
}
// Loop through the array and place the items on the page
for(var i=0;i<len;i++){
createRef(files[i]);
}
}
|
[
"function",
"uploadFileList",
"(",
"files",
")",
"{",
"// FileList",
"if",
"(",
"!",
"(",
"\"FileList\"",
"in",
"window",
")",
"||",
"(",
"files",
"instanceof",
"File",
")",
"||",
"(",
"files",
"instanceof",
"Blob",
")",
")",
"{",
"// Make an Array",
"files",
"=",
"[",
"files",
"]",
";",
"}",
"var",
"max",
"=",
"20",
",",
"len",
"=",
"files",
".",
"length",
";",
"if",
"(",
"len",
">",
"max",
")",
"{",
"var",
"bool",
"=",
"confirm",
"(",
"\"You man only upload \"",
"+",
"max",
"+",
"\" files at a time\"",
")",
";",
"if",
"(",
"!",
"bool",
")",
"{",
"return",
";",
"}",
"len",
"=",
"max",
";",
"}",
"// Loop through the array and place the items on the page",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"createRef",
"(",
"files",
"[",
"i",
"]",
")",
";",
"}",
"}"
] |
Upload file list Take all the photos in the FileList and create items with them
|
[
"Upload",
"file",
"list",
"Take",
"all",
"the",
"photos",
"in",
"the",
"FileList",
"and",
"create",
"items",
"with",
"them"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/FilePicker/filePicker.js#L491-L513
|
11,465
|
MrSwitch/hello.js
|
demos/FilePicker/filePicker.js
|
createRef
|
function createRef(file){
// Create a new fileRef
var pointer = new fileRef({
name : file.name,
type : file.type,
file : file
}, current_network, current_bucket, true);
ref.push( pointer );
if(current_folder==="local"){
readFile(file, function(dataURL){
// Update list
pointer.update({
thumbnail : dataURL,
picture : dataURL
});
});
}
else{
// Upload the files to the current directory
hello.api(current_folder, "post", {file: file}, function(r){
// Once the files have been successfully upload lets update the pointer
pointer.update({
id : r.id,
thumbnail : r.source,
picture : r.source
});
});
}
}
|
javascript
|
function createRef(file){
// Create a new fileRef
var pointer = new fileRef({
name : file.name,
type : file.type,
file : file
}, current_network, current_bucket, true);
ref.push( pointer );
if(current_folder==="local"){
readFile(file, function(dataURL){
// Update list
pointer.update({
thumbnail : dataURL,
picture : dataURL
});
});
}
else{
// Upload the files to the current directory
hello.api(current_folder, "post", {file: file}, function(r){
// Once the files have been successfully upload lets update the pointer
pointer.update({
id : r.id,
thumbnail : r.source,
picture : r.source
});
});
}
}
|
[
"function",
"createRef",
"(",
"file",
")",
"{",
"// Create a new fileRef",
"var",
"pointer",
"=",
"new",
"fileRef",
"(",
"{",
"name",
":",
"file",
".",
"name",
",",
"type",
":",
"file",
".",
"type",
",",
"file",
":",
"file",
"}",
",",
"current_network",
",",
"current_bucket",
",",
"true",
")",
";",
"ref",
".",
"push",
"(",
"pointer",
")",
";",
"if",
"(",
"current_folder",
"===",
"\"local\"",
")",
"{",
"readFile",
"(",
"file",
",",
"function",
"(",
"dataURL",
")",
"{",
"// Update list",
"pointer",
".",
"update",
"(",
"{",
"thumbnail",
":",
"dataURL",
",",
"picture",
":",
"dataURL",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"// Upload the files to the current directory",
"hello",
".",
"api",
"(",
"current_folder",
",",
"\"post\"",
",",
"{",
"file",
":",
"file",
"}",
",",
"function",
"(",
"r",
")",
"{",
"// Once the files have been successfully upload lets update the pointer",
"pointer",
".",
"update",
"(",
"{",
"id",
":",
"r",
".",
"id",
",",
"thumbnail",
":",
"r",
".",
"source",
",",
"picture",
":",
"r",
".",
"source",
"}",
")",
";",
"}",
")",
";",
"}",
"}"
] |
Do we upload them to the endpoint? Or load them into the page?
|
[
"Do",
"we",
"upload",
"them",
"to",
"the",
"endpoint?",
"Or",
"load",
"them",
"into",
"the",
"page?"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/FilePicker/filePicker.js#L516-L548
|
11,466
|
MrSwitch/hello.js
|
demos/FilePicker/filePicker.js
|
readFile
|
function readFile(file, callback){
// Run this sequentially
sync(function(){
// Create a new FileReader Object
var reader = new FileReader();
// Set an onload handler because we load files into it Asynchronously
reader.onload = function(e){
// Print onto Canvas
callback( this.result );
// Run the next one;
sync();
};
reader.readAsDataURL(file);
});
}
|
javascript
|
function readFile(file, callback){
// Run this sequentially
sync(function(){
// Create a new FileReader Object
var reader = new FileReader();
// Set an onload handler because we load files into it Asynchronously
reader.onload = function(e){
// Print onto Canvas
callback( this.result );
// Run the next one;
sync();
};
reader.readAsDataURL(file);
});
}
|
[
"function",
"readFile",
"(",
"file",
",",
"callback",
")",
"{",
"// Run this sequentially",
"sync",
"(",
"function",
"(",
")",
"{",
"// Create a new FileReader Object",
"var",
"reader",
"=",
"new",
"FileReader",
"(",
")",
";",
"// Set an onload handler because we load files into it Asynchronously",
"reader",
".",
"onload",
"=",
"function",
"(",
"e",
")",
"{",
"// Print onto Canvas",
"callback",
"(",
"this",
".",
"result",
")",
";",
"// Run the next one;",
"sync",
"(",
")",
";",
"}",
";",
"reader",
".",
"readAsDataURL",
"(",
"file",
")",
";",
"}",
")",
";",
"}"
] |
readFile Perform one operation at a time, to get a nice gradule load
|
[
"readFile",
"Perform",
"one",
"operation",
"at",
"a",
"time",
"to",
"get",
"a",
"nice",
"gradule",
"load"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/demos/FilePicker/filePicker.js#L552-L571
|
11,467
|
MrSwitch/hello.js
|
src/modules/tumblr.js
|
query
|
function query(p, callback) {
if (p.data) {
extend(p.query, p.data);
p.data = null;
}
callback(p.path);
}
|
javascript
|
function query(p, callback) {
if (p.data) {
extend(p.query, p.data);
p.data = null;
}
callback(p.path);
}
|
[
"function",
"query",
"(",
"p",
",",
"callback",
")",
"{",
"if",
"(",
"p",
".",
"data",
")",
"{",
"extend",
"(",
"p",
".",
"query",
",",
"p",
".",
"data",
")",
";",
"p",
".",
"data",
"=",
"null",
";",
"}",
"callback",
"(",
"p",
".",
"path",
")",
";",
"}"
] |
Converts post parameters to query
|
[
"Converts",
"post",
"parameters",
"to",
"query"
] |
50b2b792d758774fc08e8da911fd4415ea3831ba
|
https://github.com/MrSwitch/hello.js/blob/50b2b792d758774fc08e8da911fd4415ea3831ba/src/modules/tumblr.js#L93-L100
|
11,468
|
rtfeldman/seamless-immutable
|
seamless-immutable.development.js
|
without
|
function without(remove) {
// Calling .without() with no arguments is a no-op. Don't bother cloning.
if (typeof remove === "undefined" && arguments.length === 0) {
return this;
}
if (typeof remove !== "function") {
// If we weren't given an array, use the arguments list.
var keysToRemoveArray = (Array.isArray(remove)) ?
remove.slice() : Array.prototype.slice.call(arguments);
// Convert numeric keys to strings since that's how they'll
// come from the enumeration of the object.
keysToRemoveArray.forEach(function(el, idx, arr) {
if(typeof(el) === "number") {
arr[idx] = el.toString();
}
});
remove = function(val, key) {
return keysToRemoveArray.indexOf(key) !== -1;
};
}
var result = instantiateEmptyObject(this);
for (var key in this) {
if (this.hasOwnProperty(key) && remove(this[key], key) === false) {
result[key] = this[key];
}
}
return makeImmutableObject(result);
}
|
javascript
|
function without(remove) {
// Calling .without() with no arguments is a no-op. Don't bother cloning.
if (typeof remove === "undefined" && arguments.length === 0) {
return this;
}
if (typeof remove !== "function") {
// If we weren't given an array, use the arguments list.
var keysToRemoveArray = (Array.isArray(remove)) ?
remove.slice() : Array.prototype.slice.call(arguments);
// Convert numeric keys to strings since that's how they'll
// come from the enumeration of the object.
keysToRemoveArray.forEach(function(el, idx, arr) {
if(typeof(el) === "number") {
arr[idx] = el.toString();
}
});
remove = function(val, key) {
return keysToRemoveArray.indexOf(key) !== -1;
};
}
var result = instantiateEmptyObject(this);
for (var key in this) {
if (this.hasOwnProperty(key) && remove(this[key], key) === false) {
result[key] = this[key];
}
}
return makeImmutableObject(result);
}
|
[
"function",
"without",
"(",
"remove",
")",
"{",
"// Calling .without() with no arguments is a no-op. Don't bother cloning.",
"if",
"(",
"typeof",
"remove",
"===",
"\"undefined\"",
"&&",
"arguments",
".",
"length",
"===",
"0",
")",
"{",
"return",
"this",
";",
"}",
"if",
"(",
"typeof",
"remove",
"!==",
"\"function\"",
")",
"{",
"// If we weren't given an array, use the arguments list.",
"var",
"keysToRemoveArray",
"=",
"(",
"Array",
".",
"isArray",
"(",
"remove",
")",
")",
"?",
"remove",
".",
"slice",
"(",
")",
":",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"// Convert numeric keys to strings since that's how they'll",
"// come from the enumeration of the object.",
"keysToRemoveArray",
".",
"forEach",
"(",
"function",
"(",
"el",
",",
"idx",
",",
"arr",
")",
"{",
"if",
"(",
"typeof",
"(",
"el",
")",
"===",
"\"number\"",
")",
"{",
"arr",
"[",
"idx",
"]",
"=",
"el",
".",
"toString",
"(",
")",
";",
"}",
"}",
")",
";",
"remove",
"=",
"function",
"(",
"val",
",",
"key",
")",
"{",
"return",
"keysToRemoveArray",
".",
"indexOf",
"(",
"key",
")",
"!==",
"-",
"1",
";",
"}",
";",
"}",
"var",
"result",
"=",
"instantiateEmptyObject",
"(",
"this",
")",
";",
"for",
"(",
"var",
"key",
"in",
"this",
")",
"{",
"if",
"(",
"this",
".",
"hasOwnProperty",
"(",
"key",
")",
"&&",
"remove",
"(",
"this",
"[",
"key",
"]",
",",
"key",
")",
"===",
"false",
")",
"{",
"result",
"[",
"key",
"]",
"=",
"this",
"[",
"key",
"]",
";",
"}",
"}",
"return",
"makeImmutableObject",
"(",
"result",
")",
";",
"}"
] |
Returns an Immutable copy of the object without the given keys included.
@param {array} keysToRemove - A list of strings representing the keys to exclude in the return value. Instead of providing a single array, this method can also be called by passing multiple strings as separate arguments.
|
[
"Returns",
"an",
"Immutable",
"copy",
"of",
"the",
"object",
"without",
"the",
"given",
"keys",
"included",
"."
] |
2d870b14a01e222493c686a7644181185f859558
|
https://github.com/rtfeldman/seamless-immutable/blob/2d870b14a01e222493c686a7644181185f859558/seamless-immutable.development.js#L265-L298
|
11,469
|
rtfeldman/seamless-immutable
|
seamless-immutable.development.js
|
merge
|
function merge(other, config) {
// Calling .merge() with no arguments is a no-op. Don't bother cloning.
if (arguments.length === 0) {
return this;
}
if (other === null || (typeof other !== "object")) {
throw new TypeError("Immutable#merge can only be invoked with objects or arrays, not " + JSON.stringify(other));
}
var receivedArray = (Array.isArray(other)),
deep = config && config.deep,
mode = config && config.mode || 'merge',
merger = config && config.merger,
result;
// Use the given key to extract a value from the given object, then place
// that value in the result object under the same key. If that resulted
// in a change from this object's value at that key, set anyChanges = true.
function addToResult(currentObj, otherObj, key) {
var immutableValue = Immutable(otherObj[key]);
var mergerResult = merger && merger(currentObj[key], immutableValue, config);
var currentValue = currentObj[key];
if ((result !== undefined) ||
(mergerResult !== undefined) ||
(!currentObj.hasOwnProperty(key)) ||
!isEqual(immutableValue, currentValue)) {
var newValue;
if (mergerResult !== undefined) {
newValue = mergerResult;
} else if (deep && isMergableObject(currentValue) && isMergableObject(immutableValue)) {
newValue = Immutable.merge(currentValue, immutableValue, config);
} else {
newValue = immutableValue;
}
if (!isEqual(currentValue, newValue) || !currentObj.hasOwnProperty(key)) {
if (result === undefined) {
// Make a shallow clone of the current object.
result = quickCopy(currentObj, instantiateEmptyObject(currentObj));
}
result[key] = newValue;
}
}
}
function clearDroppedKeys(currentObj, otherObj) {
for (var key in currentObj) {
if (!otherObj.hasOwnProperty(key)) {
if (result === undefined) {
// Make a shallow clone of the current object.
result = quickCopy(currentObj, instantiateEmptyObject(currentObj));
}
delete result[key];
}
}
}
var key;
// Achieve prioritization by overriding previous values that get in the way.
if (!receivedArray) {
// The most common use case: just merge one object into the existing one.
for (key in other) {
if (Object.getOwnPropertyDescriptor(other, key)) {
addToResult(this, other, key);
}
}
if (mode === 'replace') {
clearDroppedKeys(this, other);
}
} else {
// We also accept an Array
for (var index = 0, length = other.length; index < length; index++) {
var otherFromArray = other[index];
for (key in otherFromArray) {
if (otherFromArray.hasOwnProperty(key)) {
addToResult(result !== undefined ? result : this, otherFromArray, key);
}
}
}
}
if (result === undefined) {
return this;
} else {
return makeImmutableObject(result);
}
}
|
javascript
|
function merge(other, config) {
// Calling .merge() with no arguments is a no-op. Don't bother cloning.
if (arguments.length === 0) {
return this;
}
if (other === null || (typeof other !== "object")) {
throw new TypeError("Immutable#merge can only be invoked with objects or arrays, not " + JSON.stringify(other));
}
var receivedArray = (Array.isArray(other)),
deep = config && config.deep,
mode = config && config.mode || 'merge',
merger = config && config.merger,
result;
// Use the given key to extract a value from the given object, then place
// that value in the result object under the same key. If that resulted
// in a change from this object's value at that key, set anyChanges = true.
function addToResult(currentObj, otherObj, key) {
var immutableValue = Immutable(otherObj[key]);
var mergerResult = merger && merger(currentObj[key], immutableValue, config);
var currentValue = currentObj[key];
if ((result !== undefined) ||
(mergerResult !== undefined) ||
(!currentObj.hasOwnProperty(key)) ||
!isEqual(immutableValue, currentValue)) {
var newValue;
if (mergerResult !== undefined) {
newValue = mergerResult;
} else if (deep && isMergableObject(currentValue) && isMergableObject(immutableValue)) {
newValue = Immutable.merge(currentValue, immutableValue, config);
} else {
newValue = immutableValue;
}
if (!isEqual(currentValue, newValue) || !currentObj.hasOwnProperty(key)) {
if (result === undefined) {
// Make a shallow clone of the current object.
result = quickCopy(currentObj, instantiateEmptyObject(currentObj));
}
result[key] = newValue;
}
}
}
function clearDroppedKeys(currentObj, otherObj) {
for (var key in currentObj) {
if (!otherObj.hasOwnProperty(key)) {
if (result === undefined) {
// Make a shallow clone of the current object.
result = quickCopy(currentObj, instantiateEmptyObject(currentObj));
}
delete result[key];
}
}
}
var key;
// Achieve prioritization by overriding previous values that get in the way.
if (!receivedArray) {
// The most common use case: just merge one object into the existing one.
for (key in other) {
if (Object.getOwnPropertyDescriptor(other, key)) {
addToResult(this, other, key);
}
}
if (mode === 'replace') {
clearDroppedKeys(this, other);
}
} else {
// We also accept an Array
for (var index = 0, length = other.length; index < length; index++) {
var otherFromArray = other[index];
for (key in otherFromArray) {
if (otherFromArray.hasOwnProperty(key)) {
addToResult(result !== undefined ? result : this, otherFromArray, key);
}
}
}
}
if (result === undefined) {
return this;
} else {
return makeImmutableObject(result);
}
}
|
[
"function",
"merge",
"(",
"other",
",",
"config",
")",
"{",
"// Calling .merge() with no arguments is a no-op. Don't bother cloning.",
"if",
"(",
"arguments",
".",
"length",
"===",
"0",
")",
"{",
"return",
"this",
";",
"}",
"if",
"(",
"other",
"===",
"null",
"||",
"(",
"typeof",
"other",
"!==",
"\"object\"",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"\"Immutable#merge can only be invoked with objects or arrays, not \"",
"+",
"JSON",
".",
"stringify",
"(",
"other",
")",
")",
";",
"}",
"var",
"receivedArray",
"=",
"(",
"Array",
".",
"isArray",
"(",
"other",
")",
")",
",",
"deep",
"=",
"config",
"&&",
"config",
".",
"deep",
",",
"mode",
"=",
"config",
"&&",
"config",
".",
"mode",
"||",
"'merge'",
",",
"merger",
"=",
"config",
"&&",
"config",
".",
"merger",
",",
"result",
";",
"// Use the given key to extract a value from the given object, then place",
"// that value in the result object under the same key. If that resulted",
"// in a change from this object's value at that key, set anyChanges = true.",
"function",
"addToResult",
"(",
"currentObj",
",",
"otherObj",
",",
"key",
")",
"{",
"var",
"immutableValue",
"=",
"Immutable",
"(",
"otherObj",
"[",
"key",
"]",
")",
";",
"var",
"mergerResult",
"=",
"merger",
"&&",
"merger",
"(",
"currentObj",
"[",
"key",
"]",
",",
"immutableValue",
",",
"config",
")",
";",
"var",
"currentValue",
"=",
"currentObj",
"[",
"key",
"]",
";",
"if",
"(",
"(",
"result",
"!==",
"undefined",
")",
"||",
"(",
"mergerResult",
"!==",
"undefined",
")",
"||",
"(",
"!",
"currentObj",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"||",
"!",
"isEqual",
"(",
"immutableValue",
",",
"currentValue",
")",
")",
"{",
"var",
"newValue",
";",
"if",
"(",
"mergerResult",
"!==",
"undefined",
")",
"{",
"newValue",
"=",
"mergerResult",
";",
"}",
"else",
"if",
"(",
"deep",
"&&",
"isMergableObject",
"(",
"currentValue",
")",
"&&",
"isMergableObject",
"(",
"immutableValue",
")",
")",
"{",
"newValue",
"=",
"Immutable",
".",
"merge",
"(",
"currentValue",
",",
"immutableValue",
",",
"config",
")",
";",
"}",
"else",
"{",
"newValue",
"=",
"immutableValue",
";",
"}",
"if",
"(",
"!",
"isEqual",
"(",
"currentValue",
",",
"newValue",
")",
"||",
"!",
"currentObj",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"if",
"(",
"result",
"===",
"undefined",
")",
"{",
"// Make a shallow clone of the current object.",
"result",
"=",
"quickCopy",
"(",
"currentObj",
",",
"instantiateEmptyObject",
"(",
"currentObj",
")",
")",
";",
"}",
"result",
"[",
"key",
"]",
"=",
"newValue",
";",
"}",
"}",
"}",
"function",
"clearDroppedKeys",
"(",
"currentObj",
",",
"otherObj",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"currentObj",
")",
"{",
"if",
"(",
"!",
"otherObj",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"if",
"(",
"result",
"===",
"undefined",
")",
"{",
"// Make a shallow clone of the current object.",
"result",
"=",
"quickCopy",
"(",
"currentObj",
",",
"instantiateEmptyObject",
"(",
"currentObj",
")",
")",
";",
"}",
"delete",
"result",
"[",
"key",
"]",
";",
"}",
"}",
"}",
"var",
"key",
";",
"// Achieve prioritization by overriding previous values that get in the way.",
"if",
"(",
"!",
"receivedArray",
")",
"{",
"// The most common use case: just merge one object into the existing one.",
"for",
"(",
"key",
"in",
"other",
")",
"{",
"if",
"(",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"other",
",",
"key",
")",
")",
"{",
"addToResult",
"(",
"this",
",",
"other",
",",
"key",
")",
";",
"}",
"}",
"if",
"(",
"mode",
"===",
"'replace'",
")",
"{",
"clearDroppedKeys",
"(",
"this",
",",
"other",
")",
";",
"}",
"}",
"else",
"{",
"// We also accept an Array",
"for",
"(",
"var",
"index",
"=",
"0",
",",
"length",
"=",
"other",
".",
"length",
";",
"index",
"<",
"length",
";",
"index",
"++",
")",
"{",
"var",
"otherFromArray",
"=",
"other",
"[",
"index",
"]",
";",
"for",
"(",
"key",
"in",
"otherFromArray",
")",
"{",
"if",
"(",
"otherFromArray",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"addToResult",
"(",
"result",
"!==",
"undefined",
"?",
"result",
":",
"this",
",",
"otherFromArray",
",",
"key",
")",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"result",
"===",
"undefined",
")",
"{",
"return",
"this",
";",
"}",
"else",
"{",
"return",
"makeImmutableObject",
"(",
"result",
")",
";",
"}",
"}"
] |
Returns an Immutable Object containing the properties and values of both
this object and the provided object, prioritizing the provided object's
values whenever the same key is present in both objects.
@param {object} other - The other object to merge. Multiple objects can be passed as an array. In such a case, the later an object appears in that list, the higher its priority.
@param {object} config - Optional config object that contains settings. Supported settings are: {deep: true} for deep merge and {merger: mergerFunc} where mergerFunc is a function
that takes a property from both objects. If anything is returned it overrides the normal merge behaviour.
|
[
"Returns",
"an",
"Immutable",
"Object",
"containing",
"the",
"properties",
"and",
"values",
"of",
"both",
"this",
"object",
"and",
"the",
"provided",
"object",
"prioritizing",
"the",
"provided",
"object",
"s",
"values",
"whenever",
"the",
"same",
"key",
"is",
"present",
"in",
"both",
"objects",
"."
] |
2d870b14a01e222493c686a7644181185f859558
|
https://github.com/rtfeldman/seamless-immutable/blob/2d870b14a01e222493c686a7644181185f859558/seamless-immutable.development.js#L374-L467
|
11,470
|
rtfeldman/seamless-immutable
|
seamless-immutable.development.js
|
addToResult
|
function addToResult(currentObj, otherObj, key) {
var immutableValue = Immutable(otherObj[key]);
var mergerResult = merger && merger(currentObj[key], immutableValue, config);
var currentValue = currentObj[key];
if ((result !== undefined) ||
(mergerResult !== undefined) ||
(!currentObj.hasOwnProperty(key)) ||
!isEqual(immutableValue, currentValue)) {
var newValue;
if (mergerResult !== undefined) {
newValue = mergerResult;
} else if (deep && isMergableObject(currentValue) && isMergableObject(immutableValue)) {
newValue = Immutable.merge(currentValue, immutableValue, config);
} else {
newValue = immutableValue;
}
if (!isEqual(currentValue, newValue) || !currentObj.hasOwnProperty(key)) {
if (result === undefined) {
// Make a shallow clone of the current object.
result = quickCopy(currentObj, instantiateEmptyObject(currentObj));
}
result[key] = newValue;
}
}
}
|
javascript
|
function addToResult(currentObj, otherObj, key) {
var immutableValue = Immutable(otherObj[key]);
var mergerResult = merger && merger(currentObj[key], immutableValue, config);
var currentValue = currentObj[key];
if ((result !== undefined) ||
(mergerResult !== undefined) ||
(!currentObj.hasOwnProperty(key)) ||
!isEqual(immutableValue, currentValue)) {
var newValue;
if (mergerResult !== undefined) {
newValue = mergerResult;
} else if (deep && isMergableObject(currentValue) && isMergableObject(immutableValue)) {
newValue = Immutable.merge(currentValue, immutableValue, config);
} else {
newValue = immutableValue;
}
if (!isEqual(currentValue, newValue) || !currentObj.hasOwnProperty(key)) {
if (result === undefined) {
// Make a shallow clone of the current object.
result = quickCopy(currentObj, instantiateEmptyObject(currentObj));
}
result[key] = newValue;
}
}
}
|
[
"function",
"addToResult",
"(",
"currentObj",
",",
"otherObj",
",",
"key",
")",
"{",
"var",
"immutableValue",
"=",
"Immutable",
"(",
"otherObj",
"[",
"key",
"]",
")",
";",
"var",
"mergerResult",
"=",
"merger",
"&&",
"merger",
"(",
"currentObj",
"[",
"key",
"]",
",",
"immutableValue",
",",
"config",
")",
";",
"var",
"currentValue",
"=",
"currentObj",
"[",
"key",
"]",
";",
"if",
"(",
"(",
"result",
"!==",
"undefined",
")",
"||",
"(",
"mergerResult",
"!==",
"undefined",
")",
"||",
"(",
"!",
"currentObj",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"||",
"!",
"isEqual",
"(",
"immutableValue",
",",
"currentValue",
")",
")",
"{",
"var",
"newValue",
";",
"if",
"(",
"mergerResult",
"!==",
"undefined",
")",
"{",
"newValue",
"=",
"mergerResult",
";",
"}",
"else",
"if",
"(",
"deep",
"&&",
"isMergableObject",
"(",
"currentValue",
")",
"&&",
"isMergableObject",
"(",
"immutableValue",
")",
")",
"{",
"newValue",
"=",
"Immutable",
".",
"merge",
"(",
"currentValue",
",",
"immutableValue",
",",
"config",
")",
";",
"}",
"else",
"{",
"newValue",
"=",
"immutableValue",
";",
"}",
"if",
"(",
"!",
"isEqual",
"(",
"currentValue",
",",
"newValue",
")",
"||",
"!",
"currentObj",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"if",
"(",
"result",
"===",
"undefined",
")",
"{",
"// Make a shallow clone of the current object.",
"result",
"=",
"quickCopy",
"(",
"currentObj",
",",
"instantiateEmptyObject",
"(",
"currentObj",
")",
")",
";",
"}",
"result",
"[",
"key",
"]",
"=",
"newValue",
";",
"}",
"}",
"}"
] |
Use the given key to extract a value from the given object, then place that value in the result object under the same key. If that resulted in a change from this object's value at that key, set anyChanges = true.
|
[
"Use",
"the",
"given",
"key",
"to",
"extract",
"a",
"value",
"from",
"the",
"given",
"object",
"then",
"place",
"that",
"value",
"in",
"the",
"result",
"object",
"under",
"the",
"same",
"key",
".",
"If",
"that",
"resulted",
"in",
"a",
"change",
"from",
"this",
"object",
"s",
"value",
"at",
"that",
"key",
"set",
"anyChanges",
"=",
"true",
"."
] |
2d870b14a01e222493c686a7644181185f859558
|
https://github.com/rtfeldman/seamless-immutable/blob/2d870b14a01e222493c686a7644181185f859558/seamless-immutable.development.js#L393-L422
|
11,471
|
rtfeldman/seamless-immutable
|
seamless-immutable.development.js
|
makeImmutableObject
|
function makeImmutableObject(obj) {
if (!globalConfig.use_static) {
addPropertyTo(obj, "merge", merge);
addPropertyTo(obj, "replace", objectReplace);
addPropertyTo(obj, "without", without);
addPropertyTo(obj, "asMutable", asMutableObject);
addPropertyTo(obj, "set", objectSet);
addPropertyTo(obj, "setIn", objectSetIn);
addPropertyTo(obj, "update", update);
addPropertyTo(obj, "updateIn", updateIn);
addPropertyTo(obj, "getIn", getIn);
}
return makeImmutable(obj, mutatingObjectMethods);
}
|
javascript
|
function makeImmutableObject(obj) {
if (!globalConfig.use_static) {
addPropertyTo(obj, "merge", merge);
addPropertyTo(obj, "replace", objectReplace);
addPropertyTo(obj, "without", without);
addPropertyTo(obj, "asMutable", asMutableObject);
addPropertyTo(obj, "set", objectSet);
addPropertyTo(obj, "setIn", objectSetIn);
addPropertyTo(obj, "update", update);
addPropertyTo(obj, "updateIn", updateIn);
addPropertyTo(obj, "getIn", getIn);
}
return makeImmutable(obj, mutatingObjectMethods);
}
|
[
"function",
"makeImmutableObject",
"(",
"obj",
")",
"{",
"if",
"(",
"!",
"globalConfig",
".",
"use_static",
")",
"{",
"addPropertyTo",
"(",
"obj",
",",
"\"merge\"",
",",
"merge",
")",
";",
"addPropertyTo",
"(",
"obj",
",",
"\"replace\"",
",",
"objectReplace",
")",
";",
"addPropertyTo",
"(",
"obj",
",",
"\"without\"",
",",
"without",
")",
";",
"addPropertyTo",
"(",
"obj",
",",
"\"asMutable\"",
",",
"asMutableObject",
")",
";",
"addPropertyTo",
"(",
"obj",
",",
"\"set\"",
",",
"objectSet",
")",
";",
"addPropertyTo",
"(",
"obj",
",",
"\"setIn\"",
",",
"objectSetIn",
")",
";",
"addPropertyTo",
"(",
"obj",
",",
"\"update\"",
",",
"update",
")",
";",
"addPropertyTo",
"(",
"obj",
",",
"\"updateIn\"",
",",
"updateIn",
")",
";",
"addPropertyTo",
"(",
"obj",
",",
"\"getIn\"",
",",
"getIn",
")",
";",
"}",
"return",
"makeImmutable",
"(",
"obj",
",",
"mutatingObjectMethods",
")",
";",
"}"
] |
Finalizes an object with immutable methods, freezes it, and returns it.
|
[
"Finalizes",
"an",
"object",
"with",
"immutable",
"methods",
"freezes",
"it",
"and",
"returns",
"it",
"."
] |
2d870b14a01e222493c686a7644181185f859558
|
https://github.com/rtfeldman/seamless-immutable/blob/2d870b14a01e222493c686a7644181185f859558/seamless-immutable.development.js#L586-L600
|
11,472
|
rtfeldman/seamless-immutable
|
seamless-immutable.development.js
|
toStatic
|
function toStatic(fn) {
function staticWrapper() {
var args = [].slice.call(arguments);
var self = args.shift();
return fn.apply(self, args);
}
return staticWrapper;
}
|
javascript
|
function toStatic(fn) {
function staticWrapper() {
var args = [].slice.call(arguments);
var self = args.shift();
return fn.apply(self, args);
}
return staticWrapper;
}
|
[
"function",
"toStatic",
"(",
"fn",
")",
"{",
"function",
"staticWrapper",
"(",
")",
"{",
"var",
"args",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"var",
"self",
"=",
"args",
".",
"shift",
"(",
")",
";",
"return",
"fn",
".",
"apply",
"(",
"self",
",",
"args",
")",
";",
"}",
"return",
"staticWrapper",
";",
"}"
] |
Wrapper to allow the use of object methods as static methods of Immutable.
|
[
"Wrapper",
"to",
"allow",
"the",
"use",
"of",
"object",
"methods",
"as",
"static",
"methods",
"of",
"Immutable",
"."
] |
2d870b14a01e222493c686a7644181185f859558
|
https://github.com/rtfeldman/seamless-immutable/blob/2d870b14a01e222493c686a7644181185f859558/seamless-immutable.development.js#L670-L678
|
11,473
|
rtfeldman/seamless-immutable
|
seamless-immutable.development.js
|
toStaticObjectOrArray
|
function toStaticObjectOrArray(fnObject, fnArray) {
function staticWrapper() {
var args = [].slice.call(arguments);
var self = args.shift();
if (Array.isArray(self)) {
return fnArray.apply(self, args);
} else {
return fnObject.apply(self, args);
}
}
return staticWrapper;
}
|
javascript
|
function toStaticObjectOrArray(fnObject, fnArray) {
function staticWrapper() {
var args = [].slice.call(arguments);
var self = args.shift();
if (Array.isArray(self)) {
return fnArray.apply(self, args);
} else {
return fnObject.apply(self, args);
}
}
return staticWrapper;
}
|
[
"function",
"toStaticObjectOrArray",
"(",
"fnObject",
",",
"fnArray",
")",
"{",
"function",
"staticWrapper",
"(",
")",
"{",
"var",
"args",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"var",
"self",
"=",
"args",
".",
"shift",
"(",
")",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"self",
")",
")",
"{",
"return",
"fnArray",
".",
"apply",
"(",
"self",
",",
"args",
")",
";",
"}",
"else",
"{",
"return",
"fnObject",
".",
"apply",
"(",
"self",
",",
"args",
")",
";",
"}",
"}",
"return",
"staticWrapper",
";",
"}"
] |
Wrapper to allow the use of object methods as static methods of Immutable. with the additional condition of choosing which function to call depending if argument is an array or an object.
|
[
"Wrapper",
"to",
"allow",
"the",
"use",
"of",
"object",
"methods",
"as",
"static",
"methods",
"of",
"Immutable",
".",
"with",
"the",
"additional",
"condition",
"of",
"choosing",
"which",
"function",
"to",
"call",
"depending",
"if",
"argument",
"is",
"an",
"array",
"or",
"an",
"object",
"."
] |
2d870b14a01e222493c686a7644181185f859558
|
https://github.com/rtfeldman/seamless-immutable/blob/2d870b14a01e222493c686a7644181185f859558/seamless-immutable.development.js#L683-L695
|
11,474
|
angular-ui/ui-select
|
src/uiSelectController.js
|
function(){
var origSrc = originalSource($scope);
$scope.$uisSource = Object.keys(origSrc).map(function(v){
var result = {};
result[ctrl.parserResult.keyName] = v;
result.value = origSrc[v];
return result;
});
}
|
javascript
|
function(){
var origSrc = originalSource($scope);
$scope.$uisSource = Object.keys(origSrc).map(function(v){
var result = {};
result[ctrl.parserResult.keyName] = v;
result.value = origSrc[v];
return result;
});
}
|
[
"function",
"(",
")",
"{",
"var",
"origSrc",
"=",
"originalSource",
"(",
"$scope",
")",
";",
"$scope",
".",
"$uisSource",
"=",
"Object",
".",
"keys",
"(",
"origSrc",
")",
".",
"map",
"(",
"function",
"(",
"v",
")",
"{",
"var",
"result",
"=",
"{",
"}",
";",
"result",
"[",
"ctrl",
".",
"parserResult",
".",
"keyName",
"]",
"=",
"v",
";",
"result",
".",
"value",
"=",
"origSrc",
"[",
"v",
"]",
";",
"return",
"result",
";",
"}",
")",
";",
"}"
] |
When an object is used as source, we better create an array and use it as 'source'
|
[
"When",
"an",
"object",
"is",
"used",
"as",
"source",
"we",
"better",
"create",
"an",
"array",
"and",
"use",
"it",
"as",
"source"
] |
d8fed304ab7f7f8dfde1e8424ee2a572e31c7488
|
https://github.com/angular-ui/ui-select/blob/d8fed304ab7f7f8dfde1e8424ee2a572e31c7488/src/uiSelectController.js#L231-L239
|
|
11,475
|
angular-ui/ui-select
|
src/uiSelectMultipleDirective.js
|
_handleMatchSelection
|
function _handleMatchSelection(key){
var caretPosition = _getCaretPosition($select.searchInput[0]),
length = $select.selected.length,
// none = -1,
first = 0,
last = length-1,
curr = $selectMultiple.activeMatchIndex,
next = $selectMultiple.activeMatchIndex+1,
prev = $selectMultiple.activeMatchIndex-1,
newIndex = curr;
if(caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) return false;
$select.close();
function getNewActiveMatchIndex(){
switch(key){
case KEY.LEFT:
// Select previous/first item
if(~$selectMultiple.activeMatchIndex) return prev;
// Select last item
else return last;
break;
case KEY.RIGHT:
// Open drop-down
if(!~$selectMultiple.activeMatchIndex || curr === last){
$select.activate();
return false;
}
// Select next/last item
else return next;
break;
case KEY.BACKSPACE:
// Remove selected item and select previous/first
if(~$selectMultiple.activeMatchIndex){
if($selectMultiple.removeChoice(curr)) {
return prev;
} else {
return curr;
}
} else {
// If nothing yet selected, select last item
return last;
}
break;
case KEY.DELETE:
// Remove selected item and select next item
if(~$selectMultiple.activeMatchIndex){
$selectMultiple.removeChoice($selectMultiple.activeMatchIndex);
return curr;
}
else return false;
}
}
newIndex = getNewActiveMatchIndex();
if(!$select.selected.length || newIndex === false) $selectMultiple.activeMatchIndex = -1;
else $selectMultiple.activeMatchIndex = Math.min(last,Math.max(first,newIndex));
return true;
}
|
javascript
|
function _handleMatchSelection(key){
var caretPosition = _getCaretPosition($select.searchInput[0]),
length = $select.selected.length,
// none = -1,
first = 0,
last = length-1,
curr = $selectMultiple.activeMatchIndex,
next = $selectMultiple.activeMatchIndex+1,
prev = $selectMultiple.activeMatchIndex-1,
newIndex = curr;
if(caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) return false;
$select.close();
function getNewActiveMatchIndex(){
switch(key){
case KEY.LEFT:
// Select previous/first item
if(~$selectMultiple.activeMatchIndex) return prev;
// Select last item
else return last;
break;
case KEY.RIGHT:
// Open drop-down
if(!~$selectMultiple.activeMatchIndex || curr === last){
$select.activate();
return false;
}
// Select next/last item
else return next;
break;
case KEY.BACKSPACE:
// Remove selected item and select previous/first
if(~$selectMultiple.activeMatchIndex){
if($selectMultiple.removeChoice(curr)) {
return prev;
} else {
return curr;
}
} else {
// If nothing yet selected, select last item
return last;
}
break;
case KEY.DELETE:
// Remove selected item and select next item
if(~$selectMultiple.activeMatchIndex){
$selectMultiple.removeChoice($selectMultiple.activeMatchIndex);
return curr;
}
else return false;
}
}
newIndex = getNewActiveMatchIndex();
if(!$select.selected.length || newIndex === false) $selectMultiple.activeMatchIndex = -1;
else $selectMultiple.activeMatchIndex = Math.min(last,Math.max(first,newIndex));
return true;
}
|
[
"function",
"_handleMatchSelection",
"(",
"key",
")",
"{",
"var",
"caretPosition",
"=",
"_getCaretPosition",
"(",
"$select",
".",
"searchInput",
"[",
"0",
"]",
")",
",",
"length",
"=",
"$select",
".",
"selected",
".",
"length",
",",
"// none = -1,",
"first",
"=",
"0",
",",
"last",
"=",
"length",
"-",
"1",
",",
"curr",
"=",
"$selectMultiple",
".",
"activeMatchIndex",
",",
"next",
"=",
"$selectMultiple",
".",
"activeMatchIndex",
"+",
"1",
",",
"prev",
"=",
"$selectMultiple",
".",
"activeMatchIndex",
"-",
"1",
",",
"newIndex",
"=",
"curr",
";",
"if",
"(",
"caretPosition",
">",
"0",
"||",
"(",
"$select",
".",
"search",
".",
"length",
"&&",
"key",
"==",
"KEY",
".",
"RIGHT",
")",
")",
"return",
"false",
";",
"$select",
".",
"close",
"(",
")",
";",
"function",
"getNewActiveMatchIndex",
"(",
")",
"{",
"switch",
"(",
"key",
")",
"{",
"case",
"KEY",
".",
"LEFT",
":",
"// Select previous/first item",
"if",
"(",
"~",
"$selectMultiple",
".",
"activeMatchIndex",
")",
"return",
"prev",
";",
"// Select last item",
"else",
"return",
"last",
";",
"break",
";",
"case",
"KEY",
".",
"RIGHT",
":",
"// Open drop-down",
"if",
"(",
"!",
"~",
"$selectMultiple",
".",
"activeMatchIndex",
"||",
"curr",
"===",
"last",
")",
"{",
"$select",
".",
"activate",
"(",
")",
";",
"return",
"false",
";",
"}",
"// Select next/last item",
"else",
"return",
"next",
";",
"break",
";",
"case",
"KEY",
".",
"BACKSPACE",
":",
"// Remove selected item and select previous/first",
"if",
"(",
"~",
"$selectMultiple",
".",
"activeMatchIndex",
")",
"{",
"if",
"(",
"$selectMultiple",
".",
"removeChoice",
"(",
"curr",
")",
")",
"{",
"return",
"prev",
";",
"}",
"else",
"{",
"return",
"curr",
";",
"}",
"}",
"else",
"{",
"// If nothing yet selected, select last item",
"return",
"last",
";",
"}",
"break",
";",
"case",
"KEY",
".",
"DELETE",
":",
"// Remove selected item and select next item",
"if",
"(",
"~",
"$selectMultiple",
".",
"activeMatchIndex",
")",
"{",
"$selectMultiple",
".",
"removeChoice",
"(",
"$selectMultiple",
".",
"activeMatchIndex",
")",
";",
"return",
"curr",
";",
"}",
"else",
"return",
"false",
";",
"}",
"}",
"newIndex",
"=",
"getNewActiveMatchIndex",
"(",
")",
";",
"if",
"(",
"!",
"$select",
".",
"selected",
".",
"length",
"||",
"newIndex",
"===",
"false",
")",
"$selectMultiple",
".",
"activeMatchIndex",
"=",
"-",
"1",
";",
"else",
"$selectMultiple",
".",
"activeMatchIndex",
"=",
"Math",
".",
"min",
"(",
"last",
",",
"Math",
".",
"max",
"(",
"first",
",",
"newIndex",
")",
")",
";",
"return",
"true",
";",
"}"
] |
Handles selected options in "multiple" mode
|
[
"Handles",
"selected",
"options",
"in",
"multiple",
"mode"
] |
d8fed304ab7f7f8dfde1e8424ee2a572e31c7488
|
https://github.com/angular-ui/ui-select/blob/d8fed304ab7f7f8dfde1e8424ee2a572e31c7488/src/uiSelectMultipleDirective.js#L218-L280
|
11,476
|
jedfoster/Readmore.js
|
jquery.mockjax.js
|
parseXML
|
function parseXML(xml) {
if ( window.DOMParser == undefined && window.ActiveXObject ) {
DOMParser = function() { };
DOMParser.prototype.parseFromString = function( xmlString ) {
var doc = new ActiveXObject('Microsoft.XMLDOM');
doc.async = 'false';
doc.loadXML( xmlString );
return doc;
};
}
try {
var xmlDoc = ( new DOMParser() ).parseFromString( xml, 'text/xml' );
if ( $.isXMLDoc( xmlDoc ) ) {
var err = $('parsererror', xmlDoc);
if ( err.length == 1 ) {
throw new Error('Error: ' + $(xmlDoc).text() );
}
} else {
throw new Error('Unable to parse XML');
}
return xmlDoc;
} catch( e ) {
var msg = ( e.name == undefined ? e : e.name + ': ' + e.message );
$(document).trigger('xmlParseError', [ msg ]);
return undefined;
}
}
|
javascript
|
function parseXML(xml) {
if ( window.DOMParser == undefined && window.ActiveXObject ) {
DOMParser = function() { };
DOMParser.prototype.parseFromString = function( xmlString ) {
var doc = new ActiveXObject('Microsoft.XMLDOM');
doc.async = 'false';
doc.loadXML( xmlString );
return doc;
};
}
try {
var xmlDoc = ( new DOMParser() ).parseFromString( xml, 'text/xml' );
if ( $.isXMLDoc( xmlDoc ) ) {
var err = $('parsererror', xmlDoc);
if ( err.length == 1 ) {
throw new Error('Error: ' + $(xmlDoc).text() );
}
} else {
throw new Error('Unable to parse XML');
}
return xmlDoc;
} catch( e ) {
var msg = ( e.name == undefined ? e : e.name + ': ' + e.message );
$(document).trigger('xmlParseError', [ msg ]);
return undefined;
}
}
|
[
"function",
"parseXML",
"(",
"xml",
")",
"{",
"if",
"(",
"window",
".",
"DOMParser",
"==",
"undefined",
"&&",
"window",
".",
"ActiveXObject",
")",
"{",
"DOMParser",
"=",
"function",
"(",
")",
"{",
"}",
";",
"DOMParser",
".",
"prototype",
".",
"parseFromString",
"=",
"function",
"(",
"xmlString",
")",
"{",
"var",
"doc",
"=",
"new",
"ActiveXObject",
"(",
"'Microsoft.XMLDOM'",
")",
";",
"doc",
".",
"async",
"=",
"'false'",
";",
"doc",
".",
"loadXML",
"(",
"xmlString",
")",
";",
"return",
"doc",
";",
"}",
";",
"}",
"try",
"{",
"var",
"xmlDoc",
"=",
"(",
"new",
"DOMParser",
"(",
")",
")",
".",
"parseFromString",
"(",
"xml",
",",
"'text/xml'",
")",
";",
"if",
"(",
"$",
".",
"isXMLDoc",
"(",
"xmlDoc",
")",
")",
"{",
"var",
"err",
"=",
"$",
"(",
"'parsererror'",
",",
"xmlDoc",
")",
";",
"if",
"(",
"err",
".",
"length",
"==",
"1",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Error: '",
"+",
"$",
"(",
"xmlDoc",
")",
".",
"text",
"(",
")",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to parse XML'",
")",
";",
"}",
"return",
"xmlDoc",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"var",
"msg",
"=",
"(",
"e",
".",
"name",
"==",
"undefined",
"?",
"e",
":",
"e",
".",
"name",
"+",
"': '",
"+",
"e",
".",
"message",
")",
";",
"$",
"(",
"document",
")",
".",
"trigger",
"(",
"'xmlParseError'",
",",
"[",
"msg",
"]",
")",
";",
"return",
"undefined",
";",
"}",
"}"
] |
Parse the given XML string.
|
[
"Parse",
"the",
"given",
"XML",
"string",
"."
] |
d7fe38b8214fc5804219736008c8470953b082c0
|
https://github.com/jedfoster/Readmore.js/blob/d7fe38b8214fc5804219736008c8470953b082c0/jquery.mockjax.js#L26-L53
|
11,477
|
jedfoster/Readmore.js
|
jquery.mockjax.js
|
isMockDataEqual
|
function isMockDataEqual( mock, live ) {
var identical = true;
// Test for situations where the data is a querystring (not an object)
if (typeof live === 'string') {
// Querystring may be a regex
return $.isFunction( mock.test ) ? mock.test(live) : mock == live;
}
$.each(mock, function(k) {
if ( live[k] === undefined ) {
identical = false;
return identical;
} else {
if ( typeof live[k] === 'object' && live[k] !== null ) {
if ( identical && $.isArray( live[k] ) ) {
identical = $.isArray( mock[k] ) && live[k].length === mock[k].length;
}
identical = identical && isMockDataEqual(mock[k], live[k]);
} else {
if ( mock[k] && $.isFunction( mock[k].test ) ) {
identical = identical && mock[k].test(live[k]);
} else {
identical = identical && ( mock[k] == live[k] );
}
}
}
});
return identical;
}
|
javascript
|
function isMockDataEqual( mock, live ) {
var identical = true;
// Test for situations where the data is a querystring (not an object)
if (typeof live === 'string') {
// Querystring may be a regex
return $.isFunction( mock.test ) ? mock.test(live) : mock == live;
}
$.each(mock, function(k) {
if ( live[k] === undefined ) {
identical = false;
return identical;
} else {
if ( typeof live[k] === 'object' && live[k] !== null ) {
if ( identical && $.isArray( live[k] ) ) {
identical = $.isArray( mock[k] ) && live[k].length === mock[k].length;
}
identical = identical && isMockDataEqual(mock[k], live[k]);
} else {
if ( mock[k] && $.isFunction( mock[k].test ) ) {
identical = identical && mock[k].test(live[k]);
} else {
identical = identical && ( mock[k] == live[k] );
}
}
}
});
return identical;
}
|
[
"function",
"isMockDataEqual",
"(",
"mock",
",",
"live",
")",
"{",
"var",
"identical",
"=",
"true",
";",
"// Test for situations where the data is a querystring (not an object)",
"if",
"(",
"typeof",
"live",
"===",
"'string'",
")",
"{",
"// Querystring may be a regex",
"return",
"$",
".",
"isFunction",
"(",
"mock",
".",
"test",
")",
"?",
"mock",
".",
"test",
"(",
"live",
")",
":",
"mock",
"==",
"live",
";",
"}",
"$",
".",
"each",
"(",
"mock",
",",
"function",
"(",
"k",
")",
"{",
"if",
"(",
"live",
"[",
"k",
"]",
"===",
"undefined",
")",
"{",
"identical",
"=",
"false",
";",
"return",
"identical",
";",
"}",
"else",
"{",
"if",
"(",
"typeof",
"live",
"[",
"k",
"]",
"===",
"'object'",
"&&",
"live",
"[",
"k",
"]",
"!==",
"null",
")",
"{",
"if",
"(",
"identical",
"&&",
"$",
".",
"isArray",
"(",
"live",
"[",
"k",
"]",
")",
")",
"{",
"identical",
"=",
"$",
".",
"isArray",
"(",
"mock",
"[",
"k",
"]",
")",
"&&",
"live",
"[",
"k",
"]",
".",
"length",
"===",
"mock",
"[",
"k",
"]",
".",
"length",
";",
"}",
"identical",
"=",
"identical",
"&&",
"isMockDataEqual",
"(",
"mock",
"[",
"k",
"]",
",",
"live",
"[",
"k",
"]",
")",
";",
"}",
"else",
"{",
"if",
"(",
"mock",
"[",
"k",
"]",
"&&",
"$",
".",
"isFunction",
"(",
"mock",
"[",
"k",
"]",
".",
"test",
")",
")",
"{",
"identical",
"=",
"identical",
"&&",
"mock",
"[",
"k",
"]",
".",
"test",
"(",
"live",
"[",
"k",
"]",
")",
";",
"}",
"else",
"{",
"identical",
"=",
"identical",
"&&",
"(",
"mock",
"[",
"k",
"]",
"==",
"live",
"[",
"k",
"]",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"return",
"identical",
";",
"}"
] |
Check if the data field on the mock handler and the request match. This can be used to restrict a mock handler to being used only when a certain set of data is passed to it.
|
[
"Check",
"if",
"the",
"data",
"field",
"on",
"the",
"mock",
"handler",
"and",
"the",
"request",
"match",
".",
"This",
"can",
"be",
"used",
"to",
"restrict",
"a",
"mock",
"handler",
"to",
"being",
"used",
"only",
"when",
"a",
"certain",
"set",
"of",
"data",
"is",
"passed",
"to",
"it",
"."
] |
d7fe38b8214fc5804219736008c8470953b082c0
|
https://github.com/jedfoster/Readmore.js/blob/d7fe38b8214fc5804219736008c8470953b082c0/jquery.mockjax.js#L58-L86
|
11,478
|
jedfoster/Readmore.js
|
jquery.mockjax.js
|
getMockForRequest
|
function getMockForRequest( handler, requestSettings ) {
// If the mock was registered with a function, let the function decide if we
// want to mock this request
if ( $.isFunction(handler) ) {
return handler( requestSettings );
}
// Inspect the URL of the request and check if the mock handler's url
// matches the url for this ajax request
if ( $.isFunction(handler.url.test) ) {
// The user provided a regex for the url, test it
if ( !handler.url.test( requestSettings.url ) ) {
return null;
}
} else {
// Look for a simple wildcard '*' or a direct URL match
var star = handler.url.indexOf('*');
if (handler.url !== requestSettings.url && star === -1 ||
!new RegExp(handler.url.replace(/[-[\]{}()+?.,\\^$|#\s]/g, "\\$&").replace(/\*/g, '.+')).test(requestSettings.url)) {
return null;
}
}
// Inspect the data submitted in the request (either POST body or GET query string)
if ( handler.data ) {
if ( ! requestSettings.data || !isMockDataEqual(handler.data, requestSettings.data) ) {
// They're not identical, do not mock this request
return null;
}
}
// Inspect the request type
if ( handler && handler.type &&
handler.type.toLowerCase() != requestSettings.type.toLowerCase() ) {
// The request type doesn't match (GET vs. POST)
return null;
}
return handler;
}
|
javascript
|
function getMockForRequest( handler, requestSettings ) {
// If the mock was registered with a function, let the function decide if we
// want to mock this request
if ( $.isFunction(handler) ) {
return handler( requestSettings );
}
// Inspect the URL of the request and check if the mock handler's url
// matches the url for this ajax request
if ( $.isFunction(handler.url.test) ) {
// The user provided a regex for the url, test it
if ( !handler.url.test( requestSettings.url ) ) {
return null;
}
} else {
// Look for a simple wildcard '*' or a direct URL match
var star = handler.url.indexOf('*');
if (handler.url !== requestSettings.url && star === -1 ||
!new RegExp(handler.url.replace(/[-[\]{}()+?.,\\^$|#\s]/g, "\\$&").replace(/\*/g, '.+')).test(requestSettings.url)) {
return null;
}
}
// Inspect the data submitted in the request (either POST body or GET query string)
if ( handler.data ) {
if ( ! requestSettings.data || !isMockDataEqual(handler.data, requestSettings.data) ) {
// They're not identical, do not mock this request
return null;
}
}
// Inspect the request type
if ( handler && handler.type &&
handler.type.toLowerCase() != requestSettings.type.toLowerCase() ) {
// The request type doesn't match (GET vs. POST)
return null;
}
return handler;
}
|
[
"function",
"getMockForRequest",
"(",
"handler",
",",
"requestSettings",
")",
"{",
"// If the mock was registered with a function, let the function decide if we",
"// want to mock this request",
"if",
"(",
"$",
".",
"isFunction",
"(",
"handler",
")",
")",
"{",
"return",
"handler",
"(",
"requestSettings",
")",
";",
"}",
"// Inspect the URL of the request and check if the mock handler's url",
"// matches the url for this ajax request",
"if",
"(",
"$",
".",
"isFunction",
"(",
"handler",
".",
"url",
".",
"test",
")",
")",
"{",
"// The user provided a regex for the url, test it",
"if",
"(",
"!",
"handler",
".",
"url",
".",
"test",
"(",
"requestSettings",
".",
"url",
")",
")",
"{",
"return",
"null",
";",
"}",
"}",
"else",
"{",
"// Look for a simple wildcard '*' or a direct URL match",
"var",
"star",
"=",
"handler",
".",
"url",
".",
"indexOf",
"(",
"'*'",
")",
";",
"if",
"(",
"handler",
".",
"url",
"!==",
"requestSettings",
".",
"url",
"&&",
"star",
"===",
"-",
"1",
"||",
"!",
"new",
"RegExp",
"(",
"handler",
".",
"url",
".",
"replace",
"(",
"/",
"[-[\\]{}()+?.,\\\\^$|#\\s]",
"/",
"g",
",",
"\"\\\\$&\"",
")",
".",
"replace",
"(",
"/",
"\\*",
"/",
"g",
",",
"'.+'",
")",
")",
".",
"test",
"(",
"requestSettings",
".",
"url",
")",
")",
"{",
"return",
"null",
";",
"}",
"}",
"// Inspect the data submitted in the request (either POST body or GET query string)",
"if",
"(",
"handler",
".",
"data",
")",
"{",
"if",
"(",
"!",
"requestSettings",
".",
"data",
"||",
"!",
"isMockDataEqual",
"(",
"handler",
".",
"data",
",",
"requestSettings",
".",
"data",
")",
")",
"{",
"// They're not identical, do not mock this request",
"return",
"null",
";",
"}",
"}",
"// Inspect the request type",
"if",
"(",
"handler",
"&&",
"handler",
".",
"type",
"&&",
"handler",
".",
"type",
".",
"toLowerCase",
"(",
")",
"!=",
"requestSettings",
".",
"type",
".",
"toLowerCase",
"(",
")",
")",
"{",
"// The request type doesn't match (GET vs. POST)",
"return",
"null",
";",
"}",
"return",
"handler",
";",
"}"
] |
Check the given handler should mock the given request
|
[
"Check",
"the",
"given",
"handler",
"should",
"mock",
"the",
"given",
"request"
] |
d7fe38b8214fc5804219736008c8470953b082c0
|
https://github.com/jedfoster/Readmore.js/blob/d7fe38b8214fc5804219736008c8470953b082c0/jquery.mockjax.js#L94-L132
|
11,479
|
jedfoster/Readmore.js
|
jquery.mockjax.js
|
xhr
|
function xhr(mockHandler, requestSettings, origSettings, origHandler) {
// Extend with our default mockjax settings
mockHandler = $.extend(true, {}, $.mockjaxSettings, mockHandler);
if (typeof mockHandler.headers === 'undefined') {
mockHandler.headers = {};
}
if (typeof requestSettings.headers === 'undefined') {
requestSettings.headers = {};
}
if ( mockHandler.contentType ) {
mockHandler.headers['content-type'] = mockHandler.contentType;
}
return {
status: mockHandler.status,
statusText: mockHandler.statusText,
readyState: 1,
open: function() { },
send: function() {
origHandler.fired = true;
_xhrSend.call(this, mockHandler, requestSettings, origSettings);
},
abort: function() {
clearTimeout(this.responseTimer);
},
setRequestHeader: function(header, value) {
requestSettings.headers[header] = value;
},
getResponseHeader: function(header) {
// 'Last-modified', 'Etag', 'content-type' are all checked by jQuery
if ( mockHandler.headers && mockHandler.headers[header] ) {
// Return arbitrary headers
return mockHandler.headers[header];
} else if ( header.toLowerCase() == 'last-modified' ) {
return mockHandler.lastModified || (new Date()).toString();
} else if ( header.toLowerCase() == 'etag' ) {
return mockHandler.etag || '';
} else if ( header.toLowerCase() == 'content-type' ) {
return mockHandler.contentType || 'text/plain';
}
},
getAllResponseHeaders: function() {
var headers = '';
// since jQuery 1.9 responseText type has to match contentType
if (mockHandler.contentType) {
mockHandler.headers['Content-Type'] = mockHandler.contentType;
}
$.each(mockHandler.headers, function(k, v) {
headers += k + ': ' + v + "\n";
});
return headers;
}
};
}
|
javascript
|
function xhr(mockHandler, requestSettings, origSettings, origHandler) {
// Extend with our default mockjax settings
mockHandler = $.extend(true, {}, $.mockjaxSettings, mockHandler);
if (typeof mockHandler.headers === 'undefined') {
mockHandler.headers = {};
}
if (typeof requestSettings.headers === 'undefined') {
requestSettings.headers = {};
}
if ( mockHandler.contentType ) {
mockHandler.headers['content-type'] = mockHandler.contentType;
}
return {
status: mockHandler.status,
statusText: mockHandler.statusText,
readyState: 1,
open: function() { },
send: function() {
origHandler.fired = true;
_xhrSend.call(this, mockHandler, requestSettings, origSettings);
},
abort: function() {
clearTimeout(this.responseTimer);
},
setRequestHeader: function(header, value) {
requestSettings.headers[header] = value;
},
getResponseHeader: function(header) {
// 'Last-modified', 'Etag', 'content-type' are all checked by jQuery
if ( mockHandler.headers && mockHandler.headers[header] ) {
// Return arbitrary headers
return mockHandler.headers[header];
} else if ( header.toLowerCase() == 'last-modified' ) {
return mockHandler.lastModified || (new Date()).toString();
} else if ( header.toLowerCase() == 'etag' ) {
return mockHandler.etag || '';
} else if ( header.toLowerCase() == 'content-type' ) {
return mockHandler.contentType || 'text/plain';
}
},
getAllResponseHeaders: function() {
var headers = '';
// since jQuery 1.9 responseText type has to match contentType
if (mockHandler.contentType) {
mockHandler.headers['Content-Type'] = mockHandler.contentType;
}
$.each(mockHandler.headers, function(k, v) {
headers += k + ': ' + v + "\n";
});
return headers;
}
};
}
|
[
"function",
"xhr",
"(",
"mockHandler",
",",
"requestSettings",
",",
"origSettings",
",",
"origHandler",
")",
"{",
"// Extend with our default mockjax settings",
"mockHandler",
"=",
"$",
".",
"extend",
"(",
"true",
",",
"{",
"}",
",",
"$",
".",
"mockjaxSettings",
",",
"mockHandler",
")",
";",
"if",
"(",
"typeof",
"mockHandler",
".",
"headers",
"===",
"'undefined'",
")",
"{",
"mockHandler",
".",
"headers",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"typeof",
"requestSettings",
".",
"headers",
"===",
"'undefined'",
")",
"{",
"requestSettings",
".",
"headers",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"mockHandler",
".",
"contentType",
")",
"{",
"mockHandler",
".",
"headers",
"[",
"'content-type'",
"]",
"=",
"mockHandler",
".",
"contentType",
";",
"}",
"return",
"{",
"status",
":",
"mockHandler",
".",
"status",
",",
"statusText",
":",
"mockHandler",
".",
"statusText",
",",
"readyState",
":",
"1",
",",
"open",
":",
"function",
"(",
")",
"{",
"}",
",",
"send",
":",
"function",
"(",
")",
"{",
"origHandler",
".",
"fired",
"=",
"true",
";",
"_xhrSend",
".",
"call",
"(",
"this",
",",
"mockHandler",
",",
"requestSettings",
",",
"origSettings",
")",
";",
"}",
",",
"abort",
":",
"function",
"(",
")",
"{",
"clearTimeout",
"(",
"this",
".",
"responseTimer",
")",
";",
"}",
",",
"setRequestHeader",
":",
"function",
"(",
"header",
",",
"value",
")",
"{",
"requestSettings",
".",
"headers",
"[",
"header",
"]",
"=",
"value",
";",
"}",
",",
"getResponseHeader",
":",
"function",
"(",
"header",
")",
"{",
"// 'Last-modified', 'Etag', 'content-type' are all checked by jQuery",
"if",
"(",
"mockHandler",
".",
"headers",
"&&",
"mockHandler",
".",
"headers",
"[",
"header",
"]",
")",
"{",
"// Return arbitrary headers",
"return",
"mockHandler",
".",
"headers",
"[",
"header",
"]",
";",
"}",
"else",
"if",
"(",
"header",
".",
"toLowerCase",
"(",
")",
"==",
"'last-modified'",
")",
"{",
"return",
"mockHandler",
".",
"lastModified",
"||",
"(",
"new",
"Date",
"(",
")",
")",
".",
"toString",
"(",
")",
";",
"}",
"else",
"if",
"(",
"header",
".",
"toLowerCase",
"(",
")",
"==",
"'etag'",
")",
"{",
"return",
"mockHandler",
".",
"etag",
"||",
"''",
";",
"}",
"else",
"if",
"(",
"header",
".",
"toLowerCase",
"(",
")",
"==",
"'content-type'",
")",
"{",
"return",
"mockHandler",
".",
"contentType",
"||",
"'text/plain'",
";",
"}",
"}",
",",
"getAllResponseHeaders",
":",
"function",
"(",
")",
"{",
"var",
"headers",
"=",
"''",
";",
"// since jQuery 1.9 responseText type has to match contentType",
"if",
"(",
"mockHandler",
".",
"contentType",
")",
"{",
"mockHandler",
".",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"mockHandler",
".",
"contentType",
";",
"}",
"$",
".",
"each",
"(",
"mockHandler",
".",
"headers",
",",
"function",
"(",
"k",
",",
"v",
")",
"{",
"headers",
"+=",
"k",
"+",
"': '",
"+",
"v",
"+",
"\"\\n\"",
";",
"}",
")",
";",
"return",
"headers",
";",
"}",
"}",
";",
"}"
] |
Construct a mocked XHR Object
|
[
"Construct",
"a",
"mocked",
"XHR",
"Object"
] |
d7fe38b8214fc5804219736008c8470953b082c0
|
https://github.com/jedfoster/Readmore.js/blob/d7fe38b8214fc5804219736008c8470953b082c0/jquery.mockjax.js#L252-L306
|
11,480
|
jedfoster/Readmore.js
|
jquery.mockjax.js
|
processJsonpMock
|
function processJsonpMock( requestSettings, mockHandler, origSettings ) {
// Handle JSONP Parameter Callbacks, we need to replicate some of the jQuery core here
// because there isn't an easy hook for the cross domain script tag of jsonp
processJsonpUrl( requestSettings );
requestSettings.dataType = "json";
if(requestSettings.data && CALLBACK_REGEX.test(requestSettings.data) || CALLBACK_REGEX.test(requestSettings.url)) {
createJsonpCallback(requestSettings, mockHandler, origSettings);
// We need to make sure
// that a JSONP style response is executed properly
var rurl = /^(\w+:)?\/\/([^\/?#]+)/,
parts = rurl.exec( requestSettings.url ),
remote = parts && (parts[1] && parts[1] !== location.protocol || parts[2] !== location.host);
requestSettings.dataType = "script";
if(requestSettings.type.toUpperCase() === "GET" && remote ) {
var newMockReturn = processJsonpRequest( requestSettings, mockHandler, origSettings );
// Check if we are supposed to return a Deferred back to the mock call, or just
// signal success
if(newMockReturn) {
return newMockReturn;
} else {
return true;
}
}
}
return null;
}
|
javascript
|
function processJsonpMock( requestSettings, mockHandler, origSettings ) {
// Handle JSONP Parameter Callbacks, we need to replicate some of the jQuery core here
// because there isn't an easy hook for the cross domain script tag of jsonp
processJsonpUrl( requestSettings );
requestSettings.dataType = "json";
if(requestSettings.data && CALLBACK_REGEX.test(requestSettings.data) || CALLBACK_REGEX.test(requestSettings.url)) {
createJsonpCallback(requestSettings, mockHandler, origSettings);
// We need to make sure
// that a JSONP style response is executed properly
var rurl = /^(\w+:)?\/\/([^\/?#]+)/,
parts = rurl.exec( requestSettings.url ),
remote = parts && (parts[1] && parts[1] !== location.protocol || parts[2] !== location.host);
requestSettings.dataType = "script";
if(requestSettings.type.toUpperCase() === "GET" && remote ) {
var newMockReturn = processJsonpRequest( requestSettings, mockHandler, origSettings );
// Check if we are supposed to return a Deferred back to the mock call, or just
// signal success
if(newMockReturn) {
return newMockReturn;
} else {
return true;
}
}
}
return null;
}
|
[
"function",
"processJsonpMock",
"(",
"requestSettings",
",",
"mockHandler",
",",
"origSettings",
")",
"{",
"// Handle JSONP Parameter Callbacks, we need to replicate some of the jQuery core here",
"// because there isn't an easy hook for the cross domain script tag of jsonp",
"processJsonpUrl",
"(",
"requestSettings",
")",
";",
"requestSettings",
".",
"dataType",
"=",
"\"json\"",
";",
"if",
"(",
"requestSettings",
".",
"data",
"&&",
"CALLBACK_REGEX",
".",
"test",
"(",
"requestSettings",
".",
"data",
")",
"||",
"CALLBACK_REGEX",
".",
"test",
"(",
"requestSettings",
".",
"url",
")",
")",
"{",
"createJsonpCallback",
"(",
"requestSettings",
",",
"mockHandler",
",",
"origSettings",
")",
";",
"// We need to make sure",
"// that a JSONP style response is executed properly",
"var",
"rurl",
"=",
"/",
"^(\\w+:)?\\/\\/([^\\/?#]+)",
"/",
",",
"parts",
"=",
"rurl",
".",
"exec",
"(",
"requestSettings",
".",
"url",
")",
",",
"remote",
"=",
"parts",
"&&",
"(",
"parts",
"[",
"1",
"]",
"&&",
"parts",
"[",
"1",
"]",
"!==",
"location",
".",
"protocol",
"||",
"parts",
"[",
"2",
"]",
"!==",
"location",
".",
"host",
")",
";",
"requestSettings",
".",
"dataType",
"=",
"\"script\"",
";",
"if",
"(",
"requestSettings",
".",
"type",
".",
"toUpperCase",
"(",
")",
"===",
"\"GET\"",
"&&",
"remote",
")",
"{",
"var",
"newMockReturn",
"=",
"processJsonpRequest",
"(",
"requestSettings",
",",
"mockHandler",
",",
"origSettings",
")",
";",
"// Check if we are supposed to return a Deferred back to the mock call, or just",
"// signal success",
"if",
"(",
"newMockReturn",
")",
"{",
"return",
"newMockReturn",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] |
Process a JSONP mock request.
|
[
"Process",
"a",
"JSONP",
"mock",
"request",
"."
] |
d7fe38b8214fc5804219736008c8470953b082c0
|
https://github.com/jedfoster/Readmore.js/blob/d7fe38b8214fc5804219736008c8470953b082c0/jquery.mockjax.js#L309-L340
|
11,481
|
jedfoster/Readmore.js
|
jquery.mockjax.js
|
processJsonpUrl
|
function processJsonpUrl( requestSettings ) {
if ( requestSettings.type.toUpperCase() === "GET" ) {
if ( !CALLBACK_REGEX.test( requestSettings.url ) ) {
requestSettings.url += (/\?/.test( requestSettings.url ) ? "&" : "?") +
(requestSettings.jsonp || "callback") + "=?";
}
} else if ( !requestSettings.data || !CALLBACK_REGEX.test(requestSettings.data) ) {
requestSettings.data = (requestSettings.data ? requestSettings.data + "&" : "") + (requestSettings.jsonp || "callback") + "=?";
}
}
|
javascript
|
function processJsonpUrl( requestSettings ) {
if ( requestSettings.type.toUpperCase() === "GET" ) {
if ( !CALLBACK_REGEX.test( requestSettings.url ) ) {
requestSettings.url += (/\?/.test( requestSettings.url ) ? "&" : "?") +
(requestSettings.jsonp || "callback") + "=?";
}
} else if ( !requestSettings.data || !CALLBACK_REGEX.test(requestSettings.data) ) {
requestSettings.data = (requestSettings.data ? requestSettings.data + "&" : "") + (requestSettings.jsonp || "callback") + "=?";
}
}
|
[
"function",
"processJsonpUrl",
"(",
"requestSettings",
")",
"{",
"if",
"(",
"requestSettings",
".",
"type",
".",
"toUpperCase",
"(",
")",
"===",
"\"GET\"",
")",
"{",
"if",
"(",
"!",
"CALLBACK_REGEX",
".",
"test",
"(",
"requestSettings",
".",
"url",
")",
")",
"{",
"requestSettings",
".",
"url",
"+=",
"(",
"/",
"\\?",
"/",
".",
"test",
"(",
"requestSettings",
".",
"url",
")",
"?",
"\"&\"",
":",
"\"?\"",
")",
"+",
"(",
"requestSettings",
".",
"jsonp",
"||",
"\"callback\"",
")",
"+",
"\"=?\"",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"requestSettings",
".",
"data",
"||",
"!",
"CALLBACK_REGEX",
".",
"test",
"(",
"requestSettings",
".",
"data",
")",
")",
"{",
"requestSettings",
".",
"data",
"=",
"(",
"requestSettings",
".",
"data",
"?",
"requestSettings",
".",
"data",
"+",
"\"&\"",
":",
"\"\"",
")",
"+",
"(",
"requestSettings",
".",
"jsonp",
"||",
"\"callback\"",
")",
"+",
"\"=?\"",
";",
"}",
"}"
] |
Append the required callback parameter to the end of the request URL, for a JSONP request
|
[
"Append",
"the",
"required",
"callback",
"parameter",
"to",
"the",
"end",
"of",
"the",
"request",
"URL",
"for",
"a",
"JSONP",
"request"
] |
d7fe38b8214fc5804219736008c8470953b082c0
|
https://github.com/jedfoster/Readmore.js/blob/d7fe38b8214fc5804219736008c8470953b082c0/jquery.mockjax.js#L343-L352
|
11,482
|
jedfoster/Readmore.js
|
jquery.mockjax.js
|
processJsonpRequest
|
function processJsonpRequest( requestSettings, mockHandler, origSettings ) {
// Synthesize the mock request for adding a script tag
var callbackContext = origSettings && origSettings.context || requestSettings,
newMock = null;
// If the response handler on the moock is a function, call it
if ( mockHandler.response && $.isFunction(mockHandler.response) ) {
mockHandler.response(origSettings);
} else {
// Evaluate the responseText javascript in a global context
if( typeof mockHandler.responseText === 'object' ) {
$.globalEval( '(' + JSON.stringify( mockHandler.responseText ) + ')');
} else {
$.globalEval( '(' + mockHandler.responseText + ')');
}
}
// Successful response
setTimeout(function() {
jsonpSuccess( requestSettings, callbackContext, mockHandler );
jsonpComplete( requestSettings, callbackContext, mockHandler );
}, parseResponseTimeOpt(mockHandler.responseTime) || 0);
// If we are running under jQuery 1.5+, return a deferred object
if($.Deferred){
newMock = new $.Deferred();
if(typeof mockHandler.responseText == "object"){
newMock.resolveWith( callbackContext, [mockHandler.responseText] );
}
else{
newMock.resolveWith( callbackContext, [$.parseJSON( mockHandler.responseText )] );
}
}
return newMock;
}
|
javascript
|
function processJsonpRequest( requestSettings, mockHandler, origSettings ) {
// Synthesize the mock request for adding a script tag
var callbackContext = origSettings && origSettings.context || requestSettings,
newMock = null;
// If the response handler on the moock is a function, call it
if ( mockHandler.response && $.isFunction(mockHandler.response) ) {
mockHandler.response(origSettings);
} else {
// Evaluate the responseText javascript in a global context
if( typeof mockHandler.responseText === 'object' ) {
$.globalEval( '(' + JSON.stringify( mockHandler.responseText ) + ')');
} else {
$.globalEval( '(' + mockHandler.responseText + ')');
}
}
// Successful response
setTimeout(function() {
jsonpSuccess( requestSettings, callbackContext, mockHandler );
jsonpComplete( requestSettings, callbackContext, mockHandler );
}, parseResponseTimeOpt(mockHandler.responseTime) || 0);
// If we are running under jQuery 1.5+, return a deferred object
if($.Deferred){
newMock = new $.Deferred();
if(typeof mockHandler.responseText == "object"){
newMock.resolveWith( callbackContext, [mockHandler.responseText] );
}
else{
newMock.resolveWith( callbackContext, [$.parseJSON( mockHandler.responseText )] );
}
}
return newMock;
}
|
[
"function",
"processJsonpRequest",
"(",
"requestSettings",
",",
"mockHandler",
",",
"origSettings",
")",
"{",
"// Synthesize the mock request for adding a script tag",
"var",
"callbackContext",
"=",
"origSettings",
"&&",
"origSettings",
".",
"context",
"||",
"requestSettings",
",",
"newMock",
"=",
"null",
";",
"// If the response handler on the moock is a function, call it",
"if",
"(",
"mockHandler",
".",
"response",
"&&",
"$",
".",
"isFunction",
"(",
"mockHandler",
".",
"response",
")",
")",
"{",
"mockHandler",
".",
"response",
"(",
"origSettings",
")",
";",
"}",
"else",
"{",
"// Evaluate the responseText javascript in a global context",
"if",
"(",
"typeof",
"mockHandler",
".",
"responseText",
"===",
"'object'",
")",
"{",
"$",
".",
"globalEval",
"(",
"'('",
"+",
"JSON",
".",
"stringify",
"(",
"mockHandler",
".",
"responseText",
")",
"+",
"')'",
")",
";",
"}",
"else",
"{",
"$",
".",
"globalEval",
"(",
"'('",
"+",
"mockHandler",
".",
"responseText",
"+",
"')'",
")",
";",
"}",
"}",
"// Successful response",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"jsonpSuccess",
"(",
"requestSettings",
",",
"callbackContext",
",",
"mockHandler",
")",
";",
"jsonpComplete",
"(",
"requestSettings",
",",
"callbackContext",
",",
"mockHandler",
")",
";",
"}",
",",
"parseResponseTimeOpt",
"(",
"mockHandler",
".",
"responseTime",
")",
"||",
"0",
")",
";",
"// If we are running under jQuery 1.5+, return a deferred object",
"if",
"(",
"$",
".",
"Deferred",
")",
"{",
"newMock",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"if",
"(",
"typeof",
"mockHandler",
".",
"responseText",
"==",
"\"object\"",
")",
"{",
"newMock",
".",
"resolveWith",
"(",
"callbackContext",
",",
"[",
"mockHandler",
".",
"responseText",
"]",
")",
";",
"}",
"else",
"{",
"newMock",
".",
"resolveWith",
"(",
"callbackContext",
",",
"[",
"$",
".",
"parseJSON",
"(",
"mockHandler",
".",
"responseText",
")",
"]",
")",
";",
"}",
"}",
"return",
"newMock",
";",
"}"
] |
Process a JSONP request by evaluating the mocked response text
|
[
"Process",
"a",
"JSONP",
"request",
"by",
"evaluating",
"the",
"mocked",
"response",
"text"
] |
d7fe38b8214fc5804219736008c8470953b082c0
|
https://github.com/jedfoster/Readmore.js/blob/d7fe38b8214fc5804219736008c8470953b082c0/jquery.mockjax.js#L355-L391
|
11,483
|
jedfoster/Readmore.js
|
jquery.mockjax.js
|
createJsonpCallback
|
function createJsonpCallback( requestSettings, mockHandler, origSettings ) {
var callbackContext = origSettings && origSettings.context || requestSettings;
var jsonp = requestSettings.jsonpCallback || ("jsonp" + jsc++);
// Replace the =? sequence both in the query string and the data
if ( requestSettings.data ) {
requestSettings.data = (requestSettings.data + "").replace(CALLBACK_REGEX, "=" + jsonp + "$1");
}
requestSettings.url = requestSettings.url.replace(CALLBACK_REGEX, "=" + jsonp + "$1");
// Handle JSONP-style loading
window[ jsonp ] = window[ jsonp ] || function( tmp ) {
data = tmp;
jsonpSuccess( requestSettings, callbackContext, mockHandler );
jsonpComplete( requestSettings, callbackContext, mockHandler );
// Garbage collect
window[ jsonp ] = undefined;
try {
delete window[ jsonp ];
} catch(e) {}
if ( head ) {
head.removeChild( script );
}
};
}
|
javascript
|
function createJsonpCallback( requestSettings, mockHandler, origSettings ) {
var callbackContext = origSettings && origSettings.context || requestSettings;
var jsonp = requestSettings.jsonpCallback || ("jsonp" + jsc++);
// Replace the =? sequence both in the query string and the data
if ( requestSettings.data ) {
requestSettings.data = (requestSettings.data + "").replace(CALLBACK_REGEX, "=" + jsonp + "$1");
}
requestSettings.url = requestSettings.url.replace(CALLBACK_REGEX, "=" + jsonp + "$1");
// Handle JSONP-style loading
window[ jsonp ] = window[ jsonp ] || function( tmp ) {
data = tmp;
jsonpSuccess( requestSettings, callbackContext, mockHandler );
jsonpComplete( requestSettings, callbackContext, mockHandler );
// Garbage collect
window[ jsonp ] = undefined;
try {
delete window[ jsonp ];
} catch(e) {}
if ( head ) {
head.removeChild( script );
}
};
}
|
[
"function",
"createJsonpCallback",
"(",
"requestSettings",
",",
"mockHandler",
",",
"origSettings",
")",
"{",
"var",
"callbackContext",
"=",
"origSettings",
"&&",
"origSettings",
".",
"context",
"||",
"requestSettings",
";",
"var",
"jsonp",
"=",
"requestSettings",
".",
"jsonpCallback",
"||",
"(",
"\"jsonp\"",
"+",
"jsc",
"++",
")",
";",
"// Replace the =? sequence both in the query string and the data",
"if",
"(",
"requestSettings",
".",
"data",
")",
"{",
"requestSettings",
".",
"data",
"=",
"(",
"requestSettings",
".",
"data",
"+",
"\"\"",
")",
".",
"replace",
"(",
"CALLBACK_REGEX",
",",
"\"=\"",
"+",
"jsonp",
"+",
"\"$1\"",
")",
";",
"}",
"requestSettings",
".",
"url",
"=",
"requestSettings",
".",
"url",
".",
"replace",
"(",
"CALLBACK_REGEX",
",",
"\"=\"",
"+",
"jsonp",
"+",
"\"$1\"",
")",
";",
"// Handle JSONP-style loading",
"window",
"[",
"jsonp",
"]",
"=",
"window",
"[",
"jsonp",
"]",
"||",
"function",
"(",
"tmp",
")",
"{",
"data",
"=",
"tmp",
";",
"jsonpSuccess",
"(",
"requestSettings",
",",
"callbackContext",
",",
"mockHandler",
")",
";",
"jsonpComplete",
"(",
"requestSettings",
",",
"callbackContext",
",",
"mockHandler",
")",
";",
"// Garbage collect",
"window",
"[",
"jsonp",
"]",
"=",
"undefined",
";",
"try",
"{",
"delete",
"window",
"[",
"jsonp",
"]",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"if",
"(",
"head",
")",
"{",
"head",
".",
"removeChild",
"(",
"script",
")",
";",
"}",
"}",
";",
"}"
] |
Create the required JSONP callback function for the request
|
[
"Create",
"the",
"required",
"JSONP",
"callback",
"function",
"for",
"the",
"request"
] |
d7fe38b8214fc5804219736008c8470953b082c0
|
https://github.com/jedfoster/Readmore.js/blob/d7fe38b8214fc5804219736008c8470953b082c0/jquery.mockjax.js#L395-L423
|
11,484
|
jedfoster/Readmore.js
|
jquery.mockjax.js
|
jsonpSuccess
|
function jsonpSuccess(requestSettings, callbackContext, mockHandler) {
// If a local callback was specified, fire it and pass it the data
if ( requestSettings.success ) {
requestSettings.success.call( callbackContext, mockHandler.responseText || "", status, {} );
}
// Fire the global callback
if ( requestSettings.global ) {
(requestSettings.context ? $(requestSettings.context) : $.event).trigger("ajaxSuccess", [{}, requestSettings]);
}
}
|
javascript
|
function jsonpSuccess(requestSettings, callbackContext, mockHandler) {
// If a local callback was specified, fire it and pass it the data
if ( requestSettings.success ) {
requestSettings.success.call( callbackContext, mockHandler.responseText || "", status, {} );
}
// Fire the global callback
if ( requestSettings.global ) {
(requestSettings.context ? $(requestSettings.context) : $.event).trigger("ajaxSuccess", [{}, requestSettings]);
}
}
|
[
"function",
"jsonpSuccess",
"(",
"requestSettings",
",",
"callbackContext",
",",
"mockHandler",
")",
"{",
"// If a local callback was specified, fire it and pass it the data",
"if",
"(",
"requestSettings",
".",
"success",
")",
"{",
"requestSettings",
".",
"success",
".",
"call",
"(",
"callbackContext",
",",
"mockHandler",
".",
"responseText",
"||",
"\"\"",
",",
"status",
",",
"{",
"}",
")",
";",
"}",
"// Fire the global callback",
"if",
"(",
"requestSettings",
".",
"global",
")",
"{",
"(",
"requestSettings",
".",
"context",
"?",
"$",
"(",
"requestSettings",
".",
"context",
")",
":",
"$",
".",
"event",
")",
".",
"trigger",
"(",
"\"ajaxSuccess\"",
",",
"[",
"{",
"}",
",",
"requestSettings",
"]",
")",
";",
"}",
"}"
] |
The JSONP request was successful
|
[
"The",
"JSONP",
"request",
"was",
"successful"
] |
d7fe38b8214fc5804219736008c8470953b082c0
|
https://github.com/jedfoster/Readmore.js/blob/d7fe38b8214fc5804219736008c8470953b082c0/jquery.mockjax.js#L426-L436
|
11,485
|
jedfoster/Readmore.js
|
jquery.mockjax.js
|
jsonpComplete
|
function jsonpComplete(requestSettings, callbackContext) {
// Process result
if ( requestSettings.complete ) {
requestSettings.complete.call( callbackContext, {} , status );
}
// The request was completed
if ( requestSettings.global ) {
(requestSettings.context ? $(requestSettings.context) : $.event).trigger("ajaxComplete", [{}, requestSettings]);
}
// Handle the global AJAX counter
if ( requestSettings.global && ! --$.active ) {
$.event.trigger( "ajaxStop" );
}
}
|
javascript
|
function jsonpComplete(requestSettings, callbackContext) {
// Process result
if ( requestSettings.complete ) {
requestSettings.complete.call( callbackContext, {} , status );
}
// The request was completed
if ( requestSettings.global ) {
(requestSettings.context ? $(requestSettings.context) : $.event).trigger("ajaxComplete", [{}, requestSettings]);
}
// Handle the global AJAX counter
if ( requestSettings.global && ! --$.active ) {
$.event.trigger( "ajaxStop" );
}
}
|
[
"function",
"jsonpComplete",
"(",
"requestSettings",
",",
"callbackContext",
")",
"{",
"// Process result",
"if",
"(",
"requestSettings",
".",
"complete",
")",
"{",
"requestSettings",
".",
"complete",
".",
"call",
"(",
"callbackContext",
",",
"{",
"}",
",",
"status",
")",
";",
"}",
"// The request was completed",
"if",
"(",
"requestSettings",
".",
"global",
")",
"{",
"(",
"requestSettings",
".",
"context",
"?",
"$",
"(",
"requestSettings",
".",
"context",
")",
":",
"$",
".",
"event",
")",
".",
"trigger",
"(",
"\"ajaxComplete\"",
",",
"[",
"{",
"}",
",",
"requestSettings",
"]",
")",
";",
"}",
"// Handle the global AJAX counter",
"if",
"(",
"requestSettings",
".",
"global",
"&&",
"!",
"--",
"$",
".",
"active",
")",
"{",
"$",
".",
"event",
".",
"trigger",
"(",
"\"ajaxStop\"",
")",
";",
"}",
"}"
] |
The JSONP request was completed
|
[
"The",
"JSONP",
"request",
"was",
"completed"
] |
d7fe38b8214fc5804219736008c8470953b082c0
|
https://github.com/jedfoster/Readmore.js/blob/d7fe38b8214fc5804219736008c8470953b082c0/jquery.mockjax.js#L439-L454
|
11,486
|
jedfoster/Readmore.js
|
jquery.mockjax.js
|
copyUrlParameters
|
function copyUrlParameters(mockHandler, origSettings) {
//parameters aren't captured if the URL isn't a RegExp
if (!(mockHandler.url instanceof RegExp)) {
return;
}
//if no URL params were defined on the handler, don't attempt a capture
if (!mockHandler.hasOwnProperty('urlParams')) {
return;
}
var captures = mockHandler.url.exec(origSettings.url);
//the whole RegExp match is always the first value in the capture results
if (captures.length === 1) {
return;
}
captures.shift();
//use handler params as keys and capture resuts as values
var i = 0,
capturesLength = captures.length,
paramsLength = mockHandler.urlParams.length,
//in case the number of params specified is less than actual captures
maxIterations = Math.min(capturesLength, paramsLength),
paramValues = {};
for (i; i < maxIterations; i++) {
var key = mockHandler.urlParams[i];
paramValues[key] = captures[i];
}
origSettings.urlParams = paramValues;
}
|
javascript
|
function copyUrlParameters(mockHandler, origSettings) {
//parameters aren't captured if the URL isn't a RegExp
if (!(mockHandler.url instanceof RegExp)) {
return;
}
//if no URL params were defined on the handler, don't attempt a capture
if (!mockHandler.hasOwnProperty('urlParams')) {
return;
}
var captures = mockHandler.url.exec(origSettings.url);
//the whole RegExp match is always the first value in the capture results
if (captures.length === 1) {
return;
}
captures.shift();
//use handler params as keys and capture resuts as values
var i = 0,
capturesLength = captures.length,
paramsLength = mockHandler.urlParams.length,
//in case the number of params specified is less than actual captures
maxIterations = Math.min(capturesLength, paramsLength),
paramValues = {};
for (i; i < maxIterations; i++) {
var key = mockHandler.urlParams[i];
paramValues[key] = captures[i];
}
origSettings.urlParams = paramValues;
}
|
[
"function",
"copyUrlParameters",
"(",
"mockHandler",
",",
"origSettings",
")",
"{",
"//parameters aren't captured if the URL isn't a RegExp",
"if",
"(",
"!",
"(",
"mockHandler",
".",
"url",
"instanceof",
"RegExp",
")",
")",
"{",
"return",
";",
"}",
"//if no URL params were defined on the handler, don't attempt a capture",
"if",
"(",
"!",
"mockHandler",
".",
"hasOwnProperty",
"(",
"'urlParams'",
")",
")",
"{",
"return",
";",
"}",
"var",
"captures",
"=",
"mockHandler",
".",
"url",
".",
"exec",
"(",
"origSettings",
".",
"url",
")",
";",
"//the whole RegExp match is always the first value in the capture results",
"if",
"(",
"captures",
".",
"length",
"===",
"1",
")",
"{",
"return",
";",
"}",
"captures",
".",
"shift",
"(",
")",
";",
"//use handler params as keys and capture resuts as values",
"var",
"i",
"=",
"0",
",",
"capturesLength",
"=",
"captures",
".",
"length",
",",
"paramsLength",
"=",
"mockHandler",
".",
"urlParams",
".",
"length",
",",
"//in case the number of params specified is less than actual captures",
"maxIterations",
"=",
"Math",
".",
"min",
"(",
"capturesLength",
",",
"paramsLength",
")",
",",
"paramValues",
"=",
"{",
"}",
";",
"for",
"(",
"i",
";",
"i",
"<",
"maxIterations",
";",
"i",
"++",
")",
"{",
"var",
"key",
"=",
"mockHandler",
".",
"urlParams",
"[",
"i",
"]",
";",
"paramValues",
"[",
"key",
"]",
"=",
"captures",
"[",
"i",
"]",
";",
"}",
"origSettings",
".",
"urlParams",
"=",
"paramValues",
";",
"}"
] |
Copies URL parameter values if they were captured by a regular expression
@param {Object} mockHandler
@param {Object} origSettings
|
[
"Copies",
"URL",
"parameter",
"values",
"if",
"they",
"were",
"captured",
"by",
"a",
"regular",
"expression"
] |
d7fe38b8214fc5804219736008c8470953b082c0
|
https://github.com/jedfoster/Readmore.js/blob/d7fe38b8214fc5804219736008c8470953b082c0/jquery.mockjax.js#L572-L599
|
11,487
|
marceljuenemann/angular-drag-and-drop-lists
|
angular-drag-and-drop-lists.js
|
getMimeType
|
function getMimeType(types) {
if (!types) return MSIE_MIME_TYPE; // IE 9 workaround.
for (var i = 0; i < types.length; i++) {
if (types[i] == MSIE_MIME_TYPE || types[i] == EDGE_MIME_TYPE ||
types[i].substr(0, MIME_TYPE.length) == MIME_TYPE) {
return types[i];
}
}
return null;
}
|
javascript
|
function getMimeType(types) {
if (!types) return MSIE_MIME_TYPE; // IE 9 workaround.
for (var i = 0; i < types.length; i++) {
if (types[i] == MSIE_MIME_TYPE || types[i] == EDGE_MIME_TYPE ||
types[i].substr(0, MIME_TYPE.length) == MIME_TYPE) {
return types[i];
}
}
return null;
}
|
[
"function",
"getMimeType",
"(",
"types",
")",
"{",
"if",
"(",
"!",
"types",
")",
"return",
"MSIE_MIME_TYPE",
";",
"// IE 9 workaround.",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"types",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"types",
"[",
"i",
"]",
"==",
"MSIE_MIME_TYPE",
"||",
"types",
"[",
"i",
"]",
"==",
"EDGE_MIME_TYPE",
"||",
"types",
"[",
"i",
"]",
".",
"substr",
"(",
"0",
",",
"MIME_TYPE",
".",
"length",
")",
"==",
"MIME_TYPE",
")",
"{",
"return",
"types",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Given the types array from the DataTransfer object, returns the first valid mime type.
A type is valid if it starts with MIME_TYPE, or it equals MSIE_MIME_TYPE or EDGE_MIME_TYPE.
|
[
"Given",
"the",
"types",
"array",
"from",
"the",
"DataTransfer",
"object",
"returns",
"the",
"first",
"valid",
"mime",
"type",
".",
"A",
"type",
"is",
"valid",
"if",
"it",
"starts",
"with",
"MIME_TYPE",
"or",
"it",
"equals",
"MSIE_MIME_TYPE",
"or",
"EDGE_MIME_TYPE",
"."
] |
7e98e194a8d66fa735bf6dc7c3e39886287b914e
|
https://github.com/marceljuenemann/angular-drag-and-drop-lists/blob/7e98e194a8d66fa735bf6dc7c3e39886287b914e/angular-drag-and-drop-lists.js#L454-L463
|
11,488
|
marceljuenemann/angular-drag-and-drop-lists
|
angular-drag-and-drop-lists.js
|
getItemType
|
function getItemType(mimeType) {
if (dndState.isDragging) return dndState.itemType || undefined;
if (mimeType == MSIE_MIME_TYPE || mimeType == EDGE_MIME_TYPE) return null;
return (mimeType && mimeType.substr(MIME_TYPE.length + 1)) || undefined;
}
|
javascript
|
function getItemType(mimeType) {
if (dndState.isDragging) return dndState.itemType || undefined;
if (mimeType == MSIE_MIME_TYPE || mimeType == EDGE_MIME_TYPE) return null;
return (mimeType && mimeType.substr(MIME_TYPE.length + 1)) || undefined;
}
|
[
"function",
"getItemType",
"(",
"mimeType",
")",
"{",
"if",
"(",
"dndState",
".",
"isDragging",
")",
"return",
"dndState",
".",
"itemType",
"||",
"undefined",
";",
"if",
"(",
"mimeType",
"==",
"MSIE_MIME_TYPE",
"||",
"mimeType",
"==",
"EDGE_MIME_TYPE",
")",
"return",
"null",
";",
"return",
"(",
"mimeType",
"&&",
"mimeType",
".",
"substr",
"(",
"MIME_TYPE",
".",
"length",
"+",
"1",
")",
")",
"||",
"undefined",
";",
"}"
] |
Determines the type of the item from the dndState, or from the mime type for items from
external sources. Returns undefined if no item type was set and null if the item type could
not be determined.
|
[
"Determines",
"the",
"type",
"of",
"the",
"item",
"from",
"the",
"dndState",
"or",
"from",
"the",
"mime",
"type",
"for",
"items",
"from",
"external",
"sources",
".",
"Returns",
"undefined",
"if",
"no",
"item",
"type",
"was",
"set",
"and",
"null",
"if",
"the",
"item",
"type",
"could",
"not",
"be",
"determined",
"."
] |
7e98e194a8d66fa735bf6dc7c3e39886287b914e
|
https://github.com/marceljuenemann/angular-drag-and-drop-lists/blob/7e98e194a8d66fa735bf6dc7c3e39886287b914e/angular-drag-and-drop-lists.js#L470-L474
|
11,489
|
marceljuenemann/angular-drag-and-drop-lists
|
angular-drag-and-drop-lists.js
|
getPlaceholderElement
|
function getPlaceholderElement() {
var placeholder;
angular.forEach(element.children(), function(childNode) {
var child = angular.element(childNode);
if (child.hasClass('dndPlaceholder')) {
placeholder = child;
}
});
return placeholder || angular.element("<li class='dndPlaceholder'></li>");
}
|
javascript
|
function getPlaceholderElement() {
var placeholder;
angular.forEach(element.children(), function(childNode) {
var child = angular.element(childNode);
if (child.hasClass('dndPlaceholder')) {
placeholder = child;
}
});
return placeholder || angular.element("<li class='dndPlaceholder'></li>");
}
|
[
"function",
"getPlaceholderElement",
"(",
")",
"{",
"var",
"placeholder",
";",
"angular",
".",
"forEach",
"(",
"element",
".",
"children",
"(",
")",
",",
"function",
"(",
"childNode",
")",
"{",
"var",
"child",
"=",
"angular",
".",
"element",
"(",
"childNode",
")",
";",
"if",
"(",
"child",
".",
"hasClass",
"(",
"'dndPlaceholder'",
")",
")",
"{",
"placeholder",
"=",
"child",
";",
"}",
"}",
")",
";",
"return",
"placeholder",
"||",
"angular",
".",
"element",
"(",
"\"<li class='dndPlaceholder'></li>\"",
")",
";",
"}"
] |
Tries to find a child element that has the dndPlaceholder class set. If none was found, a
new li element is created.
|
[
"Tries",
"to",
"find",
"a",
"child",
"element",
"that",
"has",
"the",
"dndPlaceholder",
"class",
"set",
".",
"If",
"none",
"was",
"found",
"a",
"new",
"li",
"element",
"is",
"created",
"."
] |
7e98e194a8d66fa735bf6dc7c3e39886287b914e
|
https://github.com/marceljuenemann/angular-drag-and-drop-lists/blob/7e98e194a8d66fa735bf6dc7c3e39886287b914e/angular-drag-and-drop-lists.js#L553-L562
|
11,490
|
marceljuenemann/angular-drag-and-drop-lists
|
angular-drag-and-drop-lists.js
|
filterEffects
|
function filterEffects(effects, effectAllowed) {
if (effectAllowed == 'all') return effects;
return effects.filter(function(effect) {
return effectAllowed.toLowerCase().indexOf(effect) != -1;
});
}
|
javascript
|
function filterEffects(effects, effectAllowed) {
if (effectAllowed == 'all') return effects;
return effects.filter(function(effect) {
return effectAllowed.toLowerCase().indexOf(effect) != -1;
});
}
|
[
"function",
"filterEffects",
"(",
"effects",
",",
"effectAllowed",
")",
"{",
"if",
"(",
"effectAllowed",
"==",
"'all'",
")",
"return",
"effects",
";",
"return",
"effects",
".",
"filter",
"(",
"function",
"(",
"effect",
")",
"{",
"return",
"effectAllowed",
".",
"toLowerCase",
"(",
")",
".",
"indexOf",
"(",
"effect",
")",
"!=",
"-",
"1",
";",
"}",
")",
";",
"}"
] |
Filters an array of drop effects using a HTML5 effectAllowed string.
|
[
"Filters",
"an",
"array",
"of",
"drop",
"effects",
"using",
"a",
"HTML5",
"effectAllowed",
"string",
"."
] |
7e98e194a8d66fa735bf6dc7c3e39886287b914e
|
https://github.com/marceljuenemann/angular-drag-and-drop-lists/blob/7e98e194a8d66fa735bf6dc7c3e39886287b914e/angular-drag-and-drop-lists.js#L629-L634
|
11,491
|
wilix-team/iohook
|
install.js
|
install
|
function install(runtime, abi, platform, arch, cb) {
const essential = runtime + '-v' + abi + '-' + platform + '-' + arch;
const pkgVersion = pkg.version;
const currentPlatform = pkg.name + '-v' + pkgVersion + '-' + essential;
console.log('Downloading prebuild for platform:', currentPlatform);
let downloadUrl = 'https://github.com/WilixLead/iohook/releases/download/v' + pkgVersion + '/' + currentPlatform + '.tar.gz';
let reqOpts = {url: downloadUrl};
let tempFile = path.join(os.tmpdir(), 'prebuild.tar.gz');
let req = get(reqOpts, function(err, res) {
if (err) {
return onerror(err);
}
if (res.statusCode !== 200) {
if (res.statusCode === 404) {
console.error('Prebuild for current platform (' + currentPlatform + ') not found!');
console.error('Try to compile for your platform:');
console.error('# cd node_modules/iohook;');
console.error('# npm run compile');
console.error('');
return onerror('Prebuild for current platform (' + currentPlatform + ') not found!');
}
return onerror('Bad response from prebuild server. Code: ' + res.statusCode);
}
pump(res, fs.createWriteStream(tempFile), function(err) {
if (err) {
throw err;
}
let options = {
readable: true,
writable: true,
hardlinkAsFilesFallback: true
};
let binaryName;
let updateName = function(entry) {
if (/\.node$/i.test(entry.name)) binaryName = entry.name
};
let targetFile = path.join(__dirname, 'builds', essential);
let extract = tfs.extract(targetFile, options)
.on('entry', updateName);
pump(fs.createReadStream(tempFile), zlib.createGunzip(), extract, function(err) {
if (err) {
return onerror(err);
}
cb()
})
})
});
req.setTimeout(30 * 1000, function() {
req.abort()
})
}
|
javascript
|
function install(runtime, abi, platform, arch, cb) {
const essential = runtime + '-v' + abi + '-' + platform + '-' + arch;
const pkgVersion = pkg.version;
const currentPlatform = pkg.name + '-v' + pkgVersion + '-' + essential;
console.log('Downloading prebuild for platform:', currentPlatform);
let downloadUrl = 'https://github.com/WilixLead/iohook/releases/download/v' + pkgVersion + '/' + currentPlatform + '.tar.gz';
let reqOpts = {url: downloadUrl};
let tempFile = path.join(os.tmpdir(), 'prebuild.tar.gz');
let req = get(reqOpts, function(err, res) {
if (err) {
return onerror(err);
}
if (res.statusCode !== 200) {
if (res.statusCode === 404) {
console.error('Prebuild for current platform (' + currentPlatform + ') not found!');
console.error('Try to compile for your platform:');
console.error('# cd node_modules/iohook;');
console.error('# npm run compile');
console.error('');
return onerror('Prebuild for current platform (' + currentPlatform + ') not found!');
}
return onerror('Bad response from prebuild server. Code: ' + res.statusCode);
}
pump(res, fs.createWriteStream(tempFile), function(err) {
if (err) {
throw err;
}
let options = {
readable: true,
writable: true,
hardlinkAsFilesFallback: true
};
let binaryName;
let updateName = function(entry) {
if (/\.node$/i.test(entry.name)) binaryName = entry.name
};
let targetFile = path.join(__dirname, 'builds', essential);
let extract = tfs.extract(targetFile, options)
.on('entry', updateName);
pump(fs.createReadStream(tempFile), zlib.createGunzip(), extract, function(err) {
if (err) {
return onerror(err);
}
cb()
})
})
});
req.setTimeout(30 * 1000, function() {
req.abort()
})
}
|
[
"function",
"install",
"(",
"runtime",
",",
"abi",
",",
"platform",
",",
"arch",
",",
"cb",
")",
"{",
"const",
"essential",
"=",
"runtime",
"+",
"'-v'",
"+",
"abi",
"+",
"'-'",
"+",
"platform",
"+",
"'-'",
"+",
"arch",
";",
"const",
"pkgVersion",
"=",
"pkg",
".",
"version",
";",
"const",
"currentPlatform",
"=",
"pkg",
".",
"name",
"+",
"'-v'",
"+",
"pkgVersion",
"+",
"'-'",
"+",
"essential",
";",
"console",
".",
"log",
"(",
"'Downloading prebuild for platform:'",
",",
"currentPlatform",
")",
";",
"let",
"downloadUrl",
"=",
"'https://github.com/WilixLead/iohook/releases/download/v'",
"+",
"pkgVersion",
"+",
"'/'",
"+",
"currentPlatform",
"+",
"'.tar.gz'",
";",
"let",
"reqOpts",
"=",
"{",
"url",
":",
"downloadUrl",
"}",
";",
"let",
"tempFile",
"=",
"path",
".",
"join",
"(",
"os",
".",
"tmpdir",
"(",
")",
",",
"'prebuild.tar.gz'",
")",
";",
"let",
"req",
"=",
"get",
"(",
"reqOpts",
",",
"function",
"(",
"err",
",",
"res",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"onerror",
"(",
"err",
")",
";",
"}",
"if",
"(",
"res",
".",
"statusCode",
"!==",
"200",
")",
"{",
"if",
"(",
"res",
".",
"statusCode",
"===",
"404",
")",
"{",
"console",
".",
"error",
"(",
"'Prebuild for current platform ('",
"+",
"currentPlatform",
"+",
"') not found!'",
")",
";",
"console",
".",
"error",
"(",
"'Try to compile for your platform:'",
")",
";",
"console",
".",
"error",
"(",
"'# cd node_modules/iohook;'",
")",
";",
"console",
".",
"error",
"(",
"'# npm run compile'",
")",
";",
"console",
".",
"error",
"(",
"''",
")",
";",
"return",
"onerror",
"(",
"'Prebuild for current platform ('",
"+",
"currentPlatform",
"+",
"') not found!'",
")",
";",
"}",
"return",
"onerror",
"(",
"'Bad response from prebuild server. Code: '",
"+",
"res",
".",
"statusCode",
")",
";",
"}",
"pump",
"(",
"res",
",",
"fs",
".",
"createWriteStream",
"(",
"tempFile",
")",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"throw",
"err",
";",
"}",
"let",
"options",
"=",
"{",
"readable",
":",
"true",
",",
"writable",
":",
"true",
",",
"hardlinkAsFilesFallback",
":",
"true",
"}",
";",
"let",
"binaryName",
";",
"let",
"updateName",
"=",
"function",
"(",
"entry",
")",
"{",
"if",
"(",
"/",
"\\.node$",
"/",
"i",
".",
"test",
"(",
"entry",
".",
"name",
")",
")",
"binaryName",
"=",
"entry",
".",
"name",
"}",
";",
"let",
"targetFile",
"=",
"path",
".",
"join",
"(",
"__dirname",
",",
"'builds'",
",",
"essential",
")",
";",
"let",
"extract",
"=",
"tfs",
".",
"extract",
"(",
"targetFile",
",",
"options",
")",
".",
"on",
"(",
"'entry'",
",",
"updateName",
")",
";",
"pump",
"(",
"fs",
".",
"createReadStream",
"(",
"tempFile",
")",
",",
"zlib",
".",
"createGunzip",
"(",
")",
",",
"extract",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"onerror",
"(",
"err",
")",
";",
"}",
"cb",
"(",
")",
"}",
")",
"}",
")",
"}",
")",
";",
"req",
".",
"setTimeout",
"(",
"30",
"*",
"1000",
",",
"function",
"(",
")",
"{",
"req",
".",
"abort",
"(",
")",
"}",
")",
"}"
] |
Download and Install prebuild
@param runtime
@param abi
@param platform
@param arch
@param cb Callback
|
[
"Download",
"and",
"Install",
"prebuild"
] |
7a298ab49afb5bfd75f74ab94b1fce220150d396
|
https://github.com/wilix-team/iohook/blob/7a298ab49afb5bfd75f74ab94b1fce220150d396/install.js#L25-L78
|
11,492
|
wilix-team/iohook
|
install.js
|
optionsFromPackage
|
function optionsFromPackage(attempts) {
attempts = attempts || 2;
if (attempts > 5) {
console.log('Can\'t resolve main package.json file');
return {
targets: [],
platforms: [process.platform],
arches: [process.arch]
}
}
let mainPath = Array(attempts).join("../");
try {
const content = fs.readFileSync(path.join(__dirname, mainPath, 'package.json'), 'utf-8');
const packageJson = JSON.parse(content);
const opts = packageJson.iohook || {};
if (!opts.targets) {
opts.targets = []
}
if (!opts.platforms) opts.platforms = [process.platform];
if (!opts.arches) opts.arches = [process.arch];
return opts
} catch (e) {
return optionsFromPackage(attempts + 1);
}
}
|
javascript
|
function optionsFromPackage(attempts) {
attempts = attempts || 2;
if (attempts > 5) {
console.log('Can\'t resolve main package.json file');
return {
targets: [],
platforms: [process.platform],
arches: [process.arch]
}
}
let mainPath = Array(attempts).join("../");
try {
const content = fs.readFileSync(path.join(__dirname, mainPath, 'package.json'), 'utf-8');
const packageJson = JSON.parse(content);
const opts = packageJson.iohook || {};
if (!opts.targets) {
opts.targets = []
}
if (!opts.platforms) opts.platforms = [process.platform];
if (!opts.arches) opts.arches = [process.arch];
return opts
} catch (e) {
return optionsFromPackage(attempts + 1);
}
}
|
[
"function",
"optionsFromPackage",
"(",
"attempts",
")",
"{",
"attempts",
"=",
"attempts",
"||",
"2",
";",
"if",
"(",
"attempts",
">",
"5",
")",
"{",
"console",
".",
"log",
"(",
"'Can\\'t resolve main package.json file'",
")",
";",
"return",
"{",
"targets",
":",
"[",
"]",
",",
"platforms",
":",
"[",
"process",
".",
"platform",
"]",
",",
"arches",
":",
"[",
"process",
".",
"arch",
"]",
"}",
"}",
"let",
"mainPath",
"=",
"Array",
"(",
"attempts",
")",
".",
"join",
"(",
"\"../\"",
")",
";",
"try",
"{",
"const",
"content",
"=",
"fs",
".",
"readFileSync",
"(",
"path",
".",
"join",
"(",
"__dirname",
",",
"mainPath",
",",
"'package.json'",
")",
",",
"'utf-8'",
")",
";",
"const",
"packageJson",
"=",
"JSON",
".",
"parse",
"(",
"content",
")",
";",
"const",
"opts",
"=",
"packageJson",
".",
"iohook",
"||",
"{",
"}",
";",
"if",
"(",
"!",
"opts",
".",
"targets",
")",
"{",
"opts",
".",
"targets",
"=",
"[",
"]",
"}",
"if",
"(",
"!",
"opts",
".",
"platforms",
")",
"opts",
".",
"platforms",
"=",
"[",
"process",
".",
"platform",
"]",
";",
"if",
"(",
"!",
"opts",
".",
"arches",
")",
"opts",
".",
"arches",
"=",
"[",
"process",
".",
"arch",
"]",
";",
"return",
"opts",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"optionsFromPackage",
"(",
"attempts",
"+",
"1",
")",
";",
"}",
"}"
] |
Return options for iohook from package.json
@return {Object}
|
[
"Return",
"options",
"for",
"iohook",
"from",
"package",
".",
"json"
] |
7a298ab49afb5bfd75f74ab94b1fce220150d396
|
https://github.com/wilix-team/iohook/blob/7a298ab49afb5bfd75f74ab94b1fce220150d396/install.js#L84-L108
|
11,493
|
govau/design-system-components
|
packages/main-nav/src/js/module.js
|
listenHandler
|
function listenHandler( event ) {
var handler = rawHandler.apply( this, arguments );
if ( handler === false) {
event.stopPropagation();
event.preventDefault();
}
return( handler );
}
|
javascript
|
function listenHandler( event ) {
var handler = rawHandler.apply( this, arguments );
if ( handler === false) {
event.stopPropagation();
event.preventDefault();
}
return( handler );
}
|
[
"function",
"listenHandler",
"(",
"event",
")",
"{",
"var",
"handler",
"=",
"rawHandler",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"if",
"(",
"handler",
"===",
"false",
")",
"{",
"event",
".",
"stopPropagation",
"(",
")",
";",
"event",
".",
"preventDefault",
"(",
")",
";",
"}",
"return",
"(",
"handler",
")",
";",
"}"
] |
Using local functions instead of anonymous for event handler
|
[
"Using",
"local",
"functions",
"instead",
"of",
"anonymous",
"for",
"event",
"handler"
] |
38aa8c127e1469a7835dea5513f1d6e2aff05186
|
https://github.com/govau/design-system-components/blob/38aa8c127e1469a7835dea5513f1d6e2aff05186/packages/main-nav/src/js/module.js#L96-L103
|
11,494
|
govau/design-system-components
|
packages/main-nav/src/js/module.js
|
attachHandler
|
function attachHandler() {
var handler = rawHandler.call( element, window.event );
if ( handler === false ) {
window.event.returnValue = false;
window.event.cancelBubble = true;
}
return( handler );
}
|
javascript
|
function attachHandler() {
var handler = rawHandler.call( element, window.event );
if ( handler === false ) {
window.event.returnValue = false;
window.event.cancelBubble = true;
}
return( handler );
}
|
[
"function",
"attachHandler",
"(",
")",
"{",
"var",
"handler",
"=",
"rawHandler",
".",
"call",
"(",
"element",
",",
"window",
".",
"event",
")",
";",
"if",
"(",
"handler",
"===",
"false",
")",
"{",
"window",
".",
"event",
".",
"returnValue",
"=",
"false",
";",
"window",
".",
"event",
".",
"cancelBubble",
"=",
"true",
";",
"}",
"return",
"(",
"handler",
")",
";",
"}"
] |
Make sure attachHandler is also going to work
|
[
"Make",
"sure",
"attachHandler",
"is",
"also",
"going",
"to",
"work"
] |
38aa8c127e1469a7835dea5513f1d6e2aff05186
|
https://github.com/govau/design-system-components/blob/38aa8c127e1469a7835dea5513f1d6e2aff05186/packages/main-nav/src/js/module.js#L106-L113
|
11,495
|
govau/design-system-components
|
packages/main-nav/src/js/module.js
|
removeEvent
|
function removeEvent( token ) {
if ( token.element.removeEventListener ) {
token.element.removeEventListener( token.event, token.handler );
} else {
token.element.detachEvent( 'on' + token.event, token.handler );
}
}
|
javascript
|
function removeEvent( token ) {
if ( token.element.removeEventListener ) {
token.element.removeEventListener( token.event, token.handler );
} else {
token.element.detachEvent( 'on' + token.event, token.handler );
}
}
|
[
"function",
"removeEvent",
"(",
"token",
")",
"{",
"if",
"(",
"token",
".",
"element",
".",
"removeEventListener",
")",
"{",
"token",
".",
"element",
".",
"removeEventListener",
"(",
"token",
".",
"event",
",",
"token",
".",
"handler",
")",
";",
"}",
"else",
"{",
"token",
".",
"element",
".",
"detachEvent",
"(",
"'on'",
"+",
"token",
".",
"event",
",",
"token",
".",
"handler",
")",
";",
"}",
"}"
] |
PRIVATE
IE8 compatible function for removing an event
@param {object} token - The token from the add listener function
|
[
"PRIVATE",
"IE8",
"compatible",
"function",
"for",
"removing",
"an",
"event"
] |
38aa8c127e1469a7835dea5513f1d6e2aff05186
|
https://github.com/govau/design-system-components/blob/38aa8c127e1469a7835dea5513f1d6e2aff05186/packages/main-nav/src/js/module.js#L140-L146
|
11,496
|
govau/design-system-components
|
packages/main-nav/src/js/module.js
|
getStyle
|
function getStyle( element, property ) {
return (
typeof getComputedStyle !== 'undefined'
? getComputedStyle( element, null)
: element.currentStyle
)[ property ]; // avoid getPropertyValue altogether
}
|
javascript
|
function getStyle( element, property ) {
return (
typeof getComputedStyle !== 'undefined'
? getComputedStyle( element, null)
: element.currentStyle
)[ property ]; // avoid getPropertyValue altogether
}
|
[
"function",
"getStyle",
"(",
"element",
",",
"property",
")",
"{",
"return",
"(",
"typeof",
"getComputedStyle",
"!==",
"'undefined'",
"?",
"getComputedStyle",
"(",
"element",
",",
"null",
")",
":",
"element",
".",
"currentStyle",
")",
"[",
"property",
"]",
";",
"// avoid getPropertyValue altogether",
"}"
] |
PRIVATE
IE8 compatible function for getting elements style
@param {object} element - element to check style
@param {object} property - property to return value
|
[
"PRIVATE",
"IE8",
"compatible",
"function",
"for",
"getting",
"elements",
"style"
] |
38aa8c127e1469a7835dea5513f1d6e2aff05186
|
https://github.com/govau/design-system-components/blob/38aa8c127e1469a7835dea5513f1d6e2aff05186/packages/main-nav/src/js/module.js#L156-L162
|
11,497
|
govau/design-system-components
|
packages/accordion/src/js/module.js
|
toggleClasses
|
function toggleClasses( element, state, openingClass, closingClass ) {
if( state === 'opening' || state === 'open' ) {
var oldClass = openingClass || 'au-accordion--closed';
var newClass = closingClass || 'au-accordion--open';
}
else {
var oldClass = closingClass || 'au-accordion--open';
var newClass = openingClass || 'au-accordion--closed';
}
removeClass( element, oldClass );
addClass( element, newClass );
}
|
javascript
|
function toggleClasses( element, state, openingClass, closingClass ) {
if( state === 'opening' || state === 'open' ) {
var oldClass = openingClass || 'au-accordion--closed';
var newClass = closingClass || 'au-accordion--open';
}
else {
var oldClass = closingClass || 'au-accordion--open';
var newClass = openingClass || 'au-accordion--closed';
}
removeClass( element, oldClass );
addClass( element, newClass );
}
|
[
"function",
"toggleClasses",
"(",
"element",
",",
"state",
",",
"openingClass",
",",
"closingClass",
")",
"{",
"if",
"(",
"state",
"===",
"'opening'",
"||",
"state",
"===",
"'open'",
")",
"{",
"var",
"oldClass",
"=",
"openingClass",
"||",
"'au-accordion--closed'",
";",
"var",
"newClass",
"=",
"closingClass",
"||",
"'au-accordion--open'",
";",
"}",
"else",
"{",
"var",
"oldClass",
"=",
"closingClass",
"||",
"'au-accordion--open'",
";",
"var",
"newClass",
"=",
"openingClass",
"||",
"'au-accordion--closed'",
";",
"}",
"removeClass",
"(",
"element",
",",
"oldClass",
")",
";",
"addClass",
"(",
"element",
",",
"newClass",
")",
";",
"}"
] |
PRIVATE
IE8 compatible function for replacing classes on a DOM node
@param {object} element - The DOM element we want to toggle classes on
@param {object} target - The DOM element we want to toggle classes on
@param {object} state - The current state of the animation on the element
@param {string} openingClass - The firstClass you want to toggle on the DOM node
@param {string} closingClass - The secondClass you want to toggle on the DOM node
|
[
"PRIVATE",
"IE8",
"compatible",
"function",
"for",
"replacing",
"classes",
"on",
"a",
"DOM",
"node"
] |
38aa8c127e1469a7835dea5513f1d6e2aff05186
|
https://github.com/govau/design-system-components/blob/38aa8c127e1469a7835dea5513f1d6e2aff05186/packages/accordion/src/js/module.js#L52-L65
|
11,498
|
govau/design-system-components
|
scripts/helper.js
|
ExitHandler
|
function ExitHandler( exiting, error ) {
if( error ) {
if( error.stack ) {
console.error( error.stack );
}
process.exit( 1 );
}
if( exiting.now ) {
process.exit( 0 ); // exit now
}
console.log('\n');
process.exit( 0 ); // now exit with a smile :)
}
|
javascript
|
function ExitHandler( exiting, error ) {
if( error ) {
if( error.stack ) {
console.error( error.stack );
}
process.exit( 1 );
}
if( exiting.now ) {
process.exit( 0 ); // exit now
}
console.log('\n');
process.exit( 0 ); // now exit with a smile :)
}
|
[
"function",
"ExitHandler",
"(",
"exiting",
",",
"error",
")",
"{",
"if",
"(",
"error",
")",
"{",
"if",
"(",
"error",
".",
"stack",
")",
"{",
"console",
".",
"error",
"(",
"error",
".",
"stack",
")",
";",
"}",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
"if",
"(",
"exiting",
".",
"now",
")",
"{",
"process",
".",
"exit",
"(",
"0",
")",
";",
"// exit now",
"}",
"console",
".",
"log",
"(",
"'\\n'",
")",
";",
"process",
".",
"exit",
"(",
"0",
")",
";",
"// now exit with a smile :)",
"}"
] |
Handle exiting of program
@param {null} exiting - null for bind
@param {object} error - Object to distinguish between closing events
|
[
"Handle",
"exiting",
"of",
"program"
] |
38aa8c127e1469a7835dea5513f1d6e2aff05186
|
https://github.com/govau/design-system-components/blob/38aa8c127e1469a7835dea5513f1d6e2aff05186/scripts/helper.js#L1266-L1282
|
11,499
|
nordnet/cordova-hot-code-push
|
scripts/beforePluginInstallHook.js
|
checkCliDependency
|
function checkCliDependency(ctx) {
var result = spawnSync('cordova-hcp', [], { cwd: './plugins/' + ctx.opts.plugin.id });
if (!result.error) {
return;
}
suggestCliInstallation();
}
|
javascript
|
function checkCliDependency(ctx) {
var result = spawnSync('cordova-hcp', [], { cwd: './plugins/' + ctx.opts.plugin.id });
if (!result.error) {
return;
}
suggestCliInstallation();
}
|
[
"function",
"checkCliDependency",
"(",
"ctx",
")",
"{",
"var",
"result",
"=",
"spawnSync",
"(",
"'cordova-hcp'",
",",
"[",
"]",
",",
"{",
"cwd",
":",
"'./plugins/'",
"+",
"ctx",
".",
"opts",
".",
"plugin",
".",
"id",
"}",
")",
";",
"if",
"(",
"!",
"result",
".",
"error",
")",
"{",
"return",
";",
"}",
"suggestCliInstallation",
"(",
")",
";",
"}"
] |
region CLI specific
Check if cordova-hcp utility is installed. If not - suggest user to install it.
|
[
"region",
"CLI",
"specific",
"Check",
"if",
"cordova",
"-",
"hcp",
"utility",
"is",
"installed",
".",
"If",
"not",
"-",
"suggest",
"user",
"to",
"install",
"it",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/beforePluginInstallHook.js#L19-L26
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.