_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 52 373k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q26300 | train | function(protoProps, classProps) {
var child = inherits(this, protoProps, classProps);
child.extend = this.extend;
// a hack required to WSH inherit `toString` method
if (protoProps.hasOwnProperty('toString'))
child.prototype.toString = protoProps.toString;
return child;
} | javascript | {
"resource": ""
} | |
q26301 | processClassName | train | function processClassName(name, item) {
name = transformClassName(name, item, 'element');
name = transformClassName(name, item, 'modifier');
// expand class name
// possible values:
// * block__element
// * block__element_modifier
// * block__element_modifier1_modifier2
// * block_modifier
var bloc... | javascript | {
"resource": ""
} |
q26302 | transformClassName | train | function transformClassName(name, item, entityType) {
var separators = getSeparators();
var reSep = new RegExp('^(' + separators[entityType] + ')+', 'g');
if (reSep.test(name)) {
var depth = 0; // parent lookup depth
var cleanName = name.replace(reSep, function(str) {
depth = str.length / separators[ent... | javascript | {
"resource": ""
} |
q26303 | train | function(title, menu) {
return utils.find(menu || this.getMenu(), function(val) {
if (val.type == 'action') {
if (val.label == title || val.name == title) {
return val.name;
}
} else {
return this.getActionNameForMenuTitle(title, val.items);
}
}, this);
} | javascript | {
"resource": ""
} | |
q26304 | parseDB | train | function parseDB(data, optimized) {
if (typeof data == 'string') {
data = JSON.parse(data);
}
if (!optimized) {
data = optimize(data);
}
vendorsDB = data.vendors;
cssDB = data.css;
erasDB = data.era;
} | javascript | {
"resource": ""
} |
q26305 | optimize | train | function optimize(data) {
if (typeof data == 'string') {
data = JSON.parse(data);
}
return {
vendors: parseVendors(data),
css: parseCSS(data),
era: parseEra(data)
};
} | javascript | {
"resource": ""
} |
q26306 | parseVendors | train | function parseVendors(data) {
var out = {};
Object.keys(data.agents).forEach(function(name) {
var agent = data.agents[name];
out[name] = {
prefix: agent.prefix,
versions: agent.versions
};
});
return out;
} | javascript | {
"resource": ""
} |
q26307 | parseCSS | train | function parseCSS(data) {
var out = {};
var cssCategories = data.cats.CSS;
Object.keys(data.data).forEach(function(name) {
var section = data.data[name];
if (name in cssSections) {
cssSections[name].forEach(function(kw) {
out[kw] = section.stats;
});
}
});
return out;
} | javascript | {
"resource": ""
} |
q26308 | parseEra | train | function parseEra(data) {
// some runtimes (like Mozilla Rhino) does not preserves
// key order so we have to sort values manually
return Object.keys(data.eras).sort(function(a, b) {
return parseInt(a.substr(1)) - parseInt(b.substr(1));
});
} | javascript | {
"resource": ""
} |
q26309 | getVendorsList | train | function getVendorsList() {
var allVendors = Object.keys(vendorsDB);
var vendors = prefs.getArray('caniuse.vendors');
if (!vendors || vendors[0] == 'all') {
return allVendors;
}
return intersection(allVendors, vendors);
} | javascript | {
"resource": ""
} |
q26310 | getVersionSlice | train | function getVersionSlice() {
var era = prefs.get('caniuse.era');
var ix = erasDB.indexOf(era);
if (!~ix) {
ix = erasDB.indexOf('e-2');
}
return ix;
} | javascript | {
"resource": ""
} |
q26311 | train | function(property) {
if (!prefs.get('caniuse.enabled') || !cssDB || !(property in cssDB)) {
return null;
}
var prefixes = [];
var propStats = cssDB[property];
var versions = getVersionSlice();
getVendorsList().forEach(function(vendor) {
var vendorVesions = vendorsDB[vendor].versions.slice(ve... | javascript | {
"resource": ""
} | |
q26312 | train | function(name, options) {
if (arguments.length == 2)
return createProfile(name, options);
else
// create profile object only
return new OutputProfile(utils.defaults(name || {}, defaultProfile));
} | javascript | {
"resource": ""
} | |
q26313 | train | function(name, syntax) {
if (!name && syntax) {
// search in user resources first
var profile = resources.findItem(syntax, 'profile');
if (profile) {
name = profile;
}
}
if (!name) {
return profiles.plain;
}
if (name instanceof OutputProfile) {
return name;
}
... | javascript | {
"resource": ""
} | |
q26314 | expectedDiff | train | function expectedDiff(expected, computedStyles) {
const received = Array.from(computedStyles)
.filter(prop => expected[prop])
.reduce(
(obj, prop) =>
Object.assign(obj, {[prop]: computedStyles.getPropertyValue(prop)}),
{},
)
const diffOutput = jestDiff(
printoutStyles(expected),
... | javascript | {
"resource": ""
} |
q26315 | _flatten | train | function _flatten (arr) {
var flat = [];
for (var i = 0, n = arr.length; i < n; i++) {
flat = flat.concat(arr[i]);
}
return flat;
} | javascript | {
"resource": ""
} |
q26316 | _every | train | function _every (arr, iterator) {
for (var i = 0; i < arr.length; i += 1) {
if (iterator(arr[i], i, arr) === false) {
return;
}
}
} | javascript | {
"resource": ""
} |
q26317 | _asyncEverySeries | train | function _asyncEverySeries (arr, iterator, callback) {
if (!arr.length) {
return callback();
}
var completed = 0;
(function iterate() {
iterator(arr[completed], function (err) {
if (err || err === false) {
callback(err);
callback = function () {};
}
else {
comp... | javascript | {
"resource": ""
} |
q26318 | reportDelete | train | function reportDelete(context, offset, text) {
const start = context.getSourceCode().getLocFromIndex(offset);
const end = context.getSourceCode().getLocFromIndex(offset + text.length);
const range = [offset, offset + text.length];
context.report({
message: 'Delete `{{ code }}`',
data: { code: showInvisi... | javascript | {
"resource": ""
} |
q26319 | reportReplace | train | function reportReplace(context, offset, deleteText, insertText) {
const start = context.getSourceCode().getLocFromIndex(offset);
const end = context
.getSourceCode()
.getLocFromIndex(offset + deleteText.length);
const range = [offset, offset + deleteText.length];
context.report({
message: 'Replace `... | javascript | {
"resource": ""
} |
q26320 | isAppInstalled | train | function isAppInstalled(app, prefixes) {
return new Promise((resolve) => {
if (!(app in prefixes)) {
return resolve(false)
}
Linking.canOpenURL(prefixes[app])
.then((result) => {
resolve(!!result)
})
.catch(() => resolve(false))
})
} | javascript | {
"resource": ""
} |
q26321 | train | function(r /*, a[, b[, ...]] */) {
// Get the arguments as an array but ommit the initial item
Array.prototype.slice.call(arguments, 1).forEach(function(a) {
if (Array.isArray(r) && Array.isArray(a)) {
Array.prototype.push.apply(r, a);
}
else if (r && (r instanceof Object || typeof r === 'object') && ... | javascript | {
"resource": ""
} | |
q26322 | train | function(service) {
// Create self, which inherits from its parent
var self = Object.create(this);
// Inherit the prototype from its parent
self.settings = Object.create(this.settings);
// Define the default service
if (service) {
self.settings.default_service = service;
}
// Create an instance o... | javascript | {
"resource": ""
} | |
q26323 | train | function(services, options) {
var utils = this.utils;
if (!services) {
return this.services;
}
// Define provider credentials
// Reformat the ID field
for (var x in services) {if (services.hasOwnProperty(x)) {
if (typeof (services[x]) !== 'object') {
services[x] = {id: services[x]};
}
}}
... | javascript | {
"resource": ""
} | |
q26324 | train | function() {
var _this = this;
var utils = _this.utils;
var error = utils.error;
// Create a new promise
var promise = utils.Promise();
var p = utils.args({name:'s', options: 'o', callback: 'f'}, arguments);
p.options = p.options || {};
// Add callback to events
promise.proxy.then(p.callback, p.c... | javascript | {
"resource": ""
} | |
q26325 | train | function(opts) {
// Remove from the store
utils.store(p.name, null);
// Emit events by default
promise.fulfill(hello.utils.merge({network:p.name}, opts || {}));
} | javascript | {
"resource": ""
} | |
q26326 | train | function(service) {
// If the service doesn't exist
service = service || this.settings.default_service;
if (!service || !(service in this.services)) {
return null;
}
return this.utils.store(service) || null;
} | javascript | {
"resource": ""
} | |
q26327 | train | function(url, params, formatFunction) {
if (params) {
// Set default formatting function
formatFunction = formatFunction || encodeURIComponent;
// Override the items in the URL which already exist
for (var x in params) {
var str = '([\\?\\&])' + x + '=[^\\&]*';
var reg = new RegExp(str);
if... | javascript | {
"resource": ""
} | |
q26328 | train | function(node, attr, target) {
var n = typeof (node) === 'string' ? document.createElement(node) : node;
if (typeof (attr) === 'object') {
if ('tagName' in attr) {
target = attr;
}
else {
for (var x in attr) {if (attr.hasOwnProperty(x)) {
if (typeof (attr[x]) === 'object') {
for (var y... | javascript | {
"resource": ""
} | |
q26329 | train | function(src) {
this.append('iframe', {src: src, style: {position:'absolute', left: '-1000px', bottom: 0, height: '1px', width: '1px'}}, 'body');
} | javascript | {
"resource": ""
} | |
q26330 | train | function(path) {
// If the path is empty
if (!path) {
return window.location;
}
// Chrome and FireFox support new URL() to extract URL objects
else if (window.URL && URL instanceof Function && URL.length !== 0) {
return new URL(path, window.location);
}
// Ugly shim, it works!
else {
var a =... | javascript | {
"resource": ""
} | |
q26331 | train | function(a, b) {
if (a || !b) {
var r = {};
for (var x in a) {
// Does the property not exist?
if (!(x in b)) {
r[x] = a[x];
}
}
return r;
}
return a;
} | javascript | {
"resource": ""
} | |
q26332 | train | function(a) {
if (!Array.isArray(a)) { return []; }
return a.filter(function(item, index) {
// Is this the first location of item
return a.indexOf(item) === index;
});
} | javascript | {
"resource": ""
} | |
q26333 | train | function(callback, guid) {
// If the guid has not been supplied then create a new one.
guid = guid || '_hellojs_' + parseInt(Math.random() * 1e12, 10).toString(36);
// Define the callback function
window[guid] = function() {
// Trigger the callback
try {
if (callback.apply(this, arguments)) {
de... | javascript | {
"resource": ""
} | |
q26334 | train | function(url, redirectUri, options) {
var documentElement = document.documentElement;
// Multi Screen Popup Positioning (http://stackoverflow.com/a/16861050)
// Credit: http://www.xtf.dk/2011/08/center-new-popup-window-even-on.html
// Fixes dual-screen position Most browsers Firef... | javascript | {
"resource": ""
} | |
q26335 | authCallback | train | function authCallback(obj, window, parent) {
var cb = obj.callback;
var network = obj.network;
// Trigger the callback on the parent
_this.store(network, obj);
// If this is a page request it has no parent or opener window to handle callbacks
if (('display' in obj) && obj.display === 'page') {
... | javascript | {
"resource": ""
} |
q26336 | getPath | train | function getPath(url) {
// Format the string if it needs it
url = url.replace(/\@\{([a-z\_\-]+)(\|.*?)?\}/gi, function(m, key, defaults) {
var val = defaults ? defaults.replace(/^\|/, '') : '';
if (key in p.query) {
val = p.query[key];
delete p.query[key];
}
else if (p.data && key in p.data) {
... | javascript | {
"resource": ""
} |
q26337 | formatUrl | train | function formatUrl(p, callback) {
// Are we signing the request?
var sign;
// OAuth1
// Remove the token from the query before signing
if (p.authResponse && p.authResponse.oauth && parseInt(p.authResponse.oauth.version, 10) === 1) {
// OAUTH SIGNING PROXY
sign = p.query.access_token;
// R... | javascript | {
"resource": ""
} |
q26338 | train | function(type, data) {
var test = 'HTML' + (type || '').replace(
/^[a-z]/,
function(m) {
return m.toUpperCase();
}
) + 'Element';
if (!data) {
return false;
}
if (window[test]) {
return data instanceof window[test];
}
else if (window.Element) {
return data instanceof window.Elemen... | javascript | {
"resource": ""
} | |
q26339 | train | function(obj) {
// Does not clone DOM elements, nor Binary data, e.g. Blobs, Filelists
if (obj === null || typeof (obj) !== 'object' || obj instanceof Date || 'nodeName' in obj || this.isBinary(obj) || (typeof FormData === 'function' && obj instanceof FormData)) {
return obj;
}
if (Array.isArray(obj)) {
... | javascript | {
"resource": ""
} | |
q26340 | headersToJSON | train | function headersToJSON(s) {
var r = {};
var reg = /([a-z\-]+):\s?(.*);?/gi;
var m;
while ((m = reg.exec(s))) {
r[m[1]] = m[2];
}
return r;
} | javascript | {
"resource": ""
} |
q26341 | train | function(url, callback, callbackID, timeout) {
var _this = this;
var error = _this.error;
// Change the name of the callback
var bool = 0;
var head = document.getElementsByTagName('head')[0];
var operaFix;
var result = error('server_error', 'server_error');
var cb = function() {
if (!(bool++)) {
... | javascript | {
"resource": ""
} | |
q26342 | train | function(data) {
for (var x in data) if (data.hasOwnProperty(x)) {
if (this.isBinary(data[x])) {
return true;
}
}
return false;
} | javascript | {
"resource": ""
} | |
q26343 | train | function(data) {
return data instanceof Object && (
(this.domInstance('input', data) && data.type === 'file') ||
('FileList' in window && data instanceof window.FileList) ||
('File' in window && data instanceof window.File) ||
('Blob' in window && data instanceof window.Blob));
} | javascript | {
"resource": ""
} | |
q26344 | train | function(p) {
var _this = this;
var w = window;
var data = p.data;
// Is data a form object
if (_this.domInstance('form', data)) {
data = _this.nodeListToJSON(data.elements);
}
else if ('NodeList' in w && data instanceof NodeList) {
data = _this.nodeListToJSON(data);
}
else if (_thi... | javascript | {
"resource": ""
} | |
q26345 | train | function(nodelist) {
var json = {};
// Create a data string
for (var i = 0; i < nodelist.length; i++) {
var input = nodelist[i];
// If the name of the input is empty or diabled, dont add it.
if (input.disabled || !input.name) {
continue;
}
// Is this a file, does the browser not s... | javascript | {
"resource": ""
} | |
q26346 | train | function(p) {
// The proxy supports allow-cross-origin-resource
// Alas that's the only thing we're using.
if (p.data && p.data.file) {
var file = p.data.file;
if (file) {
if (file.files) {
p.data = file.files[0];
}
else {
p.data = file;
}
}
}
i... | javascript | {
"resource": ""
} | |
q26347 | train | function(p, qs) {
if (p.method === 'get' || p.method === 'post') {
qs.suppress_response_codes = true;
}
// Is this a post with a data-uri?
if (p.method === 'post' && p.data && typeof (p.data.file) === 'string') {
// Convert the Data-URI to a Blob
p.data.file = hello.utils.toBlob(p.data.f... | javascript | {
"resource": ""
} | |
q26348 | train | function(p, qs) {
var m = p.method;
if (m !== 'get' && !hello.utils.hasBinary(p.data)) {
p.data.method = m;
p.method = 'get';
}
else if (p.method === 'delete') {
qs.method = 'delete';
p.method = 'post';
}
} | javascript | {
"resource": ""
} | |
q26349 | withUser | train | function withUser(cb) {
var auth = hello.getAuthResponse('flickr');
cb(auth && auth.user_nsid ? auth.user_nsid : null);
} | javascript | {
"resource": ""
} |
q26350 | gEntry | train | function gEntry(o) {
paging(o);
if ('feed' in o && 'entry' in o.feed) {
o.data = o.feed.entry.map(formatEntry);
delete o.feed;
}
// Old style: Picasa, etc.
else if ('entry' in o) {
return formatEntry(o.entry);
}
// New style: Google Drive
else if ('items' in o) {
o.data = o.items.map(form... | javascript | {
"resource": ""
} |
q26351 | Multipart | train | function Multipart() {
// Internal body
var body = [];
var boundary = (Math.random() * 1e10).toString(32);
var counter = 0;
var lineBreak = '\r\n';
var delim = lineBreak + '--' + boundary;
var ready = function() {};
var dataUri = /^data\:([^;,]+(\;charset=[^;,]+)?)(\;base64)?,/i;
// Add file
func... | javascript | {
"resource": ""
} |
q26352 | train | function(p, qs) {
var method = p.method;
var proxy = method !== 'get';
if (proxy) {
if ((method === 'post' || method === 'put') && p.query.access_token) {
p.data.access_token = p.query.access_token;
delete p.query.access_token;
}
// No access control headers
// Use the pr... | javascript | {
"resource": ""
} | |
q26353 | formatRequest | train | function formatRequest(p, qs) {
var token = qs.access_token;
delete qs.access_token;
p.headers.Authorization = 'Bearer ' + token;
return true;
} | javascript | {
"resource": ""
} |
q26354 | getSizeInPixels | train | function getSizeInPixels(el, value) {
if (/px$/i.test(value)) return parseFloat(value);
var style = el.style.left, runtimeStyle = el.runtimeStyle.left;
el.runtimeStyle.left = el.currentStyle.left;
el.style.left = value;
var result = el.style.pixelLeft;
el.style.left = style;
el.runtimeStyle.... | javascript | {
"resource": ""
} |
q26355 | train | function(eventName, handler) {
if (!this.__eventListeners) {
this.__eventListeners = { };
}
// one object with key/value pairs was passed
if (arguments.length === 1) {
for (var prop in eventName) {
this.on(prop, eventName[prop]);
}
}
else {
if (!this.__eventListen... | javascript | {
"resource": ""
} | |
q26356 | train | function(eventName, handler) {
if (!this.__eventListeners) {
this.__eventListeners = { };
}
if (this.__eventListeners[eventName]) {
fabric.util.removeFromArray(this.__eventListeners[eventName], handler);
}
} | javascript | {
"resource": ""
} | |
q26357 | train | function(eventName, options) {
if (!this.__eventListeners) {
this.__eventListeners = { }
}
var listenersForEvent = this.__eventListeners[eventName];
if (!listenersForEvent) return;
for (var i = 0, len = listenersForEvent.length; i < len; i++) {
// avoiding try/catch for perf. reasons
... | javascript | {
"resource": ""
} | |
q26358 | animate | train | function animate(options) {
options || (options = { });
var start = +new Date(),
duration = options.duration || 500,
finish = start + duration, time, pos,
onChange = options.onChange || function() { },
abort = options.abort || function() { return false; },
easing = options.easing... | javascript | {
"resource": ""
} |
q26359 | loadImage | train | function loadImage(url, callback, context) {
if (url) {
var img = new Image();
/** @ignore */
img.onload = function () {
callback && callback.call(context, img);
img = img.onload = null;
};
img.src = url;
}
else {
callback && callback.call(context, url);
... | javascript | {
"resource": ""
} |
q26360 | invoke | train | function invoke(array, method) {
var args = slice.call(arguments, 2), result = [ ];
for (var i = 0, len = array.length; i < len; i++) {
result[i] = args.length ? array[i][method].apply(array[i], args) : array[i][method].call(array[i]);
}
return result;
} | javascript | {
"resource": ""
} |
q26361 | camelize | train | function camelize(string) {
return string.replace(/-+(.)?/g, function(match, character) {
return character ? character.toUpperCase() : '';
});
} | javascript | {
"resource": ""
} |
q26362 | createClass | train | function createClass() {
var parent = null,
properties = slice.call(arguments, 0);
if (typeof properties[0] === 'function') {
parent = properties.shift();
}
function klass() {
this.initialize.apply(this, arguments);
}
klass.superclass = parent;
klass.subclasses = [ ];
... | javascript | {
"resource": ""
} |
q26363 | setStyle | train | function setStyle(element, styles) {
var elementStyle = element.style, match;
if (!elementStyle) {
return element;
}
if (typeof styles === 'string') {
element.style.cssText += ';' + styles;
return styles.indexOf('opacity') > -1
? setOpacity(element, styles.match(/opacity:\s*(\d... | javascript | {
"resource": ""
} |
q26364 | makeElement | train | function makeElement(tagName, attributes) {
var el = fabric.document.createElement(tagName);
for (var prop in attributes) {
if (prop === 'class') {
el.className = attributes[prop];
}
else if (prop === 'for') {
el.htmlFor = attributes[prop];
}
else {
el.setAt... | javascript | {
"resource": ""
} |
q26365 | addClass | train | function addClass(element, className) {
if ((' ' + element.className + ' ').indexOf(' ' + className + ' ') === -1) {
element.className += (element.className ? ' ' : '') + className;
}
} | javascript | {
"resource": ""
} |
q26366 | wrapElement | train | function wrapElement(element, wrapper, attributes) {
if (typeof wrapper === 'string') {
wrapper = makeElement(wrapper, attributes);
}
if (element.parentNode) {
element.parentNode.replaceChild(wrapper, element);
}
wrapper.appendChild(element);
return wrapper;
} | javascript | {
"resource": ""
} |
q26367 | makeElementUnselectable | train | function makeElementUnselectable(element) {
if (typeof element.onselectstart !== 'undefined') {
element.onselectstart = fabric.util.falseFunction;
}
if (selectProp) {
element.style[selectProp] = 'none';
}
else if (typeof element.unselectable == 'string') {
element.u... | javascript | {
"resource": ""
} |
q26368 | makeElementSelectable | train | function makeElementSelectable(element) {
if (typeof element.onselectstart !== 'undefined') {
element.onselectstart = null;
}
if (selectProp) {
element.style[selectProp] = '';
}
else if (typeof element.unselectable == 'string') {
element.unselectable = '';
}
... | javascript | {
"resource": ""
} |
q26369 | request | train | function request(url, options) {
options || (options = { });
var method = options.method ? options.method.toUpperCase() : 'GET',
onComplete = options.onComplete || function() { },
request = makeXHR(),
body;
/** @ignore */
request.onreadystatechange = function() {
... | javascript | {
"resource": ""
} |
q26370 | parsePointsAttribute | train | function parsePointsAttribute(points) {
// points attribute is required and must not be empty
if (!points) return null;
points = points.trim();
var asPairs = points.indexOf(',') > -1;
points = points.split(/\s+/);
var parsedPoints = [ ];
// points could look like "10,20 30,40" or "10 20 ... | javascript | {
"resource": ""
} |
q26371 | parseStyleAttribute | train | function parseStyleAttribute(element) {
var oStyle = { },
style = element.getAttribute('style');
if (style) {
if (typeof style == 'string') {
style = style.replace(/;$/, '').split(';').forEach(function (current) {
var attr = current.split(':');
oStyle[normalizeAttr(... | javascript | {
"resource": ""
} |
q26372 | getCSSRules | train | function getCSSRules(doc) {
var styles = doc.getElementsByTagName('style'),
allRules = { },
rules;
// very crude parsing of style contents
for (var i = 0, len = styles.length; i < len; i++) {
var styleContents = styles[0].textContent;
// remove comments
styleContents = st... | javascript | {
"resource": ""
} |
q26373 | loadSVGFromURL | train | function loadSVGFromURL(url, callback, reviver) {
url = url.replace(/^\n\s*/, '').trim();
svgCache.has(url, function (hasUrl) {
if (hasUrl) {
svgCache.get(url, function (value) {
var enlivedRecord = _enlivenCachedObject(value);
callback(enlivedRecord.objects, enlivedRec... | javascript | {
"resource": ""
} |
q26374 | loadSVGFromString | train | function loadSVGFromString(string, callback, reviver) {
string = string.trim();
var doc;
if (typeof DOMParser !== 'undefined') {
var parser = new DOMParser();
if (parser && parser.parseFromString) {
doc = parser.parseFromString(string, 'text/xml');
}
}
else if (fabric.windo... | javascript | {
"resource": ""
} |
q26375 | getGradientDefs | train | function getGradientDefs(doc) {
var linearGradientEls = doc.getElementsByTagName('linearGradient'),
radialGradientEls = doc.getElementsByTagName('radialGradient'),
el,
gradientDefs = { };
for (var i = linearGradientEls.length; i--; ) {
el = linearGradientEls[i];
gradientDefs... | javascript | {
"resource": ""
} |
q26376 | train | function() {
var source = this.getSource();
var r = source[0].toString(16);
r = (r.length == 1) ? ('0' + r) : r;
var g = source[1].toString(16);
g = (g.length == 1) ? ('0' + g) : g;
var b = source[2].toString(16);
b = (b.length == 1) ? ('0' + b) : b;
return r.toUpperC... | javascript | {
"resource": ""
} | |
q26377 | train | function() {
var source = this.getSource(),
average = parseInt((source[0] * 0.3 + source[1] * 0.59 + source[2] * 0.11).toFixed(0), 10),
currentAlpha = source[3];
this.setSource([average, average, average, currentAlpha]);
return this;
} | javascript | {
"resource": ""
} | |
q26378 | train | function(threshold) {
var source = this.getSource(),
average = (source[0] * 0.3 + source[1] * 0.59 + source[2] * 0.11).toFixed(0),
currentAlpha = source[3],
threshold = threshold || 127;
average = (Number(average) < Number(threshold)) ? 0 : 255;
this.setSource([average, ... | javascript | {
"resource": ""
} | |
q26379 | train | function(otherColor) {
if (!(otherColor instanceof Color)) {
otherColor = new Color(otherColor);
}
var result = [],
alpha = this.getAlpha(),
otherAlpha = 0.5,
source = this.getSource(),
otherSource = otherColor.getSource();
for (var i = 0; i < 3;... | javascript | {
"resource": ""
} | |
q26380 | train | function (url, callback) { // TODO (kangax): test callback
fabric.util.loadImage(url, function(img) {
this.overlayImage = img;
callback && callback();
}, this);
return this;
} | javascript | {
"resource": ""
} | |
q26381 | train | 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 && ('backgroundImageStre... | javascript | {
"resource": ""
} | |
q26382 | train | 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);
}
... | javascript | {
"resource": ""
} | |
q26383 | train | 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 = h... | javascript | {
"resource": ""
} | |
q26384 | train | 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(canvasToD... | javascript | {
"resource": ""
} | |
q26385 | train | 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();
... | javascript | {
"resource": ""
} | |
q26386 | train | 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);... | javascript | {
"resource": ""
} | |
q26387 | train | 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=... | javascript | {
"resource": ""
} | |
q26388 | train | 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:c... | javascript | {
"resource": ""
} | |
q26389 | train | 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.int... | javascript | {
"resource": ""
} | |
q26390 | train | 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... | javascript | {
"resource": ""
} | |
q26391 | train | function () {
return this.getObjects().reduce(function (memo, current) {
memo += current.complexity ? current.complexity() : 0;
return memo;
}, 0);
} | javascript | {
"resource": ""
} | |
q26392 | train | function(callback, context) {
var objects = this.getObjects(),
i = objects.length;
while (i--) {
callback.call(context, objects[i], i, objects);
}
return this;
} | javascript | {
"resource": ""
} | |
q26393 | train | 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 | {
"resource": ""
} | |
q26394 | train | 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, 'mousem... | javascript | {
"resource": ""
} | |
q26395 | train | 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
/... | javascript | {
"resource": ""
} | |
q26396 | train | 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) +... | javascript | {
"resource": ""
} | |
q26397 | train | 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;
... | javascript | {
"resource": ""
} | |
q26398 | train | function (e) {
var pointer = getPointer(e);
return {
x: pointer.x - this._offset.left,
y: pointer.y - this._offset.top
};
} | javascript | {
"resource": ""
} | |
q26399 | train | 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 | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.