code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function getSites ($data) {
if ($data['mobileSites'].length === 0 && $data['sites'].length) {
$data['mobileSites'] = $data['sites'];
};
var $sites = (isMobileScreen() ? $data['mobileSites'] : ($data['sites'].length ? $data['sites']: [])).slice(0);
var $disabled = $data['disabled'];
if (typeof $sites == 'string') { $sites = $sites.split(/\s*,\s*/); }
if (typeof $disabled == 'string') { $disabled = $disabled.split(/\s*,\s*/); }
if (runningInWeChat()) {
$disabled.push('wechat');
}
// Remove elements
$disabled.length && $.each($disabled, function (i, el) {
var removeItemIndex = $.inArray(el, $sites);
if (removeItemIndex !== -1) {
$sites.splice(removeItemIndex, 1);
}
});
return $sites;
}
|
Get available site lists.
@param {Array} $data
@return {Array}
|
getSites
|
javascript
|
overtrue/share.js
|
src/js/jquery.share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/jquery.share.js
|
MIT
|
function makeUrl ($name, $data) {
var $template = $templates[$name];
$data['summary'] = $data['description'];
for (var $key in $data) {
if ($data.hasOwnProperty($key)) {
var $camelCaseKey = $name + $key.replace(/^[a-z]/, function($str){
return $str.toUpperCase();
});
var $value = encodeURIComponent($data[$camelCaseKey] === undefined ? $data[$key] : $data[$camelCaseKey]);
$template = $template.replace(new RegExp('{{'+$key.toUpperCase()+'}}', 'g'), $value);
}
}
return $template;
}
|
Build the url of icon.
@param {String} $name
@param {Object} $data
@return {String}
|
makeUrl
|
javascript
|
overtrue/share.js
|
src/js/jquery.share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/jquery.share.js
|
MIT
|
function hasFirstAPI () {
if (!$.fn.jquery) return true; // for Zepto
var versions = $.fn.jquery.split('.')
return ( versions[0] !== '1' ||
versions[0] === '1' && parseInt(versions[1], 10) >= 4 );
}
|
Check whether .first() is existed
https://api.jquery.com/first/
https://api.jquery.com/first-selector/
use .first() when version is greater or equal to 1.4
@return {boolean}
|
hasFirstAPI
|
javascript
|
overtrue/share.js
|
src/js/jquery.share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/jquery.share.js
|
MIT
|
function QR8bitByte(data) {
this.mode = QRMode.MODE_8BIT_BYTE;
this.data = data;
this.parsedData = [];
// Added to support UTF-8 Characters
for (var i = 0, l = this.data.length; i < l; i++) {
var byteArray = [];
var code = this.data.charCodeAt(i);
if (code > 0x10000) {
byteArray[0] = 0xF0 | ((code & 0x1C0000) >>> 18);
byteArray[1] = 0x80 | ((code & 0x3F000) >>> 12);
byteArray[2] = 0x80 | ((code & 0xFC0) >>> 6);
byteArray[3] = 0x80 | (code & 0x3F);
} else if (code > 0x800) {
byteArray[0] = 0xE0 | ((code & 0xF000) >>> 12);
byteArray[1] = 0x80 | ((code & 0xFC0) >>> 6);
byteArray[2] = 0x80 | (code & 0x3F);
} else if (code > 0x80) {
byteArray[0] = 0xC0 | ((code & 0x7C0) >>> 6);
byteArray[1] = 0x80 | (code & 0x3F);
} else {
byteArray[0] = code;
}
this.parsedData.push(byteArray);
}
this.parsedData = Array.prototype.concat.apply([], this.parsedData);
if (this.parsedData.length != this.data.length) {
this.parsedData.unshift(191);
this.parsedData.unshift(187);
this.parsedData.unshift(239);
}
}
|
@fileoverview
- Using the 'QRCode for Javascript library'
- Fixed dataset of 'QRCode for Javascript library' for support full-spec.
- this library has no dependencies.
@author davidshimjs
@see <a href="http://www.d-project.com/" target="_blank">http://www.d-project.com/</a>
@see <a href="http://jeromeetienne.github.com/jquery-qrcode/" target="_blank">http://jeromeetienne.github.com/jquery-qrcode/</a>
|
QR8bitByte
|
javascript
|
overtrue/share.js
|
src/js/qrcode.js
|
https://github.com/overtrue/share.js/blob/master/src/js/qrcode.js
|
MIT
|
function QRCodeModel(typeNumber, errorCorrectLevel) {
this.typeNumber = typeNumber;
this.errorCorrectLevel = errorCorrectLevel;
this.modules = null;
this.moduleCount = 0;
this.dataCache = null;
this.dataList = [];
}
|
@fileoverview
- Using the 'QRCode for Javascript library'
- Fixed dataset of 'QRCode for Javascript library' for support full-spec.
- this library has no dependencies.
@author davidshimjs
@see <a href="http://www.d-project.com/" target="_blank">http://www.d-project.com/</a>
@see <a href="http://jeromeetienne.github.com/jquery-qrcode/" target="_blank">http://jeromeetienne.github.com/jquery-qrcode/</a>
|
QRCodeModel
|
javascript
|
overtrue/share.js
|
src/js/qrcode.js
|
https://github.com/overtrue/share.js/blob/master/src/js/qrcode.js
|
MIT
|
function QRPolynomial(num,shift){if(num.length==undefined){throw new Error(num.length+"/"+shift);}
var offset=0;while(offset<num.length&&num[offset]==0){offset++;}
this.num=new Array(num.length-offset+shift);for(var i=0;i<num.length-offset;i++){this.num[i]=num[i+offset];}}
|
@fileoverview
- Using the 'QRCode for Javascript library'
- Fixed dataset of 'QRCode for Javascript library' for support full-spec.
- this library has no dependencies.
@author davidshimjs
@see <a href="http://www.d-project.com/" target="_blank">http://www.d-project.com/</a>
@see <a href="http://jeromeetienne.github.com/jquery-qrcode/" target="_blank">http://jeromeetienne.github.com/jquery-qrcode/</a>
|
QRPolynomial
|
javascript
|
overtrue/share.js
|
src/js/qrcode.js
|
https://github.com/overtrue/share.js/blob/master/src/js/qrcode.js
|
MIT
|
function _isSupportCanvas() {
return typeof CanvasRenderingContext2D != "undefined";
}
|
@fileoverview
- Using the 'QRCode for Javascript library'
- Fixed dataset of 'QRCode for Javascript library' for support full-spec.
- this library has no dependencies.
@author davidshimjs
@see <a href="http://www.d-project.com/" target="_blank">http://www.d-project.com/</a>
@see <a href="http://jeromeetienne.github.com/jquery-qrcode/" target="_blank">http://jeromeetienne.github.com/jquery-qrcode/</a>
|
_isSupportCanvas
|
javascript
|
overtrue/share.js
|
src/js/qrcode.js
|
https://github.com/overtrue/share.js/blob/master/src/js/qrcode.js
|
MIT
|
function _getAndroid() {
var android = false;
var sAgent = navigator.userAgent;
if (/android/i.test(sAgent)) { // android
android = true;
var aMat = sAgent.toString().match(/android ([0-9]\.[0-9])/i);
if (aMat && aMat[1]) {
android = parseFloat(aMat[1]);
}
}
return android;
}
|
@fileoverview
- Using the 'QRCode for Javascript library'
- Fixed dataset of 'QRCode for Javascript library' for support full-spec.
- this library has no dependencies.
@author davidshimjs
@see <a href="http://www.d-project.com/" target="_blank">http://www.d-project.com/</a>
@see <a href="http://jeromeetienne.github.com/jquery-qrcode/" target="_blank">http://jeromeetienne.github.com/jquery-qrcode/</a>
|
_getAndroid
|
javascript
|
overtrue/share.js
|
src/js/qrcode.js
|
https://github.com/overtrue/share.js/blob/master/src/js/qrcode.js
|
MIT
|
Drawing = function (el, htOption) {
this._el = el;
this._htOption = htOption;
}
|
@fileoverview
- Using the 'QRCode for Javascript library'
- Fixed dataset of 'QRCode for Javascript library' for support full-spec.
- this library has no dependencies.
@author davidshimjs
@see <a href="http://www.d-project.com/" target="_blank">http://www.d-project.com/</a>
@see <a href="http://jeromeetienne.github.com/jquery-qrcode/" target="_blank">http://jeromeetienne.github.com/jquery-qrcode/</a>
|
Drawing
|
javascript
|
overtrue/share.js
|
src/js/qrcode.js
|
https://github.com/overtrue/share.js/blob/master/src/js/qrcode.js
|
MIT
|
function makeSVG(tag, attrs) {
var el = document.createElementNS('http://www.w3.org/2000/svg', tag);
for (var k in attrs)
if (attrs.hasOwnProperty(k)) el.setAttribute(k, attrs[k]);
return el;
}
|
@fileoverview
- Using the 'QRCode for Javascript library'
- Fixed dataset of 'QRCode for Javascript library' for support full-spec.
- this library has no dependencies.
@author davidshimjs
@see <a href="http://www.d-project.com/" target="_blank">http://www.d-project.com/</a>
@see <a href="http://jeromeetienne.github.com/jquery-qrcode/" target="_blank">http://jeromeetienne.github.com/jquery-qrcode/</a>
|
makeSVG
|
javascript
|
overtrue/share.js
|
src/js/qrcode.js
|
https://github.com/overtrue/share.js/blob/master/src/js/qrcode.js
|
MIT
|
Drawing = function (el, htOption) {
this._el = el;
this._htOption = htOption;
}
|
@fileoverview
- Using the 'QRCode for Javascript library'
- Fixed dataset of 'QRCode for Javascript library' for support full-spec.
- this library has no dependencies.
@author davidshimjs
@see <a href="http://www.d-project.com/" target="_blank">http://www.d-project.com/</a>
@see <a href="http://jeromeetienne.github.com/jquery-qrcode/" target="_blank">http://jeromeetienne.github.com/jquery-qrcode/</a>
|
Drawing
|
javascript
|
overtrue/share.js
|
src/js/qrcode.js
|
https://github.com/overtrue/share.js/blob/master/src/js/qrcode.js
|
MIT
|
function _safeSetDataURI(fSuccess, fFail) {
var self = this;
self._fFail = fFail;
self._fSuccess = fSuccess;
// Check it just once
if (self._bSupportDataURI === null) {
var el = document.createElement("img");
var fOnError = function() {
self._bSupportDataURI = false;
if (self._fFail) {
self._fFail.call(self);
}
};
var fOnSuccess = function() {
self._bSupportDataURI = true;
if (self._fSuccess) {
self._fSuccess.call(self);
}
};
el.onabort = fOnError;
el.onerror = fOnError;
el.onload = fOnSuccess;
el.src = "data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; // the Image contains 1px data.
return;
} else if (self._bSupportDataURI === true && self._fSuccess) {
self._fSuccess.call(self);
} else if (self._bSupportDataURI === false && self._fFail) {
self._fFail.call(self);
}
}
|
Check whether the user's browser supports Data URI or not
@private
@param {Function} fSuccess Occurs if it supports Data URI
@param {Function} fFail Occurs if it doesn't support Data URI
|
_safeSetDataURI
|
javascript
|
overtrue/share.js
|
src/js/qrcode.js
|
https://github.com/overtrue/share.js/blob/master/src/js/qrcode.js
|
MIT
|
fOnError = function() {
self._bSupportDataURI = false;
if (self._fFail) {
self._fFail.call(self);
}
}
|
Check whether the user's browser supports Data URI or not
@private
@param {Function} fSuccess Occurs if it supports Data URI
@param {Function} fFail Occurs if it doesn't support Data URI
|
fOnError
|
javascript
|
overtrue/share.js
|
src/js/qrcode.js
|
https://github.com/overtrue/share.js/blob/master/src/js/qrcode.js
|
MIT
|
fOnSuccess = function() {
self._bSupportDataURI = true;
if (self._fSuccess) {
self._fSuccess.call(self);
}
}
|
Check whether the user's browser supports Data URI or not
@private
@param {Function} fSuccess Occurs if it supports Data URI
@param {Function} fFail Occurs if it doesn't support Data URI
|
fOnSuccess
|
javascript
|
overtrue/share.js
|
src/js/qrcode.js
|
https://github.com/overtrue/share.js/blob/master/src/js/qrcode.js
|
MIT
|
Drawing = function (el, htOption) {
this._bIsPainted = false;
this._android = _getAndroid();
this._htOption = htOption;
this._elCanvas = document.createElement("canvas");
this._elCanvas.width = htOption.width;
this._elCanvas.height = htOption.height;
el.appendChild(this._elCanvas);
this._el = el;
this._oContext = this._elCanvas.getContext("2d");
this._bIsPainted = false;
this._elImage = document.createElement("img");
this._elImage.alt = "Scan me!";
this._elImage.style.display = "none";
this._el.appendChild(this._elImage);
this._bSupportDataURI = null;
}
|
Drawing QRCode by using canvas
@constructor
@param {HTMLElement} el
@param {Object} htOption QRCode Options
|
Drawing
|
javascript
|
overtrue/share.js
|
src/js/qrcode.js
|
https://github.com/overtrue/share.js/blob/master/src/js/qrcode.js
|
MIT
|
function _getTypeNumber(sText, nCorrectLevel) {
var nType = 1;
var length = _getUTF8Length(sText);
for (var i = 0, len = QRCodeLimitLength.length; i <= len; i++) {
var nLimit = 0;
switch (nCorrectLevel) {
case QRErrorCorrectLevel.L :
nLimit = QRCodeLimitLength[i][0];
break;
case QRErrorCorrectLevel.M :
nLimit = QRCodeLimitLength[i][1];
break;
case QRErrorCorrectLevel.Q :
nLimit = QRCodeLimitLength[i][2];
break;
case QRErrorCorrectLevel.H :
nLimit = QRCodeLimitLength[i][3];
break;
}
if (length <= nLimit) {
break;
} else {
nType++;
}
}
if (nType > QRCodeLimitLength.length) {
throw new Error("Too long data");
}
return nType;
}
|
Get the type by string length
@private
@param {String} sText
@param {Number} nCorrectLevel
@return {Number} type
|
_getTypeNumber
|
javascript
|
overtrue/share.js
|
src/js/qrcode.js
|
https://github.com/overtrue/share.js/blob/master/src/js/qrcode.js
|
MIT
|
function _getUTF8Length(sText) {
var replacedText = encodeURI(sText).toString().replace(/\%[0-9a-fA-F]{2}/g, 'a');
return replacedText.length + (replacedText.length != sText ? 3 : 0);
}
|
Get the type by string length
@private
@param {String} sText
@param {Number} nCorrectLevel
@return {Number} type
|
_getUTF8Length
|
javascript
|
overtrue/share.js
|
src/js/qrcode.js
|
https://github.com/overtrue/share.js/blob/master/src/js/qrcode.js
|
MIT
|
function share(elem, options) {
var data = mixin({}, defaults, options || {}, dataset(elem));
if (data.imageSelector) {
data.image = querySelectorAlls(data.imageSelector).map(function(item) {
return item.src;
}).join('||');
}
addClass(elem, 'share-component social-share');
createIcons(elem, data);
createWechat(elem, data);
elem.initialized = true;
}
|
Initialize a share bar.
@param {Object} $options globals (optional).
@return {Void}
|
share
|
javascript
|
overtrue/share.js
|
src/js/social-share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/social-share.js
|
MIT
|
function createIcons(elem, data) {
var sites = getSites(data);
var isPrepend = data.mode == 'prepend';
each(isPrepend ? sites.reverse() : sites, function (name) {
var url = makeUrl(name, data);
var link = data.initialized ? getElementsByClassName(elem, 'icon-' + name) : createElementByString('<a class="social-share-icon icon-' + name + '"></a>');
if (!link.length) {
return true;
}
link[0].href = url;
if (name === 'wechat') {
link[0].tabindex = -1;
} else {
link[0].target = '_blank';
}
if (!data.initialized) {
isPrepend ? elem.insertBefore(link[0], elem.firstChild) : elem.appendChild(link[0]);
}
});
}
|
Create site icons
@param {Element} elem
@param {Object} data
|
createIcons
|
javascript
|
overtrue/share.js
|
src/js/social-share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/social-share.js
|
MIT
|
function createWechat (elem, data) {
var wechat = getElementsByClassName(elem, 'icon-wechat', 'a');
if (wechat.length === 0) {
return false;
}
var elems = createElementByString('<div class="wechat-qrcode"><h4>' + data.wechatQrcodeTitle + '</h4><div class="qrcode"></div><div class="help">' + data.wechatQrcodeHelper + '</div></div>');
var qrcode = getElementsByClassName(elems[0], 'qrcode', 'div');
new QRCode(qrcode[0], {text: data.url, width: data.wechatQrcodeSize, height: data.wechatQrcodeSize});
wechat[0].appendChild(elems[0]);
}
|
Create the wechat icon and QRCode.
@param {Element} elem
@param {Object} data
|
createWechat
|
javascript
|
overtrue/share.js
|
src/js/social-share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/social-share.js
|
MIT
|
function getSites(data) {
if (!data['mobileSites'].length) {
data['mobileSites'] = data['sites'];
}
var sites = (isMobileScreen ? data['mobileSites'] : data['sites']).slice(0);
var disabled = data['disabled'];
if (typeof sites == 'string') {
sites = sites.split(/\s*,\s*/);
}
if (typeof disabled == 'string') {
disabled = disabled.split(/\s*,\s*/);
}
if (runningInWeChat) {
disabled.push('wechat');
}
// Remove elements
disabled.length && each(disabled, function (it) {
sites.splice(inArray(it, sites), 1);
});
return sites;
}
|
Get available site lists.
@param {Object} data
@returns {Array}
|
getSites
|
javascript
|
overtrue/share.js
|
src/js/social-share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/social-share.js
|
MIT
|
function makeUrl(name, data) {
if (! data['summary']){
data['summary'] = data['description'];
}
return templates[name].replace(/\{\{(\w)(\w*)\}\}/g, function (m, fix, key) {
var nameKey = name + fix + key.toLowerCase();
key = (fix + key).toLowerCase();
return encodeURIComponent((data[nameKey] === undefined ? data[key] : data[nameKey]) || '');
});
}
|
Build the url of icon.
@param {String} name
@param {Object} data
@returns {String}
|
makeUrl
|
javascript
|
overtrue/share.js
|
src/js/social-share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/social-share.js
|
MIT
|
function querySelectorAlls(str) {
return (document.querySelectorAll || window.jQuery || window.Zepto || selector).call(document, str);
}
|
Supports querySelectorAll, jQuery, Zepto and simple selector.
@param str
@returns {*}
|
querySelectorAlls
|
javascript
|
overtrue/share.js
|
src/js/social-share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/social-share.js
|
MIT
|
function selector(str) {
var elems = [];
each(str.split(/\s*,\s*/), function(s) {
var m = s.match(/([#.])(\w+)/);
if (m === null) {
throw Error('Supports only simple single #ID or .CLASS selector.');
}
if (m[1]) {
var elem = document.getElementById(m[2]);
if (elem) {
elems.push(elem);
}
}
elems = elems.concat(getElementsByClassName(str));
});
return elems;
}
|
Simple selector.
@param {String} str #ID or .CLASS
@returns {Array}
|
selector
|
javascript
|
overtrue/share.js
|
src/js/social-share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/social-share.js
|
MIT
|
function addClass(elem, value) {
if (value && typeof value === "string") {
var classNames = (elem.className + ' ' + value).split(/\s+/);
var setClass = ' ';
each(classNames, function (className) {
if (setClass.indexOf(' ' + className + ' ') < 0) {
setClass += className + ' ';
}
});
elem.className = setClass.slice(1, -1);
}
}
|
Add the classNames for element.
@param {Element} elem
@param {String} value
|
addClass
|
javascript
|
overtrue/share.js
|
src/js/social-share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/social-share.js
|
MIT
|
function getMetaContentByName(name) {
return (document.getElementsByName(name)[0] || 0).content;
}
|
Get meta element content value
@param {String} name
@returns {String|*}
|
getMetaContentByName
|
javascript
|
overtrue/share.js
|
src/js/social-share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/social-share.js
|
MIT
|
function getElementsByClassName(elem, name, tag) {
if (elem.getElementsByClassName) {
return elem.getElementsByClassName(name);
}
var elements = [];
var elems = elem.getElementsByTagName(tag || '*');
name = ' ' + name + ' ';
each(elems, function (elem) {
if ((' ' + (elem.className || '') + ' ').indexOf(name) >= 0) {
elements.push(elem);
}
});
return elements;
}
|
Get elements By className for IE8-
@param {Element} elem element
@param {String} name className
@param {String} tag tagName
@returns {HTMLCollection|Array}
|
getElementsByClassName
|
javascript
|
overtrue/share.js
|
src/js/social-share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/social-share.js
|
MIT
|
function createElementByString(str) {
var div = document.createElement('div');
div.innerHTML = str;
return div.childNodes;
}
|
Create element by string.
@param {String} str
@returns {NodeList}
|
createElementByString
|
javascript
|
overtrue/share.js
|
src/js/social-share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/social-share.js
|
MIT
|
function dataset(elem) {
if (elem.dataset) {
return JSON.parse(JSON.stringify(elem.dataset));
}
var target = {};
if (elem.hasAttributes()) {
each(elem.attributes, function (attr) {
var name = attr.name;
if (name.indexOf('data-') !== 0) {
return true;
}
name = name.replace(/^data-/i, '')
.replace(/-(\w)/g, function (all, letter) {
return letter.toUpperCase();
});
target[name] = attr.value;
});
return target;
}
return {};
}
|
Get dataset object.
@param {Element} elem
@returns {Object}
|
dataset
|
javascript
|
overtrue/share.js
|
src/js/social-share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/social-share.js
|
MIT
|
function inArray(elem, arr, i) {
var len;
if (arr) {
if (Array$indexOf) {
return Array$indexOf.call(arr, elem, i);
}
len = arr.length;
i = i ? i < 0 ? Math.max(0, len + i) : i : 0;
for (; i < len; i++) {
// Skip accessing in sparse arrays
if (i in arr && arr[i] === elem) {
return i;
}
}
}
return -1;
}
|
found element in the array.
@param {Array|Object} elem
@param {Array} arr
@param {Number} i
@returns {Number}
|
inArray
|
javascript
|
overtrue/share.js
|
src/js/social-share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/social-share.js
|
MIT
|
function each(obj, callback) {
var length = obj.length;
if (length === undefined) {
for (var name in obj) {
if (obj.hasOwnProperty(name)) {
if (callback.call(obj[name], obj[name], name) === false) {
break;
}
}
}
} else {
for (var i = 0; i < length; i++) {
if (callback.call(obj[i], obj[i], i) === false) {
break;
}
}
}
}
|
Simple each.
@param {Array|Object} obj
@param {Function} callback
@returns {*}
|
each
|
javascript
|
overtrue/share.js
|
src/js/social-share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/social-share.js
|
MIT
|
function alReady ( fn ) {
var add = 'addEventListener';
var pre = document[ add ] ? '' : 'on';
~document.readyState.indexOf( 'm' ) ? fn() :
'load DOMContentLoaded readystatechange'.replace( /\w+/g, function( type, i ) {
( i ? document : window )
[ pre ? 'attachEvent' : add ]
(
pre + type,
function(){ if ( fn ) if ( i < 6 || ~document.readyState.indexOf( 'm' ) ) fn(), fn = 0 },
!1
)
})
}
|
Dom ready.
@param {Function} fn
@link https://github.com/jed/alReady.js
|
alReady
|
javascript
|
overtrue/share.js
|
src/js/social-share.js
|
https://github.com/overtrue/share.js/blob/master/src/js/social-share.js
|
MIT
|
function runExec(container) {
var options = {
Cmd: ['bash', '-c', 'echo test $VAR'],
Env: ['VAR=ttslkfjsdalkfj'],
AttachStdout: true,
AttachStderr: true
};
container.exec(options, function(err, exec) {
if (err) return;
exec.start(function(err, stream) {
if (err) return;
container.modem.demuxStream(stream, process.stdout, process.stderr);
exec.inspect(function(err, data) {
if (err) return;
console.log(data);
});
});
});
}
|
Get env list from running container
@param container
|
runExec
|
javascript
|
apocas/dockerode
|
examples/exec_running_container.js
|
https://github.com/apocas/dockerode/blob/master/examples/exec_running_container.js
|
Apache-2.0
|
Config = function(modem, id) {
this.modem = modem;
this.id = id;
}
|
Represents a config
@param {Object} modem docker-modem
@param {String} id Config's id
|
Config
|
javascript
|
apocas/dockerode
|
lib/config.js
|
https://github.com/apocas/dockerode/blob/master/lib/config.js
|
Apache-2.0
|
Container = function(modem, id) {
this.modem = modem;
this.id = id;
this.defaultOptions = {
top: {},
start: {},
commit: {},
stop: {},
pause: {},
unpause: {},
restart: {},
resize: {},
attach: {},
remove: {},
copy: {},
kill: {},
exec: {},
rename: {},
log: {},
stats: {},
getArchive: {},
infoArchive: {},
putArchive: {},
update: {},
wait: {}
};
}
|
Represents a Container
@param {Object} modem docker-modem
@param {String} id Container's ID
|
Container
|
javascript
|
apocas/dockerode
|
lib/container.js
|
https://github.com/apocas/dockerode/blob/master/lib/container.js
|
Apache-2.0
|
function dial(callback) {
util.prepareBuildContext(file, (ctx) => {
optsf.file = ctx;
self.modem.dial(optsf, callback);
});
}
|
Builds an image
@param {String} file File
@param {Object} opts Options (optional)
@param {Function} callback Callback
|
dial
|
javascript
|
apocas/dockerode
|
lib/docker.js
|
https://github.com/apocas/dockerode/blob/master/lib/docker.js
|
Apache-2.0
|
function dialWithSession(callback) {
if (opts?.version === "2") {
withSession(self, optsf.authconfig,(err, sessionId, done) => {
if (err) {
return callback(err);
}
optsf.options.session = sessionId;
dial((err, data) => {
callback(err, data);
if (data) {
data.on("end", done);
}
});
});
} else {
dial(callback);
}
}
|
Builds an image
@param {String} file File
@param {Object} opts Options (optional)
@param {Function} callback Callback
|
dialWithSession
|
javascript
|
apocas/dockerode
|
lib/docker.js
|
https://github.com/apocas/dockerode/blob/master/lib/docker.js
|
Apache-2.0
|
Exec = function(modem, id) {
this.modem = modem;
this.id = id;
}
|
Represents an Exec
@param {Object} modem docker-modem
@param {String} id Exec's ID
|
Exec
|
javascript
|
apocas/dockerode
|
lib/exec.js
|
https://github.com/apocas/dockerode/blob/master/lib/exec.js
|
Apache-2.0
|
Image = function(modem, name) {
this.modem = modem;
this.name = name;
}
|
Represents an image
@param {Object} modem docker-modem
@param {String} name Image's name
|
Image
|
javascript
|
apocas/dockerode
|
lib/image.js
|
https://github.com/apocas/dockerode/blob/master/lib/image.js
|
Apache-2.0
|
Network = function(modem, id) {
this.modem = modem;
this.id = id;
}
|
Represents an network
@param {Object} modem docker-modem
@param {String} id Network's id
|
Network
|
javascript
|
apocas/dockerode
|
lib/network.js
|
https://github.com/apocas/dockerode/blob/master/lib/network.js
|
Apache-2.0
|
Node = function(modem, id) {
this.modem = modem;
this.id = id;
}
|
Represents an Node
@param {Object} modem docker-modem
@param {String} id Node's ID
|
Node
|
javascript
|
apocas/dockerode
|
lib/node.js
|
https://github.com/apocas/dockerode/blob/master/lib/node.js
|
Apache-2.0
|
Plugin = function(modem, name, remote) {
this.modem = modem;
this.name = name;
this.remote = remote || name;
}
|
Represents a plugin
@param {Object} modem docker-modem
@param {String} name Plugin's name
|
Plugin
|
javascript
|
apocas/dockerode
|
lib/plugin.js
|
https://github.com/apocas/dockerode/blob/master/lib/plugin.js
|
Apache-2.0
|
Secret = function(modem, id) {
this.modem = modem;
this.id = id;
}
|
Represents a secret
@param {Object} modem docker-modem
@param {String} id Secret's id
|
Secret
|
javascript
|
apocas/dockerode
|
lib/secret.js
|
https://github.com/apocas/dockerode/blob/master/lib/secret.js
|
Apache-2.0
|
Service = function(modem, id) {
this.modem = modem;
this.id = id;
}
|
Represents an Service
@param {Object} modem docker-modem
@param {String} id Service's ID
|
Service
|
javascript
|
apocas/dockerode
|
lib/service.js
|
https://github.com/apocas/dockerode/blob/master/lib/service.js
|
Apache-2.0
|
Task = function(modem, id) {
this.modem = modem;
this.id = id;
this.defaultOptions = {
log: {}
};
}
|
Represents an Task
@param {Object} modem docker-modem
@param {String} id Task's ID
|
Task
|
javascript
|
apocas/dockerode
|
lib/task.js
|
https://github.com/apocas/dockerode/blob/master/lib/task.js
|
Apache-2.0
|
Volume = function(modem, name) {
this.modem = modem;
this.name = name;
}
|
Represents a volume
@param {Object} modem docker-modem
@param {String} name Volume's name
|
Volume
|
javascript
|
apocas/dockerode
|
lib/volume.js
|
https://github.com/apocas/dockerode/blob/master/lib/volume.js
|
Apache-2.0
|
function handler(err, container) {
expect(err).to.be.null;
expect(container).to.be.ok;
var attach_opts = {
stream: true,
stdin: true,
stdout: true,
stderr: true,
hijack: true
};
container.attach(attach_opts, function handler(err, stream) {
expect(err).to.be.null;
expect(stream).to.be.ok;
var memStream = new MemoryStream();
var output = '';
memStream.on('data', function(data) {
output += data.toString();
});
stream.pipe(memStream);
container.start(function(err, data) {
expect(err).to.be.null;
var aux = randomString(size) + '\n\x04';
stream.write(aux);
container.wait(function(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
expect(+output.slice(size)).to.equal(size + 1);
done();
});
});
});
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
function handler(err, container) {
expect(err).to.be.null;
expect(container).to.be.ok;
var attach_opts = {
stream: true,
stdin: true,
stdout: true,
stderr: true,
hijack: true
};
container.attach(attach_opts, function handler(err, stream) {
expect(err).to.be.null;
expect(stream).to.be.ok;
var memStream = new MemoryStream();
var output = '';
memStream.on('data', function(data) {
output += data.toString();
});
stream.pipe(memStream);
container.start(function(err, data) {
expect(err).to.be.null;
stream.write('printf "' + randomString(size) + '" | wc -c; exit;\n');
container.wait(function(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
expect(parseInt(output.replace(/\D/g, ''))).to.equal(size);
done();
});
});
});
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
function handler(err, container) {
expect(err).to.be.null;
expect(container).to.be.ok;
container.attach({
stream: true,
stdout: true,
stderr: true
}, function handler(err, stream) {
expect(err).to.be.null;
expect(stream).to.be.ok;
var memStream = new MemoryStream();
var output = '';
memStream.on('data', function(data) {
output += data.toString();
});
container.modem.demuxStream(stream, memStream, memStream);
container.start(function(err, data) {
expect(err).to.be.null;
container.wait(function(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
expect(output).to.match(/.*user.*load average.*/);
done();
});
});
});
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
function handler(err, container) {
expect(err).to.be.null;
expect(container).to.be.ok;
var attach_opts = {
stream: true,
stdin: true,
stdout: true,
stderr: true,
hijack: true
};
container.attach(attach_opts, function handler(err, stream) {
expect(err).to.be.null;
expect(stream).to.be.ok;
var memStream = new MemoryStream();
var output = '';
memStream.on('data', function(data) {
output += data.toString();
});
stream.pipe(memStream);
container.start(function(err, data) {
expect(err).to.be.null;
stream.write("uptime; exit\n");
container.wait(function(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
expect(output).to.match(/.*user.*load average.*/);
done();
});
});
});
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
function handler(err, container) {
expect(err).to.be.null;
expect(container).to.be.ok;
var attach_opts = {
stream: true,
hijack: true,
stdin: true,
stdout: true,
stderr: true
};
container.attach(attach_opts, function handler(err, stream) {
expect(err).to.be.null;
expect(stream).to.be.an.instanceof(Socket);
var memStream = new MemoryStream();
var output = '';
memStream.on('data', function(data) {
output += data.toString();
});
stream.pipe(memStream);
container.start(function(err, data) {
expect(err).to.be.null;
stream.write("uptime; exit\n");
container.wait(function(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
expect(output).to.match(/.*user.*load average.*/);
done();
});
});
});
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
function handler(err, data) {
expect(err).to.be.null;
done();
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
function handler(err, stream) {
expect(err).to.be.null;
expect(stream).to.be.ok;
done();
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
function handler(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
done();
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
function handler(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
done();
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
function handler(err, stream) {
expect(err).to.be.null;
expect(stream.pipe).to.be.ok;
done();
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
function handler(err, exec) {
expect(err).to.be.null;
exec.start(function(err, stream) {
expect(err).to.be.null;
expect(stream.pipe).to.be.ok;
exec.inspect(function(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
done();
});
});
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
function handler(err, exec) {
expect(err).to.be.null;
exec.start()
.then(stream => {
expect(stream.pipe).to.be.ok;
done();
})
.catch(done);
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
function handler(err, exec) {
expect(err).to.be.null;
exec.start(startOpts, function(err, stream) {
expect(err).to.be.null;
//expect(stream).to.be.ok;
expect(stream).to.be.an.instanceof(Socket);
//return done();
var SAMPLE = 'echo\nall\nof\nme\n';
var bufs = [];
stream.on('data', function(d) {
bufs.push(d);
}).on('end', function() {
var out = Buffer.concat(bufs);
expect(out.readUInt8(0)).to.equal(1);
expect(out.readUInt32BE(4)).to.equal(SAMPLE.length);
expect(out.toString('utf8', 8)).to.equal(SAMPLE);
done();
});
stream.end(SAMPLE);
//stream.end();
});
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
function handler(err, stream) {
expect(err).to.be.null;
expect(stream).to.be.ok;
done();
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
function handler(err, data) {
expect(err).to.be.null;
done();
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
function handler(err, data) {
expect(err).to.be.null;
done();
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
function handler(err, data) {
expect(err).to.be.null;
done();
}
|
simple test that writes 1000 bytes to the "wc -c" command, that command
returns the number of bytes it received, so it should return 1000 for this test
|
handler
|
javascript
|
apocas/dockerode
|
test/container.js
|
https://github.com/apocas/dockerode/blob/master/test/container.js
|
Apache-2.0
|
parseComment = function(comment) {
// from esdoc (https://github.com/esdoc/esdoc/blob/master/src/Parser/CommentParser.js)
comment = comment.replace(/\r\n/gm, '\n') // for windows
comment = comment.replace(/^\t*\s?/gm, '') // remove trailing tab
comment = comment.replace(/^\*\s?/, '') // remove first '*'
comment = comment.replace(/ $/, '') // remove last ' '
comment = comment.replace(/^ *\* ?/gm, '') // remove line head '*'
if (comment.charAt(0) !== '@') comment = '@desc ' + comment // auto insert @desc
comment = comment.replace(/\s*$/, '') // remove tail space.
comment = comment.replace(/^(@\w+)$/gm, '$1 \\TRUE') // auto insert tag text to non-text tag (e.g. @interface)
comment = comment.replace(/^(@\w+)\s(.*)/gm, '\\Z$1\\Z$2') // insert separator (\\Z@tag\\Ztext)
var lines = comment.split('\\Z')
var tagName = ''
var tagValue = ''
var tags = []
for (var i = 0; i < lines.length; i++) {
var line = lines[i]
if (line.charAt(0) === '@') {
tagName = line
var nextLine = lines[i + 1]
if (nextLine.charAt(0) === '@') {
tagValue = ''
} else {
tagValue = nextLine
i++
}
tagValue = tagValue.replace('\\TRUE', '').replace(/^\n/, '').replace(/\n*$/, '')
var tag = {}
tag[tagName] = tagValue
tags.push(tag)
}
}
return tags
}
|
A little module that extracts the API information from doc comments.
@type {exports|module.exports}
|
parseComment
|
javascript
|
ritzyed/ritzy
|
extractapi.js
|
https://github.com/ritzyed/ritzy/blob/master/extractapi.js
|
Apache-2.0
|
printApiMethod = function(apiMethod) {
//console.log(metadata)
//console.log(metadata.comments)
var docString = '====\n' +
'https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js#L' + apiMethod.line + '[Ritzy.' + apiMethod.name + ']::\n' +
apiMethod.comments.filter(function(c) { return c.hasOwnProperty('@desc') })[0]['@desc'] + '\n'
var params = apiMethod.comments.filter(function(c) { return c.hasOwnProperty('@param') })
if(params.length > 0) {
docString += '\nParameters:::\n'
params.map(function(p) { return p['@param'] }).forEach(function(p) {
docString += '* ' + p + '\n'
})
}
docString += '====\n'
return docString
}
|
A little module that extracts the API information from doc comments.
@type {exports|module.exports}
|
printApiMethod
|
javascript
|
ritzyed/ritzy
|
extractapi.js
|
https://github.com/ritzyed/ritzy/blob/master/extractapi.js
|
Apache-2.0
|
byApiMethod = function(apiDocString) {
return function(apiMethod) {
return apiMethod.comments.filter(function(c) {
return c.hasOwnProperty('@apidoc') && c['@apidoc'] === apiDocString
}).length > 0
}
}
|
A little module that extracts the API information from doc comments.
@type {exports|module.exports}
|
byApiMethod
|
javascript
|
ritzyed/ritzy
|
extractapi.js
|
https://github.com/ritzyed/ritzy/blob/master/extractapi.js
|
Apache-2.0
|
writeSection = function(section, sectionRef, sectionDescription) {
process.stdout.write('[[' + sectionRef + ']]\n== ' + section + '\n\n' + sectionDescription + '\n\n')
apiInfo.filter(byApiMethod(section)).map(printApiMethod).forEach(function(apiDoc) {
process.stdout.write(apiDoc + '\n')
})
}
|
A little module that extracts the API information from doc comments.
@type {exports|module.exports}
|
writeSection
|
javascript
|
ritzyed/ritzy
|
extractapi.js
|
https://github.com/ritzyed/ritzy/blob/master/extractapi.js
|
Apache-2.0
|
initConfig = function(config) {
let defaultVal = function(key, defaultValue) {
if(!config.hasOwnProperty(key)) {
if(typeof defaultValue === 'function') {
config[key] = defaultValue()
} else {
config[key] = defaultValue
}
}
}
let requireVal = function(key) {
if(!config.hasOwnProperty(key)) {
throw new Error(`Configuration must contain a property '${key}'.`)
}
}
let webFontPromise = function(webFontFamily) {
return new Promise(function(resolve, reject) {
let webFontConfig = {
classes: false,
active() {
resolve()
},
inactive() {
reject(Error('Webfonts [' + JSON.stringify(webFontFamily) + '] could not be loaded.'))
}
}
Object.keys(webFontFamily).forEach(k => webFontConfig[k] = webFontFamily[k])
WebFont.load(webFontConfig)
})
}
let otFontPromise = function(fontUrl) {
return new Promise(function(resolve, reject) {
OpenType.load(fontUrl, (err, font) => {
if (err) {
reject(Error('Opentype.js font ' + fontUrl + ' could not be loaded: ' + err))
} else {
resolve(font)
}
})
})
}
defaultVal('localFontPath', '/fonts/')
defaultVal('fontRegular', 'OpenSans-Regular-Latin.ttf')
defaultVal('fontBold', 'OpenSans-Bold-Latin.ttf')
defaultVal('fontBoldItalic', 'OpenSans-BoldItalic-Latin.ttf')
defaultVal('fontItalic', 'OpenSans-Italic-Latin.ttf')
defaultVal('webFontFamily', {
google: {
families: ['Open Sans:400italic,700italic,700,400']
}
})
//noinspection JSUnresolvedVariable
return Promise.all([
otFontPromise(config.localFontPath + config.fontRegular),
otFontPromise(config.localFontPath + config.fontBold),
otFontPromise(config.localFontPath + config.fontBoldItalic),
otFontPromise(config.localFontPath + config.fontItalic),
webFontPromise(config.webFontFamily)
]).then(function(fontsResult) {
config.fonts = {
regular: fontsResult[0],
bold: fontsResult[1],
boldItalic: fontsResult[2],
italic: fontsResult[3]
}
// all units per em must be the same (they are for OpenSans)
config.unitsPerEm = fontsResult[0].unitsPerEm
// we could detect minFontSize when needed (with this one-time approach, if the user changes it, they will need to refresh)
config.minFontSize = detectMinFontSize()
// if config.skin is undefined or 'default', we load default-skin.less
defaultVal('skin', 'default')
if(config.skin === 'default') {
require('./styles/default-skin.less')
}
requireVal('id')
requireVal('fonts')
defaultVal('fontSize', 18)
requireVal('minFontSize')
requireVal('unitsPerEm')
defaultVal('width', 600)
defaultVal('marginH', 30)
defaultVal('marginV', 35)
defaultVal('userId', () => {
let localUser = window.localStorage.getItem('localuser') || 'A' + parseInt(Math.random() * 10000).toString(16)
window.localStorage.setItem('localuser', localUser)
return localUser
})
defaultVal('userName', config.userId)
defaultVal('wsPort', null)
defaultVal('renderOptimizations', true)
defaultVal('showErrorNotification', true)
return config
})
}
|
This is the main entry point to the Ritzy editor. See client.js for an example of how it can be used. This
is basically an API wrapper around the Editor react component, which can be used directly as well.
|
initConfig
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
initConfig = function(config) {
let defaultVal = function(key, defaultValue) {
if(!config.hasOwnProperty(key)) {
if(typeof defaultValue === 'function') {
config[key] = defaultValue()
} else {
config[key] = defaultValue
}
}
}
let requireVal = function(key) {
if(!config.hasOwnProperty(key)) {
throw new Error(`Configuration must contain a property '${key}'.`)
}
}
let webFontPromise = function(webFontFamily) {
return new Promise(function(resolve, reject) {
let webFontConfig = {
classes: false,
active() {
resolve()
},
inactive() {
reject(Error('Webfonts [' + JSON.stringify(webFontFamily) + '] could not be loaded.'))
}
}
Object.keys(webFontFamily).forEach(k => webFontConfig[k] = webFontFamily[k])
WebFont.load(webFontConfig)
})
}
let otFontPromise = function(fontUrl) {
return new Promise(function(resolve, reject) {
OpenType.load(fontUrl, (err, font) => {
if (err) {
reject(Error('Opentype.js font ' + fontUrl + ' could not be loaded: ' + err))
} else {
resolve(font)
}
})
})
}
defaultVal('localFontPath', '/fonts/')
defaultVal('fontRegular', 'OpenSans-Regular-Latin.ttf')
defaultVal('fontBold', 'OpenSans-Bold-Latin.ttf')
defaultVal('fontBoldItalic', 'OpenSans-BoldItalic-Latin.ttf')
defaultVal('fontItalic', 'OpenSans-Italic-Latin.ttf')
defaultVal('webFontFamily', {
google: {
families: ['Open Sans:400italic,700italic,700,400']
}
})
//noinspection JSUnresolvedVariable
return Promise.all([
otFontPromise(config.localFontPath + config.fontRegular),
otFontPromise(config.localFontPath + config.fontBold),
otFontPromise(config.localFontPath + config.fontBoldItalic),
otFontPromise(config.localFontPath + config.fontItalic),
webFontPromise(config.webFontFamily)
]).then(function(fontsResult) {
config.fonts = {
regular: fontsResult[0],
bold: fontsResult[1],
boldItalic: fontsResult[2],
italic: fontsResult[3]
}
// all units per em must be the same (they are for OpenSans)
config.unitsPerEm = fontsResult[0].unitsPerEm
// we could detect minFontSize when needed (with this one-time approach, if the user changes it, they will need to refresh)
config.minFontSize = detectMinFontSize()
// if config.skin is undefined or 'default', we load default-skin.less
defaultVal('skin', 'default')
if(config.skin === 'default') {
require('./styles/default-skin.less')
}
requireVal('id')
requireVal('fonts')
defaultVal('fontSize', 18)
requireVal('minFontSize')
requireVal('unitsPerEm')
defaultVal('width', 600)
defaultVal('marginH', 30)
defaultVal('marginV', 35)
defaultVal('userId', () => {
let localUser = window.localStorage.getItem('localuser') || 'A' + parseInt(Math.random() * 10000).toString(16)
window.localStorage.setItem('localuser', localUser)
return localUser
})
defaultVal('userName', config.userId)
defaultVal('wsPort', null)
defaultVal('renderOptimizations', true)
defaultVal('showErrorNotification', true)
return config
})
}
|
This is the main entry point to the Ritzy editor. See client.js for an example of how it can be used. This
is basically an API wrapper around the Editor react component, which can be used directly as well.
|
initConfig
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
defaultVal = function(key, defaultValue) {
if(!config.hasOwnProperty(key)) {
if(typeof defaultValue === 'function') {
config[key] = defaultValue()
} else {
config[key] = defaultValue
}
}
}
|
This is the main entry point to the Ritzy editor. See client.js for an example of how it can be used. This
is basically an API wrapper around the Editor react component, which can be used directly as well.
|
defaultVal
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
defaultVal = function(key, defaultValue) {
if(!config.hasOwnProperty(key)) {
if(typeof defaultValue === 'function') {
config[key] = defaultValue()
} else {
config[key] = defaultValue
}
}
}
|
This is the main entry point to the Ritzy editor. See client.js for an example of how it can be used. This
is basically an API wrapper around the Editor react component, which can be used directly as well.
|
defaultVal
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
requireVal = function(key) {
if(!config.hasOwnProperty(key)) {
throw new Error(`Configuration must contain a property '${key}'.`)
}
}
|
This is the main entry point to the Ritzy editor. See client.js for an example of how it can be used. This
is basically an API wrapper around the Editor react component, which can be used directly as well.
|
requireVal
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
requireVal = function(key) {
if(!config.hasOwnProperty(key)) {
throw new Error(`Configuration must contain a property '${key}'.`)
}
}
|
This is the main entry point to the Ritzy editor. See client.js for an example of how it can be used. This
is basically an API wrapper around the Editor react component, which can be used directly as well.
|
requireVal
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
webFontPromise = function(webFontFamily) {
return new Promise(function(resolve, reject) {
let webFontConfig = {
classes: false,
active() {
resolve()
},
inactive() {
reject(Error('Webfonts [' + JSON.stringify(webFontFamily) + '] could not be loaded.'))
}
}
Object.keys(webFontFamily).forEach(k => webFontConfig[k] = webFontFamily[k])
WebFont.load(webFontConfig)
})
}
|
This is the main entry point to the Ritzy editor. See client.js for an example of how it can be used. This
is basically an API wrapper around the Editor react component, which can be used directly as well.
|
webFontPromise
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
webFontPromise = function(webFontFamily) {
return new Promise(function(resolve, reject) {
let webFontConfig = {
classes: false,
active() {
resolve()
},
inactive() {
reject(Error('Webfonts [' + JSON.stringify(webFontFamily) + '] could not be loaded.'))
}
}
Object.keys(webFontFamily).forEach(k => webFontConfig[k] = webFontFamily[k])
WebFont.load(webFontConfig)
})
}
|
This is the main entry point to the Ritzy editor. See client.js for an example of how it can be used. This
is basically an API wrapper around the Editor react component, which can be used directly as well.
|
webFontPromise
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
inactive() {
reject(Error('Webfonts [' + JSON.stringify(webFontFamily) + '] could not be loaded.'))
}
|
This is the main entry point to the Ritzy editor. See client.js for an example of how it can be used. This
is basically an API wrapper around the Editor react component, which can be used directly as well.
|
inactive
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
otFontPromise = function(fontUrl) {
return new Promise(function(resolve, reject) {
OpenType.load(fontUrl, (err, font) => {
if (err) {
reject(Error('Opentype.js font ' + fontUrl + ' could not be loaded: ' + err))
} else {
resolve(font)
}
})
})
}
|
This is the main entry point to the Ritzy editor. See client.js for an example of how it can be used. This
is basically an API wrapper around the Editor react component, which can be used directly as well.
|
otFontPromise
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
otFontPromise = function(fontUrl) {
return new Promise(function(resolve, reject) {
OpenType.load(fontUrl, (err, font) => {
if (err) {
reject(Error('Opentype.js font ' + fontUrl + ' could not be loaded: ' + err))
} else {
resolve(font)
}
})
})
}
|
This is the main entry point to the Ritzy editor. See client.js for an example of how it can be used. This
is basically an API wrapper around the Editor react component, which can be used directly as well.
|
otFontPromise
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
renderEditor = function(config, renderTarget) {
const editorFactory = React.createFactory(Editor)
React.render(
editorFactory(config),
renderTarget
)
}
|
This is the main entry point to the Ritzy editor. See client.js for an example of how it can be used. This
is basically an API wrapper around the Editor react component, which can be used directly as well.
|
renderEditor
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
renderEditor = function(config, renderTarget) {
const editorFactory = React.createFactory(Editor)
React.render(
editorFactory(config),
renderTarget
)
}
|
This is the main entry point to the Ritzy editor. See client.js for an example of how it can be used. This
is basically an API wrapper around the Editor react component, which can be used directly as well.
|
renderEditor
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
setUserName(userName) {
this.updateConfig('userName', userName)
}
|
Sets the user name of the editor's user, which will be associated with all remote cursors that
represent the cursor in this editor. Updates remote cursors immediately.
@apidoc Configuration
@param userName The user name to set.
@returns {*}
|
setUserName
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
setFontSize(fontSize) {
this.updateConfig('fontSize', fontSize)
}
|
Sets the editor font size, and update the editor contents immediately to reflect this.
@apidoc Configuration
@param fontSize The font size, in pixels, to set.
@returns {*}
|
setFontSize
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
setWidth(width) {
this.updateConfig('width', width)
}
|
Sets the editor width in pixels, and update the editor immediately to reflect this.
@apidoc Configuration
@param width The width of the editor in pixels. This includes the internal margins.
@returns {*}
|
setWidth
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
setMargin(horizontal, vertical) {
this.updateConfig('margin', { horizontal: horizontal, vertical: vertical })
}
|
Sets the editor internal margins, and update the editor contents immediately to reflect this.
Margins provide a useful "click area" where the user can click to go to the beginning
or end of a line (or first or last line) without being super-precise about the click.
@apidoc Configuration
@param horizontal The horizontal (left-right) margins.
@param vertical The vertical (top-bottom) margins.
@returns {*}
|
setMargin
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
setMarginHorizontal(horizontal) {
let margin = { horizontal: horizontal, vertical: this.config.margin.vertical }
this.updateConfig('margin', margin)
}
|
Sets the editor internal horizontal margin.
@apidoc Configuration
@param horizontal The horizontal (left-right) margins.
@returns {*}
|
setMarginHorizontal
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
setMarginVertical(vertical) {
let margin = { horizontal: this.config.margin.horizontal, vertical: vertical }
this.updateConfig('margin', margin)
}
|
Sets the editor internal vertical margin.
@apidoc Configuration
@param vertical The vertical (top-bottom) margins.
@returns {*}
|
setMarginVertical
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
getContents() {
return EditorStore.getContents()
}
|
Returns the contents of the editor as an array of Char objects. The Char object is from the
underlying CRDT data store.
@apidoc Contents
@returns Array[Char]
|
getContents
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
getContentsRich() {
return EditorStore.getContentsRich()
}
|
Returns the contents of the editor in a rich text JSON format representing the rich text chunks and the
associated attributes.
@apidoc Contents
@returns {*}
|
getContentsRich
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
getContentsHtml() {
return EditorStore.getContentsHtml()
}
|
Returns the contents of the editor as HTML.
@apidoc Contents
@returns {*}
|
getContentsHtml
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
getContentsText() {
return EditorStore.getContentsText()
}
|
Returns the contents of the editor as plain text.
@apidoc Contents
@returns {*}
|
getContentsText
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
getSelection() {
return EditorStore.getSelection()
}
|
Returns the contents of the current selection as an array of Char objects. The Char object is from the
underlying CRDT data store.
Returns the contents of the current selection in the underlying CRDT data storage format.
@apidoc Selection
@returns Array[Char]
|
getSelection
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
getSelectionRich() {
return EditorStore.getSelectionRich()
}
|
Returns the contents of the current selection in a rich text JSON format representing the rich text chunks
and the associated attributes.
@apidoc Selection
@returns {*}
|
getSelectionRich
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
getSelectionHtml() {
return EditorStore.getSelectionHtml()
}
|
Returns the contents of the current selection as HTML.
@apidoc Selection
@returns {*}
|
getSelectionHtml
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
getSelectionText() {
return EditorStore.getSelectionText()
}
|
Returns the contents of the current selection as plain text.
@apidoc Selection
@returns {*}
|
getSelectionText
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
getPosition() {
return EditorStore.getPosition()
}
|
Returns the current position of the local cursor. The position is a character at which the cursor is placed
(the point just after the character), and an eolStart attribute. The eolStart attribute is when the position is
at the character at the end of a line (will generally be space if it is a soft break, and a newline if it is a
hard break), if eolStart is false the cursor is at the end of the line with that character, and if eolStart is
true, the cursor is at the start of the next line. This is necessary because both cursor positions represent
the *same* character position.
@apidoc Cursors
@returns {*}
|
getPosition
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
getRemoteCursors() {
return EditorStore.getRemoteCursors()
}
|
Gets all remote cursors currently active in the document. Each remote cursor has attributes such as name
('name'), the last update time ('ms'), and the remote position of the cursor.
@apidoc Cursors
@returns Array[{*}]
|
getRemoteCursors
|
javascript
|
ritzyed/ritzy
|
src/ritzy.js
|
https://github.com/ritzyed/ritzy/blob/master/src/ritzy.js
|
Apache-2.0
|
getDefaultProps() {
return {
renderOptimizations: true
}
}
|
A React component to obtain TextInput from the user and insert it into the editor. We capture shortcuts
via Mousetrap.js bindings. All other characters bypass Mousetrap and are inserted by the browser into the
focused hidden text input area (so the browser's internal machinery deals with the key capture and translation
to characters, so it should work for complex IME input as well), and from there the browser triggers the
onInput event on the input area, at which point we grab the character and place it into the editor.
|
getDefaultProps
|
javascript
|
ritzyed/ritzy
|
src/components/TextInput.js
|
https://github.com/ritzyed/ritzy/blob/master/src/components/TextInput.js
|
Apache-2.0
|
componentDidMount() {
this.input = React.findDOMNode(this.refs.input)
this.hiddenContainer = React.findDOMNode(this.refs.hiddenContainer)
this.ieClipboardDiv = React.findDOMNode(this.refs.ieClipboardDiv)
// for HTML paste support in IE -- ignored by Chrome/Firefox
this.input.addEventListener('beforepaste', () => {
if (document.activeElement !== this.ieClipboardDiv) {
this._focusIeClipboardDiv()
}
}, true)
let keyBindings = new Mousetrap(this.input)
keyBindings.bind(['up', 'down', 'left', 'right'], this._handleKeyArrow)
keyBindings.bind(['shift+up', 'shift+down', 'shift+left', 'shift+right'], this._handleKeySelectionArrow)
keyBindings.bind(['pageup', 'pagedown'], this._handleKeyNavigationPage)
keyBindings.bind(['shift+pageup', 'shift+pagedown'], this._handleKeySelectionPage)
keyBindings.bind(['mod+home', 'home', 'mod+end', 'end'], this._handleKeyNavigationHomeEnd)
keyBindings.bind(['mod+shift+home', 'shift+home', 'mod+shift+end', 'shift+end'], this._handleKeySelectionHomeEnd)
keyBindings.bind(['mod+left', 'mod+right'], this._handleKeyNavigationWord)
keyBindings.bind(['shift+mod+left', 'shift+mod+right'], this._handleKeySelectionWord)
keyBindings.bind('mod+a', this._handleKeySelectionAll)
keyBindings.bind('backspace', this._handleKeyBackspace)
keyBindings.bind('del', this._handleKeyDelete)
keyBindings.bind('mod+backspace', this._handleKeyWordBackspace)
keyBindings.bind('mod+del', this._handleKeyWordDelete)
//keyBindings.bind('mod+s', this._handleKeySave)
//keyBindings.bind('tab', this._handleKeyTab)
//keyBindings.bind('mod+z', this._handleUndo)
//keyBindings.bind('mod+y', this._handleRedo)
keyBindings.bind('mod+b', this._handleKeyBold)
keyBindings.bind('mod+i', this._handleKeyItalics)
keyBindings.bind('mod+u', this._handleKeyUnderline)
keyBindings.bind('alt+shift+5', this._handleKeyStrikethrough)
keyBindings.bind('mod+.', this._handleKeySuperscript)
keyBindings.bind('mod+,', this._handleKeySubscript)
if(this.props.focused) {
this._focus()
}
}
|
A React component to obtain TextInput from the user and insert it into the editor. We capture shortcuts
via Mousetrap.js bindings. All other characters bypass Mousetrap and are inserted by the browser into the
focused hidden text input area (so the browser's internal machinery deals with the key capture and translation
to characters, so it should work for complex IME input as well), and from there the browser triggers the
onInput event on the input area, at which point we grab the character and place it into the editor.
|
componentDidMount
|
javascript
|
ritzyed/ritzy
|
src/components/TextInput.js
|
https://github.com/ritzyed/ritzy/blob/master/src/components/TextInput.js
|
Apache-2.0
|
shouldComponentUpdate(nextProps) {
if(!nextProps.renderOptimizations) {
return true
}
return this.props.focused !== nextProps.focused
|| this.props.coordinates.x !== nextProps.coordinates.x
|| this.props.coordinates.y !== nextProps.coordinates.y
}
|
A React component to obtain TextInput from the user and insert it into the editor. We capture shortcuts
via Mousetrap.js bindings. All other characters bypass Mousetrap and are inserted by the browser into the
focused hidden text input area (so the browser's internal machinery deals with the key capture and translation
to characters, so it should work for complex IME input as well), and from there the browser triggers the
onInput event on the input area, at which point we grab the character and place it into the editor.
|
shouldComponentUpdate
|
javascript
|
ritzyed/ritzy
|
src/components/TextInput.js
|
https://github.com/ritzyed/ritzy/blob/master/src/components/TextInput.js
|
Apache-2.0
|
componentDidUpdate() {
if(this.props.focused) {
this._focus()
}
}
|
A React component to obtain TextInput from the user and insert it into the editor. We capture shortcuts
via Mousetrap.js bindings. All other characters bypass Mousetrap and are inserted by the browser into the
focused hidden text input area (so the browser's internal machinery deals with the key capture and translation
to characters, so it should work for complex IME input as well), and from there the browser triggers the
onInput event on the input area, at which point we grab the character and place it into the editor.
|
componentDidUpdate
|
javascript
|
ritzyed/ritzy
|
src/components/TextInput.js
|
https://github.com/ritzyed/ritzy/blob/master/src/components/TextInput.js
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.