230500
This commit is contained in:
@@ -0,0 +1,373 @@
|
||||
/*
|
||||
* [hi-base64]{@link https://github.com/emn178/hi-base64}
|
||||
*
|
||||
* @version 0.2.1
|
||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||
* @copyright Chen, Yi-Cyuan 2014-2017
|
||||
* @license MIT
|
||||
*/
|
||||
/*jslint bitwise: true */
|
||||
/*Modified by Pagelayer*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var root = typeof window === 'object' ? window : {};
|
||||
var NODE_JS = false;
|
||||
if (NODE_JS) {
|
||||
root = global;
|
||||
}
|
||||
var COMMON_JS = !root.HI_BASE64_NO_COMMON_JS && typeof module === 'object' && module.exports;
|
||||
var AMD = typeof define === 'function' && define.amd;
|
||||
var BASE64_ENCODE_CHAR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
|
||||
var BASE64_DECODE_CHAR = {
|
||||
'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4, 'F': 5, 'G': 6, 'H': 7, 'I': 8,
|
||||
'J': 9, 'K': 10, 'L': 11, 'M': 12, 'N': 13, 'O': 14, 'P': 15, 'Q': 16,
|
||||
'R': 17, 'S': 18, 'T': 19, 'U': 20, 'V': 21, 'W': 22, 'X': 23, 'Y': 24,
|
||||
'Z': 25, 'a': 26, 'b': 27, 'c': 28, 'd': 29, 'e': 30, 'f': 31, 'g': 32,
|
||||
'h': 33, 'i': 34, 'j': 35, 'k': 36, 'l': 37, 'm': 38, 'n': 39, 'o': 40,
|
||||
'p': 41, 'q': 42, 'r': 43, 's': 44, 't': 45, 'u': 46, 'v': 47, 'w': 48,
|
||||
'x': 49, 'y': 50, 'z': 51, '0': 52, '1': 53, '2': 54, '3': 55, '4': 56,
|
||||
'5': 57, '6': 58, '7': 59, '8': 60, '9': 61, '+': 62, '/': 63, '-': 62,
|
||||
'_': 63
|
||||
};
|
||||
|
||||
var utf8ToBytes = function (str) {
|
||||
var bytes = [];
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
var c = str.charCodeAt(i);
|
||||
if (c < 0x80) {
|
||||
bytes[bytes.length] = c;
|
||||
} else if (c < 0x800) {
|
||||
bytes[bytes.length] = 0xc0 | (c >> 6);
|
||||
bytes[bytes.length] = 0x80 | (c & 0x3f);
|
||||
} else if (c < 0xd800 || c >= 0xe000) {
|
||||
bytes[bytes.length] = 0xe0 | (c >> 12);
|
||||
bytes[bytes.length] = 0x80 | ((c >> 6) & 0x3f);
|
||||
bytes[bytes.length] = 0x80 | (c & 0x3f);
|
||||
} else {
|
||||
c = 0x10000 + (((c & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff));
|
||||
bytes[bytes.length] = 0xf0 | (c >> 18);
|
||||
bytes[bytes.length] = 0x80 | ((c >> 12) & 0x3f);
|
||||
bytes[bytes.length] = 0x80 | ((c >> 6) & 0x3f);
|
||||
bytes[bytes.length] = 0x80 | (c & 0x3f);
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
};
|
||||
|
||||
var decodeAsBytes = function (base64Str) {
|
||||
var v1, v2, v3, v4, bytes = [], index = 0, length = base64Str.length;
|
||||
if (base64Str.charAt(length - 2) === '=') {
|
||||
length -= 2;
|
||||
} else if (base64Str.charAt(length - 1) === '=') {
|
||||
length -= 1;
|
||||
}
|
||||
|
||||
// 4 char to 3 bytes
|
||||
for (var i = 0, count = length >> 2 << 2; i < count;) {
|
||||
v1 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
v2 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
v3 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
v4 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
bytes[index++] = (v1 << 2 | v2 >>> 4) & 255;
|
||||
bytes[index++] = (v2 << 4 | v3 >>> 2) & 255;
|
||||
bytes[index++] = (v3 << 6 | v4) & 255;
|
||||
}
|
||||
|
||||
// remain bytes
|
||||
var remain = length - count;
|
||||
if (remain === 2) {
|
||||
v1 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
v2 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
bytes[index++] = (v1 << 2 | v2 >>> 4) & 255;
|
||||
} else if (remain === 3) {
|
||||
v1 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
v2 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
v3 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
bytes[index++] = (v1 << 2 | v2 >>> 4) & 255;
|
||||
bytes[index++] = (v2 << 4 | v3 >>> 2) & 255;
|
||||
}
|
||||
return bytes;
|
||||
};
|
||||
|
||||
var encodeFromBytes = function (bytes) {
|
||||
var v1, v2, v3, base64Str = '', length = bytes.length;
|
||||
for (var i = 0, count = parseInt(length / 3) * 3; i < count;) {
|
||||
v1 = bytes[i++];
|
||||
v2 = bytes[i++];
|
||||
v3 = bytes[i++];
|
||||
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
|
||||
BASE64_ENCODE_CHAR[(v1 << 4 | v2 >>> 4) & 63] +
|
||||
BASE64_ENCODE_CHAR[(v2 << 2 | v3 >>> 6) & 63] +
|
||||
BASE64_ENCODE_CHAR[v3 & 63];
|
||||
}
|
||||
|
||||
// remain char
|
||||
var remain = length - count;
|
||||
if (remain === 1) {
|
||||
v1 = bytes[i];
|
||||
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
|
||||
BASE64_ENCODE_CHAR[(v1 << 4) & 63] +
|
||||
'==';
|
||||
} else if (remain === 2) {
|
||||
v1 = bytes[i++];
|
||||
v2 = bytes[i];
|
||||
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
|
||||
BASE64_ENCODE_CHAR[(v1 << 4 | v2 >>> 4) & 63] +
|
||||
BASE64_ENCODE_CHAR[(v2 << 2) & 63] +
|
||||
'=';
|
||||
}
|
||||
return base64Str;
|
||||
};
|
||||
|
||||
var btoa = root.btoa, atob = root.atob, utf8Base64Encode, utf8Base64Decode;
|
||||
if (NODE_JS) {
|
||||
} else if (!btoa) {
|
||||
btoa = function (str) {
|
||||
var v1, v2, v3, base64Str = '', length = str.length;
|
||||
for (var i = 0, count = parseInt(length / 3) * 3; i < count;) {
|
||||
v1 = str.charCodeAt(i++);
|
||||
v2 = str.charCodeAt(i++);
|
||||
v3 = str.charCodeAt(i++);
|
||||
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
|
||||
BASE64_ENCODE_CHAR[(v1 << 4 | v2 >>> 4) & 63] +
|
||||
BASE64_ENCODE_CHAR[(v2 << 2 | v3 >>> 6) & 63] +
|
||||
BASE64_ENCODE_CHAR[v3 & 63];
|
||||
}
|
||||
|
||||
// remain char
|
||||
var remain = length - count;
|
||||
if (remain === 1) {
|
||||
v1 = str.charCodeAt(i);
|
||||
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
|
||||
BASE64_ENCODE_CHAR[(v1 << 4) & 63] +
|
||||
'==';
|
||||
} else if (remain === 2) {
|
||||
v1 = str.charCodeAt(i++);
|
||||
v2 = str.charCodeAt(i);
|
||||
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
|
||||
BASE64_ENCODE_CHAR[(v1 << 4 | v2 >>> 4) & 63] +
|
||||
BASE64_ENCODE_CHAR[(v2 << 2) & 63] +
|
||||
'=';
|
||||
}
|
||||
return base64Str;
|
||||
};
|
||||
|
||||
utf8Base64Encode = function (str) {
|
||||
var v1, v2, v3, base64Str = '', bytes = utf8ToBytes(str), length = bytes.length;
|
||||
for (var i = 0, count = parseInt(length / 3) * 3; i < count;) {
|
||||
v1 = bytes[i++];
|
||||
v2 = bytes[i++];
|
||||
v3 = bytes[i++];
|
||||
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
|
||||
BASE64_ENCODE_CHAR[(v1 << 4 | v2 >>> 4) & 63] +
|
||||
BASE64_ENCODE_CHAR[(v2 << 2 | v3 >>> 6) & 63] +
|
||||
BASE64_ENCODE_CHAR[v3 & 63];
|
||||
}
|
||||
|
||||
// remain char
|
||||
var remain = length - count;
|
||||
if (remain === 1) {
|
||||
v1 = bytes[i];
|
||||
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
|
||||
BASE64_ENCODE_CHAR[(v1 << 4) & 63] +
|
||||
'==';
|
||||
} else if (remain === 2) {
|
||||
v1 = bytes[i++];
|
||||
v2 = bytes[i];
|
||||
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
|
||||
BASE64_ENCODE_CHAR[(v1 << 4 | v2 >>> 4) & 63] +
|
||||
BASE64_ENCODE_CHAR[(v2 << 2) & 63] +
|
||||
'=';
|
||||
}
|
||||
return base64Str;
|
||||
};
|
||||
|
||||
atob = function (base64Str) {
|
||||
var v1, v2, v3, v4, str = '', length = base64Str.length;
|
||||
if (base64Str.charAt(length - 2) === '=') {
|
||||
length -= 2;
|
||||
} else if (base64Str.charAt(length - 1) === '=') {
|
||||
length -= 1;
|
||||
}
|
||||
|
||||
// 4 char to 3 bytes
|
||||
for (var i = 0, count = length >> 2 << 2; i < count;) {
|
||||
v1 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
v2 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
v3 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
v4 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
str += String.fromCharCode((v1 << 2 | v2 >>> 4) & 255) +
|
||||
String.fromCharCode((v2 << 4 | v3 >>> 2) & 255) +
|
||||
String.fromCharCode((v3 << 6 | v4) & 255);
|
||||
}
|
||||
|
||||
// remain bytes
|
||||
var remain = length - count;
|
||||
if (remain === 2) {
|
||||
v1 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
v2 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
str += String.fromCharCode((v1 << 2 | v2 >>> 4) & 255);
|
||||
} else if (remain === 3) {
|
||||
v1 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
v2 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
v3 = BASE64_DECODE_CHAR[base64Str.charAt(i++)];
|
||||
str += String.fromCharCode((v1 << 2 | v2 >>> 4) & 255) +
|
||||
String.fromCharCode((v2 << 4 | v3 >>> 2) & 255);
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
utf8Base64Decode = function (base64Str) {
|
||||
var str = '', bytes = decodeAsBytes(base64Str), length = bytes.length;
|
||||
var i = 0, followingChars = 0, b, c;
|
||||
while (i < length) {
|
||||
b = bytes[i++];
|
||||
if (b <= 0x7F) {
|
||||
str += String.fromCharCode(b);
|
||||
continue;
|
||||
} else if (b > 0xBF && b <= 0xDF) {
|
||||
c = b & 0x1F;
|
||||
followingChars = 1;
|
||||
} else if (b <= 0xEF) {
|
||||
c = b & 0x0F;
|
||||
followingChars = 2;
|
||||
} else if (b <= 0xF7) {
|
||||
c = b & 0x07;
|
||||
followingChars = 3;
|
||||
} else {
|
||||
throw 'not a UTF-8 string';
|
||||
}
|
||||
|
||||
for (var j = 0; j < followingChars; ++j) {
|
||||
b = bytes[i++];
|
||||
if (b < 0x80 || b > 0xBF) {
|
||||
throw 'not a UTF-8 string';
|
||||
}
|
||||
c <<= 6;
|
||||
c += b & 0x3F;
|
||||
}
|
||||
if (c >= 0xD800 && c <= 0xDFFF) {
|
||||
throw 'not a UTF-8 string';
|
||||
}
|
||||
if (c > 0x10FFFF) {
|
||||
throw 'not a UTF-8 string';
|
||||
}
|
||||
|
||||
if (c <= 0xFFFF) {
|
||||
str += String.fromCharCode(c);
|
||||
} else {
|
||||
c -= 0x10000;
|
||||
str += String.fromCharCode((c >> 10) + 0xD800);
|
||||
str += String.fromCharCode((c & 0x3FF) + 0xDC00);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
};
|
||||
} else {
|
||||
utf8Base64Encode = function (str) {
|
||||
var result = '';
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
var charcode = str.charCodeAt(i);
|
||||
if (charcode < 0x80) {
|
||||
result += String.fromCharCode(charcode);
|
||||
} else if (charcode < 0x800) {
|
||||
result += String.fromCharCode(0xc0 | (charcode >> 6)) +
|
||||
String.fromCharCode(0x80 | (charcode & 0x3f));
|
||||
} else if (charcode < 0xd800 || charcode >= 0xe000) {
|
||||
result += String.fromCharCode(0xe0 | (charcode >> 12)) +
|
||||
String.fromCharCode(0x80 | ((charcode >> 6) & 0x3f)) +
|
||||
String.fromCharCode(0x80 | (charcode & 0x3f));
|
||||
} else {
|
||||
charcode = 0x10000 + (((charcode & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff));
|
||||
result += String.fromCharCode(0xf0 | (charcode >> 18)) +
|
||||
String.fromCharCode(0x80 | ((charcode >> 12) & 0x3f)) +
|
||||
String.fromCharCode(0x80 | ((charcode >> 6) & 0x3f)) +
|
||||
String.fromCharCode(0x80 | (charcode & 0x3f));
|
||||
}
|
||||
}
|
||||
return btoa(result);
|
||||
};
|
||||
|
||||
utf8Base64Decode = function (base64Str) {
|
||||
var tmpStr = atob(base64Str.trim('=').replace(/-/g, '+').replace(/_/g, '/'));
|
||||
if (!/[^\x00-\x7F]/.test(tmpStr)) {
|
||||
return tmpStr;
|
||||
}
|
||||
var str = '', i = 0, length = tmpStr.length, followingChars = 0, b, c;
|
||||
while (i < length) {
|
||||
b = tmpStr.charCodeAt(i++);
|
||||
if (b <= 0x7F) {
|
||||
str += String.fromCharCode(b);
|
||||
continue;
|
||||
} else if (b > 0xBF && b <= 0xDF) {
|
||||
c = b & 0x1F;
|
||||
followingChars = 1;
|
||||
} else if (b <= 0xEF) {
|
||||
c = b & 0x0F;
|
||||
followingChars = 2;
|
||||
} else if (b <= 0xF7) {
|
||||
c = b & 0x07;
|
||||
followingChars = 3;
|
||||
} else {
|
||||
throw 'not a UTF-8 string';
|
||||
}
|
||||
|
||||
for (var j = 0; j < followingChars; ++j) {
|
||||
b = tmpStr.charCodeAt(i++);
|
||||
if (b < 0x80 || b > 0xBF) {
|
||||
throw 'not a UTF-8 string';
|
||||
}
|
||||
c <<= 6;
|
||||
c += b & 0x3F;
|
||||
}
|
||||
if (c >= 0xD800 && c <= 0xDFFF) {
|
||||
throw 'not a UTF-8 string';
|
||||
}
|
||||
if (c > 0x10FFFF) {
|
||||
throw 'not a UTF-8 string';
|
||||
}
|
||||
|
||||
if (c <= 0xFFFF) {
|
||||
str += String.fromCharCode(c);
|
||||
} else {
|
||||
c -= 0x10000;
|
||||
str += String.fromCharCode((c >> 10) + 0xD800);
|
||||
str += String.fromCharCode((c & 0x3FF) + 0xDC00);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
};
|
||||
}
|
||||
|
||||
var encode = function (str, asciiOnly) {
|
||||
var notString = typeof(str) != 'string';
|
||||
if (notString && str.constructor === root.ArrayBuffer) {
|
||||
str = new Uint8Array(str);
|
||||
}
|
||||
if (notString) {
|
||||
return encodeFromBytes(str);
|
||||
} else {
|
||||
if (!asciiOnly && /[^\x00-\x7F]/.test(str)) {
|
||||
return utf8Base64Encode(str);
|
||||
} else {
|
||||
return btoa(str);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var decode = function (base64Str, asciiOnly) {
|
||||
return asciiOnly ? atob(base64Str) : utf8Base64Decode(base64Str);
|
||||
};
|
||||
|
||||
var exports = {
|
||||
encode: encode,
|
||||
decode: decode,
|
||||
atob: atob,
|
||||
btoa: btoa
|
||||
};
|
||||
decode.bytes = decodeAsBytes;
|
||||
decode.string = decode;
|
||||
|
||||
root.pagelayer_Base64 = exports;
|
||||
})();
|
||||
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* [hi-base64]{@link https://github.com/emn178/hi-base64}
|
||||
*
|
||||
* @version 0.2.1
|
||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||
* @copyright Chen, Yi-Cyuan 2014-2017
|
||||
* @license MIT
|
||||
*/
|
||||
/*jslint bitwise: true */
|
||||
/*Modified by Pagelayer*/
|
||||
!function(){"use strict";var r="object"==typeof window?window:{};!r.HI_BASE64_NO_COMMON_JS&&"object"==typeof module&&module.exports,"function"==typeof define&&define.amd;var t,o,e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),n={A:0,B:1,C:2,D:3,E:4,F:5,G:6,H:7,I:8,J:9,K:10,L:11,M:12,N:13,O:14,P:15,Q:16,R:17,S:18,T:19,U:20,V:21,W:22,X:23,Y:24,Z:25,a:26,b:27,c:28,d:29,e:30,f:31,g:32,h:33,i:34,j:35,k:36,l:37,m:38,n:39,o:40,p:41,q:42,r:43,s:44,t:45,u:46,v:47,w:48,x:49,y:50,z:51,0:52,1:53,2:54,3:55,4:56,5:57,6:58,7:59,8:60,9:61,"+":62,"/":63,"-":62,_:63},a=function(r){var t,o,e,a,h=[],f=0,i=r.length;"="===r.charAt(i-2)?i-=2:"="===r.charAt(i-1)&&(i-=1);for(var C=0,c=i>>2<<2;C<c;)t=n[r.charAt(C++)],o=n[r.charAt(C++)],e=n[r.charAt(C++)],a=n[r.charAt(C++)],h[f++]=255&(t<<2|o>>>4),h[f++]=255&(o<<4|e>>>2),h[f++]=255&(e<<6|a);var g=i-c;return 2===g?(t=n[r.charAt(C++)],o=n[r.charAt(C++)],h[f++]=255&(t<<2|o>>>4)):3===g&&(t=n[r.charAt(C++)],o=n[r.charAt(C++)],e=n[r.charAt(C++)],h[f++]=255&(t<<2|o>>>4),h[f++]=255&(o<<4|e>>>2)),h},h=r.btoa,f=r.atob;h?(t=function(r){for(var t="",o=0;o<r.length;o++){var e=r.charCodeAt(o);e<128?t+=String.fromCharCode(e):e<2048?t+=String.fromCharCode(192|e>>6)+String.fromCharCode(128|63&e):e<55296||e>=57344?t+=String.fromCharCode(224|e>>12)+String.fromCharCode(128|e>>6&63)+String.fromCharCode(128|63&e):(e=65536+((1023&e)<<10|1023&r.charCodeAt(++o)),t+=String.fromCharCode(240|e>>18)+String.fromCharCode(128|e>>12&63)+String.fromCharCode(128|e>>6&63)+String.fromCharCode(128|63&e))}return h(t)},o=function(r){var t=f(r.trim("=").replace(/-/g,"+").replace(/_/g,"/"));if(!/[^\x00-\x7F]/.test(t))return t;for(var o,e,n="",a=0,h=t.length,i=0;a<h;)if((o=t.charCodeAt(a++))<=127)n+=String.fromCharCode(o);else{if(o>191&&o<=223)e=31&o,i=1;else if(o<=239)e=15&o,i=2;else{if(!(o<=247))throw"not a UTF-8 string";e=7&o,i=3}for(var C=0;C<i;++C){if((o=t.charCodeAt(a++))<128||o>191)throw"not a UTF-8 string";e<<=6,e+=63&o}if(e>=55296&&e<=57343)throw"not a UTF-8 string";if(e>1114111)throw"not a UTF-8 string";e<=65535?n+=String.fromCharCode(e):(e-=65536,n+=String.fromCharCode(55296+(e>>10)),n+=String.fromCharCode(56320+(1023&e)))}return n}):(h=function(r){for(var t,o,n,a="",h=r.length,f=0,i=3*parseInt(h/3);f<i;)t=r.charCodeAt(f++),o=r.charCodeAt(f++),n=r.charCodeAt(f++),a+=e[t>>>2]+e[63&(t<<4|o>>>4)]+e[63&(o<<2|n>>>6)]+e[63&n];var C=h-i;return 1===C?(t=r.charCodeAt(f),a+=e[t>>>2]+e[t<<4&63]+"=="):2===C&&(t=r.charCodeAt(f++),o=r.charCodeAt(f),a+=e[t>>>2]+e[63&(t<<4|o>>>4)]+e[o<<2&63]+"="),a},t=function(r){for(var t,o,n,a="",h=function(r){for(var t=[],o=0;o<r.length;o++){var e=r.charCodeAt(o);e<128?t[t.length]=e:e<2048?(t[t.length]=192|e>>6,t[t.length]=128|63&e):e<55296||e>=57344?(t[t.length]=224|e>>12,t[t.length]=128|e>>6&63,t[t.length]=128|63&e):(e=65536+((1023&e)<<10|1023&r.charCodeAt(++o)),t[t.length]=240|e>>18,t[t.length]=128|e>>12&63,t[t.length]=128|e>>6&63,t[t.length]=128|63&e)}return t}(r),f=h.length,i=0,C=3*parseInt(f/3);i<C;)t=h[i++],o=h[i++],n=h[i++],a+=e[t>>>2]+e[63&(t<<4|o>>>4)]+e[63&(o<<2|n>>>6)]+e[63&n];var c=f-C;return 1===c?(t=h[i],a+=e[t>>>2]+e[t<<4&63]+"=="):2===c&&(t=h[i++],o=h[i],a+=e[t>>>2]+e[63&(t<<4|o>>>4)]+e[o<<2&63]+"="),a},f=function(r){var t,o,e,a,h="",f=r.length;"="===r.charAt(f-2)?f-=2:"="===r.charAt(f-1)&&(f-=1);for(var i=0,C=f>>2<<2;i<C;)t=n[r.charAt(i++)],o=n[r.charAt(i++)],e=n[r.charAt(i++)],a=n[r.charAt(i++)],h+=String.fromCharCode(255&(t<<2|o>>>4))+String.fromCharCode(255&(o<<4|e>>>2))+String.fromCharCode(255&(e<<6|a));var c=f-C;return 2===c?(t=n[r.charAt(i++)],o=n[r.charAt(i++)],h+=String.fromCharCode(255&(t<<2|o>>>4))):3===c&&(t=n[r.charAt(i++)],o=n[r.charAt(i++)],e=n[r.charAt(i++)],h+=String.fromCharCode(255&(t<<2|o>>>4))+String.fromCharCode(255&(o<<4|e>>>2))),h},o=function(r){for(var t,o,e="",n=a(r),h=n.length,f=0,i=0;f<h;)if((t=n[f++])<=127)e+=String.fromCharCode(t);else{if(t>191&&t<=223)o=31&t,i=1;else if(t<=239)o=15&t,i=2;else{if(!(t<=247))throw"not a UTF-8 string";o=7&t,i=3}for(var C=0;C<i;++C){if((t=n[f++])<128||t>191)throw"not a UTF-8 string";o<<=6,o+=63&t}if(o>=55296&&o<=57343)throw"not a UTF-8 string";if(o>1114111)throw"not a UTF-8 string";o<=65535?e+=String.fromCharCode(o):(o-=65536,e+=String.fromCharCode(55296+(o>>10)),e+=String.fromCharCode(56320+(1023&o)))}return e});var i=function(r,t){return t?f(r):o(r)},C={encode:function(o,n){var a="string"!=typeof o;return a&&o.constructor===r.ArrayBuffer&&(o=new Uint8Array(o)),a?function(r){for(var t,o,n,a="",h=r.length,f=0,i=3*parseInt(h/3);f<i;)t=r[f++],o=r[f++],n=r[f++],a+=e[t>>>2]+e[63&(t<<4|o>>>4)]+e[63&(o<<2|n>>>6)]+e[63&n];var C=h-i;return 1===C?(t=r[f],a+=e[t>>>2]+e[t<<4&63]+"=="):2===C&&(t=r[f++],o=r[f],a+=e[t>>>2]+e[63&(t<<4|o>>>4)]+e[o<<2&63]+"="),a}(o):!n&&/[^\x00-\x7F]/.test(o)?t(o):h(o)},decode:i,atob:f,btoa:h};i.bytes=a,i.string=i,r.pagelayer_Base64=C}();
|
||||
@@ -0,0 +1 @@
|
||||
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '0d1f000656bdb8897914');
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
//===========================================================
|
||||
// givejs.php
|
||||
//===========================================================
|
||||
// PAGELAYER
|
||||
// Inspired by the DESIRE to be the BEST OF ALL
|
||||
// ----------------------------------------------------------
|
||||
// Started by: Pulkit Gupta
|
||||
// Date: 23rd Jan 2017
|
||||
// Time: 23:00 hrs
|
||||
// Site: http://pagelayer.com/wordpress (PAGELAYER)
|
||||
// ----------------------------------------------------------
|
||||
// Please Read the Terms of use at http://pagelayer.com/tos
|
||||
// ----------------------------------------------------------
|
||||
//===========================================================
|
||||
// (c)Pagelayer Team
|
||||
//===========================================================
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
if(!empty($_REQUEST['test'])){
|
||||
echo 1;
|
||||
die();
|
||||
}
|
||||
|
||||
// Read the file
|
||||
$data = '';
|
||||
$data_premium = '';
|
||||
$self_path = dirname(__FILE__);
|
||||
$files = array(
|
||||
// Admin JS
|
||||
'pagelayer-editor.js',
|
||||
'widgets.js',
|
||||
'premium.js',
|
||||
'properties.js',
|
||||
'base-64.min.js',
|
||||
'slimscroll.js',
|
||||
'vanilla-picker.min.js',
|
||||
'tlite.min.js',
|
||||
'pagelayer-pen.js',
|
||||
// Enduser JS
|
||||
'imagesloaded.min.js',
|
||||
'nivo-lightbox.min.js',
|
||||
'owl.carousel.min.js',
|
||||
'pagelayer-frontend.js',
|
||||
'premium-frontend.js',
|
||||
'wow.min.js',
|
||||
'jquery-numerator.js',
|
||||
'simpleParallax.min.js',
|
||||
'chart.min.js',
|
||||
'shuffle.min.js'
|
||||
);
|
||||
|
||||
// What files to give
|
||||
$give = @$_REQUEST['give'];
|
||||
|
||||
// Premium
|
||||
$premium = @$_REQUEST['premium'];
|
||||
|
||||
if(!empty($give)){
|
||||
|
||||
$give = explode(',', $give);
|
||||
|
||||
// Check all files are in the supported list
|
||||
foreach($give as $file){
|
||||
if(in_array($file, $files)){
|
||||
$final[md5($file)] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!empty($premium)){
|
||||
|
||||
$premium = explode(',', trim($premium, ','));
|
||||
|
||||
// Check all files are in the supported list
|
||||
foreach($premium as $file){
|
||||
if(in_array($file, $files)){
|
||||
$final_premium[md5($file)] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Give all
|
||||
if(empty($final)){
|
||||
$final = $files;
|
||||
}
|
||||
|
||||
foreach($final as $k => $v){
|
||||
//echo $k.'<br>';
|
||||
$data .= file_get_contents($self_path.'/'.$v)."\n\n";
|
||||
}
|
||||
|
||||
if(!empty($final_premium)){
|
||||
|
||||
foreach($final_premium as $k => $v){
|
||||
//echo $k.'<br>';
|
||||
$data_premium .= file_get_contents($self_path.'/'.$v)."\n\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// We are zipping if possible
|
||||
if(function_exists('ob_gzhandler') && !ini_get('zlib.output_compression')){
|
||||
ob_start('ob_gzhandler');
|
||||
}
|
||||
|
||||
// Type javascript
|
||||
header("Content-type: text/javascript; charset: UTF-8");
|
||||
|
||||
// Set a zero Mtime
|
||||
$filetime = filemtime($self_path.'/pagelayer-editor.js');
|
||||
|
||||
// Are we to also serve Shortcodes ?
|
||||
if(!empty($pagelayer->shortcodes)){
|
||||
$data .= 'pagelayer_shortcodes = '.json_encode($pagelayer->shortcodes).';'."\n\n";
|
||||
$data .= 'pagelayer_styles = '.json_encode($pagelayer->styles).';'."\n\n";
|
||||
$data .= 'pagelayer_groups = '.json_encode($pagelayer->groups).';'."\n\n";
|
||||
}
|
||||
|
||||
// Add the langs as well
|
||||
preg_match_all('/pagelayer_l\([\'"](\w*)[\'"]\)/is', $data, $matches);
|
||||
if(!empty($matches[1]) && function_exists('__pl')){
|
||||
foreach($matches[1] as $lk => $lv){
|
||||
$export_langs[$lv] = __pl($lv);
|
||||
}
|
||||
}
|
||||
|
||||
// Also add the fonts
|
||||
if(!empty($pagelayer->fonts)){
|
||||
$export_langs['pl_fonts_list'] = $pagelayer->fonts;
|
||||
}
|
||||
|
||||
// And lang string ?
|
||||
if(!empty($export_langs)){
|
||||
$data .= 'pagelayer_lang = '.json_encode($export_langs).';'."\n\n";
|
||||
}
|
||||
|
||||
// Cache Control
|
||||
header("Cache-Control: must-revalidate");
|
||||
|
||||
// Checking if the client is validating his cache and if it is current.
|
||||
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $filetime)) {
|
||||
|
||||
// Client's cache IS current, so we just respond '304 Not Modified'.
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $filetime).' GMT', true, 304);
|
||||
|
||||
return;
|
||||
|
||||
}else{
|
||||
|
||||
// Image not cached or cache outdated, we respond '200 OK' and output the image.
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $filetime).' GMT', true, 200);
|
||||
|
||||
}
|
||||
|
||||
echo $data;
|
||||
echo $data_premium;
|
||||
|
||||
// Write if we are front-end only then
|
||||
$dev = dirname(dirname(__FILE__)).'/dev.php';
|
||||
if(!empty($_REQUEST['write']) && file_exists($dev)){
|
||||
include_once($dev);
|
||||
write_js();
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* jQuery Numerator Plugin 0.2.1
|
||||
* https://github.com/garethdn/jquery-numerator
|
||||
*
|
||||
* Copyright 2015, Gareth Nolan
|
||||
* http://ie.linkedin.com/in/garethnolan/
|
||||
|
||||
* Based on jQuery Boilerplate by Zeno Rocha with the help of Addy Osmani
|
||||
* http://jqueryboilerplate.com
|
||||
*
|
||||
* Licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
;(function (factory) {
|
||||
'use strict';
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD is used - Register as an anonymous module.
|
||||
define(['jquery'], factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
factory(require('jquery'));
|
||||
} else {
|
||||
// Neither AMD nor CommonJS used. Use global variables.
|
||||
if (typeof jQuery === 'undefined') {
|
||||
throw 'jquery-numerator requires jQuery to be loaded first';
|
||||
}
|
||||
factory(jQuery);
|
||||
}
|
||||
}(function ($) {
|
||||
|
||||
var pluginName = "numerator",
|
||||
defaults = {
|
||||
easing: 'swing',
|
||||
duration: 500,
|
||||
delimiter: undefined,
|
||||
rounding: 0,
|
||||
toValue: undefined,
|
||||
fromValue: undefined,
|
||||
queue: false,
|
||||
onStart: function(){},
|
||||
onStep: function(){},
|
||||
onProgress: function(){},
|
||||
onComplete: function(){}
|
||||
};
|
||||
|
||||
function Plugin ( element, options ) {
|
||||
this.element = element;
|
||||
this.settings = $.extend( {}, defaults, options );
|
||||
this._defaults = defaults;
|
||||
this._name = pluginName;
|
||||
this.init();
|
||||
}
|
||||
|
||||
Plugin.prototype = {
|
||||
|
||||
init: function () {
|
||||
this.parseElement();
|
||||
this.setValue();
|
||||
},
|
||||
|
||||
parseElement: function () {
|
||||
var elText = $.trim($(this.element).text());
|
||||
|
||||
this.settings.fromValue = this.settings.fromValue || this.format(elText);
|
||||
},
|
||||
|
||||
setValue: function() {
|
||||
var self = this;
|
||||
|
||||
$({value: self.settings.fromValue}).animate({value: self.settings.toValue}, {
|
||||
|
||||
duration: parseInt(self.settings.duration, 10),
|
||||
|
||||
easing: self.settings.easing,
|
||||
|
||||
start: self.settings.onStart,
|
||||
|
||||
step: function(now, fx) {
|
||||
$(self.element).text(self.format(now));
|
||||
// accepts two params - (now, fx)
|
||||
self.settings.onStep(now, fx);
|
||||
},
|
||||
|
||||
// accepts three params - (animation object, progress ratio, time remaining(ms))
|
||||
progress: self.settings.onProgress,
|
||||
|
||||
complete: self.settings.onComplete
|
||||
});
|
||||
},
|
||||
|
||||
format: function(value){
|
||||
var self = this;
|
||||
|
||||
if ( parseInt(this.settings.rounding ) < 1) {
|
||||
value = parseInt(value, 10);
|
||||
} else {
|
||||
value = parseFloat(value).toFixed( parseInt(this.settings.rounding) );
|
||||
}
|
||||
|
||||
if (self.settings.delimiter) {
|
||||
return this.delimit(value)
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
},
|
||||
|
||||
// TODO: Add comments to this function
|
||||
delimit: function(value){
|
||||
var self = this;
|
||||
|
||||
value = value.toString();
|
||||
|
||||
if (self.settings.rounding && parseInt(self.settings.rounding, 10) > 0) {
|
||||
var decimals = value.substring( (value.length - (self.settings.rounding + 1)), value.length ),
|
||||
wholeValue = value.substring( 0, (value.length - (self.settings.rounding + 1)));
|
||||
|
||||
return self.addDelimiter(wholeValue) + decimals;
|
||||
} else {
|
||||
return self.addDelimiter(value);
|
||||
}
|
||||
},
|
||||
|
||||
addDelimiter: function(value){
|
||||
return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, this.settings.delimiter);
|
||||
}
|
||||
};
|
||||
|
||||
$.fn[ pluginName ] = function ( options ) {
|
||||
return this.each(function() {
|
||||
if ( $.data( this, "plugin_" + pluginName ) ) {
|
||||
$.data(this, 'plugin_' + pluginName, null);
|
||||
}
|
||||
$.data( this, "plugin_" + pluginName, new Plugin( this, options ) );
|
||||
});
|
||||
};
|
||||
|
||||
}));
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,79 @@
|
||||
// Lets start
|
||||
jQuery(document).ready(function(){
|
||||
|
||||
var pl_admin_tabs = function(sel){
|
||||
jQuery('.nav-tab-wrapper a').click(function(){
|
||||
|
||||
var tEle = jQuery(this);
|
||||
|
||||
var sel = tEle.attr('tab-class') || 'pagelayer-tab-panel';
|
||||
|
||||
// Limit effect to the container element.
|
||||
var context = tEle.closest('.nav-tab-wrapper').parent().parent();
|
||||
context.find('.nav-tab-wrapper a').removeClass('nav-tab-active');
|
||||
tEle.addClass('nav-tab-active');
|
||||
context.find('.'+sel).hide();
|
||||
context.find(tEle.attr('href')).show();
|
||||
location.hash = tEle.attr('href')+'_tab';
|
||||
|
||||
return false;
|
||||
|
||||
});
|
||||
|
||||
// Make setting nav-tab-active optional.
|
||||
jQuery('.nav-tab-wrapper.pagelayer-wrapper').each(function(){
|
||||
|
||||
var jEle = jQuery(this);
|
||||
var hash = location.hash.slice(1, -4);
|
||||
|
||||
if(hash){
|
||||
var active_tab_ele = jEle.find('[href="#'+hash+'"]');
|
||||
if (active_tab_ele.length > 0){
|
||||
active_tab_ele.click();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var first = jEle.find('a').first();
|
||||
first.click();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
var pl_admin_accordion = function(){
|
||||
|
||||
jQuery('.pagelayer-acc-wrapper .pagelayer-acc-tab').click(function(){
|
||||
|
||||
var tEle = jQuery(this);
|
||||
|
||||
if(tEle.hasClass('nav-tab-active')){
|
||||
tEle.toggleClass('nav-tab-active').next('.pagelayer-acc-panel').toggle();
|
||||
}else{
|
||||
// Limit effect to the container element.
|
||||
var context = tEle.closest('.pagelayer-acc-wrapper ');
|
||||
context.find('.pagelayer-acc-tab').removeClass('nav-tab-active');
|
||||
context.find('.pagelayer-acc-panel').hide();
|
||||
tEle.addClass('nav-tab-active');
|
||||
tEle.next('.pagelayer-acc-panel').show();
|
||||
}
|
||||
});
|
||||
|
||||
// Make setting nav-tab-active optional.
|
||||
jQuery('.pagelayer-acc-wrapper').each(function(){
|
||||
|
||||
var jEle = jQuery(this);
|
||||
|
||||
var active_acc_ele = jEle.find('nav-tab-active');
|
||||
if (active_acc_ele.length > 0){
|
||||
active_acc_ele.click();
|
||||
}else{
|
||||
jEle.find('.pagelayer-acc-tab').first().click();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
pl_admin_tabs();
|
||||
pl_admin_accordion();
|
||||
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,869 @@
|
||||
/*! Licensed under MIT, https://github.com/sofish/pen */
|
||||
(function(root, doc) {
|
||||
|
||||
var Pen, debugMode, selection, utils = {};
|
||||
var toString = Object.prototype.toString;
|
||||
var slice = Array.prototype.slice;
|
||||
|
||||
// allow command list
|
||||
var commandsReg = {
|
||||
block: /^(?:p|h[1-6]|blockquote|pre)$/,
|
||||
inline: /^(?:bold|italic|underline|insertorderedlist|insertunorderedlist|indent|outdent)$/,
|
||||
source: /^(?:createlink|unlink)$/,
|
||||
insert: /^(?:inserthorizontalrule|insertimage|insert)$/,
|
||||
wrap: /^(?:code)$/
|
||||
};
|
||||
|
||||
var lineBreakReg = /^(?:blockquote|pre|div)$/i;
|
||||
|
||||
var effectNodeReg = /(?:[pubia]|h[1-6]|blockquote|[uo]l|li)/i;
|
||||
|
||||
var strReg = {
|
||||
whiteSpace: /(^\s+)|(\s+$)/g,
|
||||
mailTo: /^(?!mailto:|.+\/|.+#|.+\?)(.*@.*\..+)$/,
|
||||
http: /^(?!\w+?:\/\/|mailto:|\/|\.\/|\?|#)(.*)$/
|
||||
};
|
||||
|
||||
var autoLinkReg = {
|
||||
url: /((https?|ftp):\/\/|www\.)[^\s<]{3,}/gi,
|
||||
prefix: /^(?:https?|ftp):\/\//i,
|
||||
notLink: /^(?:img|a|input|audio|video|source|code|pre|script|head|title|style)$/i,
|
||||
maxLength: 100
|
||||
};
|
||||
|
||||
// type detect
|
||||
utils.is = function(obj, type) {
|
||||
return toString.call(obj).slice(8, -1) === type;
|
||||
};
|
||||
|
||||
utils.forEach = function(obj, iterator, arrayLike) {
|
||||
if (!obj) return;
|
||||
if (arrayLike == null) arrayLike = utils.is(obj, 'Array');
|
||||
if (arrayLike) {
|
||||
for (var i = 0, l = obj.length; i < l; i++) iterator(obj[i], i, obj);
|
||||
} else {
|
||||
for (var key in obj) {
|
||||
if (obj.hasOwnProperty(key)) iterator(obj[key], key, obj);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// copy props from a obj
|
||||
utils.copy = function(defaults, source) {
|
||||
utils.forEach(source, function (value, key) {
|
||||
defaults[key] = utils.is(value, 'Object') ? utils.copy({}, value) :
|
||||
utils.is(value, 'Array') ? utils.copy([], value) : value;
|
||||
});
|
||||
return defaults;
|
||||
};
|
||||
|
||||
// log
|
||||
utils.log = function(message, force) {
|
||||
if (debugMode || force)
|
||||
console.log('%cPEN DEBUGGER: %c' + message, 'font-family:arial,sans-serif;color:#1abf89;line-height:2em;', 'font-family:cursor,monospace;color:#333;');
|
||||
};
|
||||
|
||||
utils.delayExec = function (fn) {
|
||||
var timer = null;
|
||||
return function (delay) {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(function() {
|
||||
fn();
|
||||
}, delay || 1);
|
||||
};
|
||||
};
|
||||
|
||||
// merge: make it easy to have a fallback
|
||||
utils.merge = function(config) {
|
||||
|
||||
// default settings
|
||||
var defaults = {
|
||||
class: 'pen',
|
||||
debug: false,
|
||||
toolbar: null, // custom toolbar
|
||||
stay: config.stay || !config.debug,
|
||||
stayMsg: 'Are you going to leave here?',
|
||||
textarea: '<textarea name="content"></textarea>',
|
||||
list: [
|
||||
'blockquote', 'h2', 'h3', 'p', 'code', 'insertorderedlist', 'insertunorderedlist', 'inserthorizontalrule',
|
||||
'indent', 'outdent', 'bold', 'italic', 'underline', 'createlink', 'insertimage'
|
||||
],
|
||||
titles: {},
|
||||
cleanAttrs: ['id', 'class', 'style', 'name'],
|
||||
cleanTags: ['script'],
|
||||
linksInNewWindow: false
|
||||
};
|
||||
|
||||
// user-friendly config
|
||||
if (config.nodeType === 1) {
|
||||
defaults.editor = config;
|
||||
} else if (config.match && config.match(/^#[\S]+$/)) {
|
||||
defaults.editor = doc.getElementById(config.slice(1));
|
||||
} else {
|
||||
defaults = utils.copy(defaults, config);
|
||||
}
|
||||
|
||||
return defaults;
|
||||
};
|
||||
|
||||
function commandOverall(ctx, cmd, val) {
|
||||
var message = ' to exec 「' + cmd + '」 command' + (val ? (' with value: ' + val) : '');
|
||||
|
||||
try {
|
||||
doc.execCommand(cmd, false, val);
|
||||
} catch(err) {
|
||||
// TODO: there's an error when insert a image to document, but not a bug
|
||||
return utils.log('fail' + message, true);
|
||||
}
|
||||
|
||||
utils.log('success' + message);
|
||||
}
|
||||
|
||||
function commandInsert(ctx, name, val) {
|
||||
var node = getNode(ctx);
|
||||
if (!node) return;
|
||||
ctx._range.selectNode(node);
|
||||
ctx._range.collapse(false);
|
||||
|
||||
// hide menu when a image was inserted
|
||||
if(name === 'insertimage' && ctx._menu) toggleNode(ctx._menu, true);
|
||||
|
||||
return commandOverall(ctx, name, val);
|
||||
}
|
||||
|
||||
function commandBlock(ctx, name) {
|
||||
var list = effectNode(ctx, getNode(ctx), true);
|
||||
if (list.indexOf(name) !== -1) name = 'p';
|
||||
return commandOverall(ctx, 'formatblock', name);
|
||||
}
|
||||
|
||||
function commandWrap(ctx, tag, value) {
|
||||
value = '<' + tag + '>' + (value||selection.toString()) + '</' + tag + '>';
|
||||
return commandOverall(ctx, 'insertHTML', value);
|
||||
}
|
||||
|
||||
function commandLink(ctx, tag, value) {
|
||||
if (ctx.config.linksInNewWindow) {
|
||||
value = '< a href="' + value + '" target="_blank">' + (selection.toString()) + '</a>';
|
||||
return commandOverall(ctx, 'insertHTML', value);
|
||||
} else {
|
||||
return commandOverall(ctx, tag, value);
|
||||
}
|
||||
}
|
||||
|
||||
function initToolbar(ctx) {
|
||||
var icons = '', inputStr = '<input class="pen-input" placeholder="http://" />';
|
||||
|
||||
ctx._toolbar = ctx.config.toolbar;
|
||||
if (!ctx._toolbar) {
|
||||
var toolList = ctx.config.list;
|
||||
utils.forEach(toolList, function (name) {
|
||||
var klass = 'pen-icon icon-' + name;
|
||||
var title = ctx.config.titles[name] || '';
|
||||
icons += '<i class="' + klass + '" data-action="' + name + '" title="' + title + '"></i>';
|
||||
}, true);
|
||||
if (toolList.indexOf('createlink') >= 0 || toolList.indexOf('insertimage') >= 0)
|
||||
icons += inputStr;
|
||||
} else if (ctx._toolbar.querySelectorAll('[data-action=createlink]').length ||
|
||||
ctx._toolbar.querySelectorAll('[data-action=insertimage]').length) {
|
||||
icons += inputStr;
|
||||
}
|
||||
|
||||
if (icons) {
|
||||
ctx._menu = doc.createElement('div');
|
||||
ctx._menu.setAttribute('class', ctx.config.class + '-menu pen-menu');
|
||||
ctx._menu.innerHTML = icons;
|
||||
ctx._inputBar = ctx._menu.querySelector('input');
|
||||
toggleNode(ctx._menu, true);
|
||||
doc.body.appendChild(ctx._menu);
|
||||
}
|
||||
if (ctx._toolbar && ctx._inputBar) toggleNode(ctx._inputBar);
|
||||
}
|
||||
|
||||
function initEvents(ctx) {
|
||||
var toolbar = ctx._toolbar || ctx._menu, editor = ctx.config.editor;
|
||||
|
||||
var toggleMenu = utils.delayExec(function() {
|
||||
ctx.highlight().menu();
|
||||
});
|
||||
var outsideClick = function() {};
|
||||
|
||||
function updateStatus(delay) {
|
||||
ctx._range = ctx.getRange();
|
||||
toggleMenu(delay);
|
||||
}
|
||||
|
||||
if (ctx._menu) {
|
||||
var setpos = function() {
|
||||
if (ctx._menu.style.display === 'block') ctx.menu();
|
||||
};
|
||||
|
||||
// change menu offset when window resize / scroll
|
||||
addListener(ctx, root, 'resize', setpos);
|
||||
addListener(ctx, root, 'scroll', setpos);
|
||||
|
||||
// toggle toolbar on mouse select
|
||||
var selecting = false;
|
||||
addListener(ctx, editor, 'mousedown', function() {
|
||||
selecting = true;
|
||||
});
|
||||
addListener(ctx, editor, 'mouseleave', function() {
|
||||
if (selecting) updateStatus(800);
|
||||
selecting = false;
|
||||
});
|
||||
addListener(ctx, editor, 'mouseup', function() {
|
||||
if (selecting) updateStatus(100);
|
||||
selecting = false;
|
||||
});
|
||||
// Hide menu when focusing outside of editor
|
||||
outsideClick = function(e) {
|
||||
if (ctx._menu && !containsNode(editor, e.target) && !containsNode(ctx._menu, e.target)) {
|
||||
removeListener(ctx, doc, 'click', outsideClick);
|
||||
toggleMenu(100);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
addListener(ctx, editor, 'click', function() {
|
||||
updateStatus(0);
|
||||
});
|
||||
}
|
||||
|
||||
addListener(ctx, editor, 'keyup', function(e) {
|
||||
if (e.which === 8 && ctx.isEmpty()) return lineBreak(ctx, true);
|
||||
// toggle toolbar on key select
|
||||
if (e.which !== 13 || e.shiftKey) return updateStatus(400);
|
||||
var node = getNode(ctx, true);
|
||||
if (!node || !node.nextSibling || !lineBreakReg.test(node.nodeName)) return;
|
||||
if (node.nodeName !== node.nextSibling.nodeName) return;
|
||||
// hack for webkit, make 'enter' behavior like as firefox.
|
||||
if (node.lastChild.nodeName !== 'BR') node.appendChild(doc.createElement('br'));
|
||||
utils.forEach(node.nextSibling.childNodes, function(child) {
|
||||
if (child) node.appendChild(child);
|
||||
}, true);
|
||||
node.parentNode.removeChild(node.nextSibling);
|
||||
focusNode(ctx, node.lastChild, ctx.getRange());
|
||||
});
|
||||
|
||||
// check line break
|
||||
addListener(ctx, editor, 'keydown', function(e) {
|
||||
editor.classList.remove('pen-placeholder');
|
||||
if (e.which !== 13 || e.shiftKey) return;
|
||||
var node = getNode(ctx, true);
|
||||
if (!node || !lineBreakReg.test(node.nodeName)) return;
|
||||
var lastChild = node.lastChild;
|
||||
if (!lastChild || !lastChild.previousSibling) return;
|
||||
if (lastChild.previousSibling.textContent || lastChild.textContent) return;
|
||||
// quit block mode for 2 'enter'
|
||||
e.preventDefault();
|
||||
var p = doc.createElement('p');
|
||||
p.innerHTML = '<br>';
|
||||
node.removeChild(lastChild);
|
||||
if (!node.nextSibling) node.parentNode.appendChild(p);
|
||||
else node.parentNode.insertBefore(p, node.nextSibling);
|
||||
focusNode(ctx, p, ctx.getRange());
|
||||
});
|
||||
|
||||
var menuApply = function(action, value) {
|
||||
ctx.execCommand(action, value);
|
||||
ctx._range = ctx.getRange();
|
||||
ctx.highlight().menu();
|
||||
};
|
||||
|
||||
// toggle toolbar on key select
|
||||
addListener(ctx, toolbar, 'click', function(e) {
|
||||
var node = e.target, action;
|
||||
|
||||
while (node !== toolbar && !(action = node.getAttribute('data-action'))) {
|
||||
node = node.parentNode;
|
||||
}
|
||||
|
||||
if (!action) return;
|
||||
if (!/(?:createlink)|(?:insertimage)/.test(action)) return menuApply(action);
|
||||
if (!ctx._inputBar) return;
|
||||
|
||||
// create link
|
||||
var input = ctx._inputBar;
|
||||
if (toolbar === ctx._menu) toggleNode(input);
|
||||
else {
|
||||
ctx._inputActive = true;
|
||||
ctx.menu();
|
||||
}
|
||||
if (ctx._menu.style.display === 'none') return;
|
||||
|
||||
setTimeout(function() { input.focus(); }, 400);
|
||||
var createlink = function() {
|
||||
var inputValue = input.value;
|
||||
|
||||
if (!inputValue) action = 'unlink';
|
||||
else {
|
||||
inputValue = input.value
|
||||
.replace(strReg.whiteSpace, '')
|
||||
.replace(strReg.mailTo, 'mailto:$1')
|
||||
.replace(strReg.http, 'http://$1');
|
||||
}
|
||||
menuApply(action, inputValue);
|
||||
if (toolbar === ctx._menu) toggleNode(input, false);
|
||||
else toggleNode(ctx._menu, true);
|
||||
};
|
||||
|
||||
input.onkeypress = function(e) {
|
||||
if (e.which === 13) return createlink();
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
// listen for placeholder
|
||||
addListener(ctx, editor, 'focus', function() {
|
||||
if (ctx.isEmpty()) lineBreak(ctx, true);
|
||||
addListener(ctx, doc, 'click', outsideClick);
|
||||
});
|
||||
|
||||
addListener(ctx, editor, 'blur', function() {
|
||||
checkPlaceholder(ctx);
|
||||
ctx.checkContentChange();
|
||||
});
|
||||
|
||||
// listen for paste and clear style
|
||||
addListener(ctx, editor, 'paste', function() {
|
||||
setTimeout(function() {
|
||||
ctx.cleanContent();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function addListener(ctx, target, type, listener) {
|
||||
if (ctx._events.hasOwnProperty(type)) {
|
||||
ctx._events[type].push(listener);
|
||||
} else {
|
||||
ctx._eventTargets = ctx._eventTargets || [];
|
||||
ctx._eventsCache = ctx._eventsCache || [];
|
||||
var index = ctx._eventTargets.indexOf(target);
|
||||
if (index < 0) index = ctx._eventTargets.push(target) - 1;
|
||||
ctx._eventsCache[index] = ctx._eventsCache[index] || {};
|
||||
ctx._eventsCache[index][type] = ctx._eventsCache[index][type] || [];
|
||||
ctx._eventsCache[index][type].push(listener);
|
||||
|
||||
target.addEventListener(type, listener, false);
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
// trigger local events
|
||||
function triggerListener(ctx, type) {
|
||||
if (!ctx._events.hasOwnProperty(type)) return;
|
||||
var args = slice.call(arguments, 2);
|
||||
utils.forEach(ctx._events[type], function (listener) {
|
||||
listener.apply(ctx, args);
|
||||
});
|
||||
}
|
||||
|
||||
function removeListener(ctx, target, type, listener) {
|
||||
var events = ctx._events[type];
|
||||
if (!events) {
|
||||
var _index = ctx._eventTargets.indexOf(target);
|
||||
if (_index >= 0) events = ctx._eventsCache[_index][type];
|
||||
}
|
||||
if (!events) return ctx;
|
||||
var index = events.indexOf(listener);
|
||||
if (index >= 0) events.splice(index, 1);
|
||||
target.removeEventListener(type, listener, false);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
function removeAllListeners(ctx) {
|
||||
utils.forEach(this._events, function (events) {
|
||||
events.length = 0;
|
||||
}, false);
|
||||
if (!ctx._eventsCache) return ctx;
|
||||
utils.forEach(ctx._eventsCache, function (events, index) {
|
||||
var target = ctx._eventTargets[index];
|
||||
utils.forEach(events, function (listeners, type) {
|
||||
utils.forEach(listeners, function (listener) {
|
||||
target.removeEventListener(type, listener, false);
|
||||
}, true);
|
||||
}, false);
|
||||
}, true);
|
||||
ctx._eventTargets = [];
|
||||
ctx._eventsCache = [];
|
||||
return ctx;
|
||||
}
|
||||
|
||||
function checkPlaceholder(ctx) {
|
||||
ctx.config.editor.classList[ctx.isEmpty() ? 'add' : 'remove']('pen-placeholder');
|
||||
}
|
||||
|
||||
function trim(str) {
|
||||
return (str || '').replace(/^\s+|\s+$/g, '');
|
||||
}
|
||||
|
||||
// node.contains is not implemented in IE10/IE11
|
||||
function containsNode(parent, child) {
|
||||
if (parent === child) return true;
|
||||
child = child.parentNode;
|
||||
while (child) {
|
||||
if (child === parent) return true;
|
||||
child = child.parentNode;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getNode(ctx, byRoot) {
|
||||
var node, root = ctx.config.editor;
|
||||
ctx._range = ctx._range || ctx.getRange();
|
||||
node = ctx._range.commonAncestorContainer;
|
||||
if (!node || node === root) return null;
|
||||
while (node && (node.nodeType !== 1) && (node.parentNode !== root)) node = node.parentNode;
|
||||
while (node && byRoot && (node.parentNode !== root)) node = node.parentNode;
|
||||
return containsNode(root, node) ? node : null;
|
||||
}
|
||||
|
||||
// node effects
|
||||
function effectNode(ctx, el, returnAsNodeName) {
|
||||
var nodes = [];
|
||||
el = el || ctx.config.editor;
|
||||
while (el && el !== ctx.config.editor) {
|
||||
if (el.nodeName.match(effectNodeReg)) {
|
||||
nodes.push(returnAsNodeName ? el.nodeName.toLowerCase() : el);
|
||||
}
|
||||
el = el.parentNode;
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
// breakout from node
|
||||
function lineBreak(ctx, empty) {
|
||||
var range = ctx._range = ctx.getRange(), node = doc.createElement('p');
|
||||
if (empty) ctx.config.editor.innerHTML = '';
|
||||
node.innerHTML = '<br>';
|
||||
range.insertNode(node);
|
||||
focusNode(ctx, node.childNodes[0], range);
|
||||
}
|
||||
|
||||
function focusNode(ctx, node, range) {
|
||||
range.setStartAfter(node);
|
||||
range.setEndBefore(node);
|
||||
range.collapse(false);
|
||||
ctx.setRange(range);
|
||||
}
|
||||
|
||||
function autoLink(node) {
|
||||
if (node.nodeType === 1) {
|
||||
if (autoLinkReg.notLink.test(node.tagName)) return;
|
||||
utils.forEach(node.childNodes, function (child) {
|
||||
autoLink(child);
|
||||
}, true);
|
||||
} else if (node.nodeType === 3) {
|
||||
var result = urlToLink(node.nodeValue || '');
|
||||
if (!result.links) return;
|
||||
var frag = doc.createDocumentFragment(),
|
||||
div = doc.createElement('div');
|
||||
div.innerHTML = result.text;
|
||||
while (div.childNodes.length) frag.appendChild(div.childNodes[0]);
|
||||
node.parentNode.replaceChild(frag, node);
|
||||
}
|
||||
}
|
||||
|
||||
function urlToLink(str) {
|
||||
var count = 0;
|
||||
str = str.replace(autoLinkReg.url, function(url) {
|
||||
var realUrl = url, displayUrl = url;
|
||||
count++;
|
||||
if (url.length > autoLinkReg.maxLength) displayUrl = url.slice(0, autoLinkReg.maxLength) + '...';
|
||||
// Add http prefix if necessary
|
||||
if (!autoLinkReg.prefix.test(realUrl)) realUrl = 'http://' + realUrl;
|
||||
return '<a href="' + realUrl + '">' + displayUrl + '</a>';
|
||||
});
|
||||
return {links: count, text: str};
|
||||
}
|
||||
|
||||
function toggleNode(node, hide) {
|
||||
node.style.display = hide ? 'none' : 'block';
|
||||
}
|
||||
|
||||
Pen = function(config) {
|
||||
|
||||
if (!config) throw new Error('Can\'t find config');
|
||||
|
||||
debugMode = config.debug;
|
||||
|
||||
// merge user config
|
||||
var defaults = utils.merge(config);
|
||||
|
||||
var editor = defaults.editor;
|
||||
|
||||
if (!editor || editor.nodeType !== 1) throw new Error('Can\'t find editor');
|
||||
|
||||
// set default class
|
||||
editor.classList.add(defaults.class);
|
||||
|
||||
// set contenteditable
|
||||
editor.setAttribute('contenteditable', 'true');
|
||||
|
||||
// assign config
|
||||
this.config = defaults;
|
||||
|
||||
// set placeholder
|
||||
if (defaults.placeholder) editor.setAttribute('data-placeholder', defaults.placeholder);
|
||||
checkPlaceholder(this);
|
||||
|
||||
// save the selection obj
|
||||
this.selection = selection;
|
||||
|
||||
// define local events
|
||||
this._events = {change: []};
|
||||
|
||||
// enable toolbar
|
||||
initToolbar(this);
|
||||
|
||||
// init events
|
||||
initEvents(this);
|
||||
|
||||
// to check content change
|
||||
this._prevContent = this.getContent();
|
||||
|
||||
// enable markdown covert
|
||||
if (this.markdown) this.markdown.init(this);
|
||||
|
||||
// stay on the page
|
||||
if (this.config.stay) this.stay(this.config);
|
||||
|
||||
if(this.config.input) {
|
||||
this.addOnSubmitListener(this.config.input);
|
||||
}
|
||||
};
|
||||
|
||||
Pen.prototype.on = function(type, listener) {
|
||||
addListener(this, this.config.editor, type, listener);
|
||||
return this;
|
||||
};
|
||||
|
||||
Pen.prototype.addOnSubmitListener = function(inputElement) {
|
||||
var form = inputElement.form;
|
||||
var me = this;
|
||||
form.addEventListener("submit", function() {
|
||||
inputElement.value = me.config.saveAsMarkdown ? me.toMd(me.config.editor.innerHTML) : me.config.editor.innerHTML;
|
||||
});
|
||||
};
|
||||
|
||||
Pen.prototype.isEmpty = function(node) {
|
||||
node = node || this.config.editor;
|
||||
return !(node.querySelector('img')) && !(node.querySelector('blockquote')) &&
|
||||
!(node.querySelector('li')) && !trim(node.textContent);
|
||||
};
|
||||
|
||||
Pen.prototype.getContent = function() {
|
||||
return this.isEmpty() ? '' : trim(this.config.editor.innerHTML);
|
||||
};
|
||||
|
||||
Pen.prototype.setContent = function(html) {
|
||||
this.config.editor.innerHTML = html;
|
||||
this.cleanContent();
|
||||
return this;
|
||||
};
|
||||
|
||||
Pen.prototype.checkContentChange = function () {
|
||||
var prevContent = this._prevContent, currentContent = this.getContent();
|
||||
if (prevContent === currentContent) return;
|
||||
this._prevContent = currentContent;
|
||||
triggerListener(this, 'change', currentContent, prevContent);
|
||||
};
|
||||
|
||||
Pen.prototype.getRange = function() {
|
||||
var editor = this.config.editor, range = selection.rangeCount && selection.getRangeAt(0);
|
||||
if (!range) range = doc.createRange();
|
||||
if (!containsNode(editor, range.commonAncestorContainer)) {
|
||||
range.selectNodeContents(editor);
|
||||
range.collapse(false);
|
||||
}
|
||||
return range;
|
||||
};
|
||||
|
||||
Pen.prototype.setRange = function(range) {
|
||||
range = range || this._range;
|
||||
if (!range) {
|
||||
range = this.getRange();
|
||||
range.collapse(false); // set to end
|
||||
}
|
||||
try {
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
} catch (e) {/* IE throws error sometimes*/}
|
||||
return this;
|
||||
};
|
||||
|
||||
Pen.prototype.focus = function(focusStart) {
|
||||
if (!focusStart) this.setRange();
|
||||
this.config.editor.focus();
|
||||
return this;
|
||||
};
|
||||
|
||||
Pen.prototype.execCommand = function(name, value) {
|
||||
name = name.toLowerCase();
|
||||
this.setRange();
|
||||
|
||||
if (commandsReg.block.test(name)) {
|
||||
commandBlock(this, name);
|
||||
} else if (commandsReg.inline.test(name)) {
|
||||
commandOverall(this, name, value);
|
||||
} else if (commandsReg.source.test(name)) {
|
||||
commandLink(this, name, value);
|
||||
} else if (commandsReg.insert.test(name)) {
|
||||
commandInsert(this, name, value);
|
||||
} else if (commandsReg.wrap.test(name)) {
|
||||
commandWrap(this, name, value);
|
||||
} else {
|
||||
utils.log('can not find command function for name: ' + name + (value ? (', value: ' + value) : ''), true);
|
||||
}
|
||||
if (name === 'indent') this.checkContentChange();
|
||||
else this.cleanContent({cleanAttrs: ['style']});
|
||||
};
|
||||
|
||||
// remove attrs and tags
|
||||
// pen.cleanContent({cleanAttrs: ['style'], cleanTags: ['id']})
|
||||
Pen.prototype.cleanContent = function(options) {
|
||||
var editor = this.config.editor;
|
||||
|
||||
if (!options) options = this.config;
|
||||
utils.forEach(options.cleanAttrs, function (attr) {
|
||||
utils.forEach(editor.querySelectorAll('[' + attr + ']'), function(item) {
|
||||
item.removeAttribute(attr);
|
||||
}, true);
|
||||
}, true);
|
||||
utils.forEach(options.cleanTags, function (tag) {
|
||||
utils.forEach(editor.querySelectorAll(tag), function(item) {
|
||||
item.parentNode.removeChild(item);
|
||||
}, true);
|
||||
}, true);
|
||||
|
||||
checkPlaceholder(this);
|
||||
this.checkContentChange();
|
||||
return this;
|
||||
};
|
||||
|
||||
// auto link content, return content
|
||||
Pen.prototype.autoLink = function() {
|
||||
autoLink(this.config.editor);
|
||||
return this.getContent();
|
||||
};
|
||||
|
||||
// highlight menu
|
||||
Pen.prototype.highlight = function() {
|
||||
var toolbar = this._toolbar || this._menu
|
||||
, node = getNode(this);
|
||||
// remove all highlights
|
||||
utils.forEach(toolbar.querySelectorAll('.active'), function(el) {
|
||||
el.classList.remove('active');
|
||||
}, true);
|
||||
|
||||
if (!node) return this;
|
||||
|
||||
var effects = effectNode(this, node)
|
||||
, inputBar = this._inputBar
|
||||
, highlight;
|
||||
|
||||
if (inputBar && toolbar === this._menu) {
|
||||
// display link input if createlink enabled
|
||||
inputBar.style.display = 'none';
|
||||
// reset link input value
|
||||
inputBar.value = '';
|
||||
}
|
||||
|
||||
highlight = function(str) {
|
||||
if (!str) return;
|
||||
var el = toolbar.querySelector('[data-action=' + str + ']');
|
||||
return el && el.classList.add('active');
|
||||
};
|
||||
utils.forEach(effects, function(item) {
|
||||
var tag = item.nodeName.toLowerCase();
|
||||
switch(tag) {
|
||||
case 'a':
|
||||
if (inputBar) inputBar.value = item.getAttribute('href');
|
||||
tag = 'createlink';
|
||||
break;
|
||||
case 'img':
|
||||
if (inputBar) inputBar.value = item.getAttribute('src');
|
||||
tag = 'insertimage';
|
||||
break;
|
||||
case 'i':
|
||||
tag = 'italic';
|
||||
break;
|
||||
case 'u':
|
||||
tag = 'underline';
|
||||
break;
|
||||
case 'b':
|
||||
tag = 'bold';
|
||||
break;
|
||||
case 'pre':
|
||||
case 'code':
|
||||
tag = 'code';
|
||||
break;
|
||||
case 'ul':
|
||||
tag = 'insertunorderedlist';
|
||||
break;
|
||||
case 'ol':
|
||||
tag = 'insertorderedlist';
|
||||
break;
|
||||
case 'li':
|
||||
tag = 'indent';
|
||||
break;
|
||||
}
|
||||
highlight(tag);
|
||||
}, true);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
// show menu
|
||||
Pen.prototype.menu = function() {
|
||||
|
||||
var allMenus = document.getElementsByClassName('pen-menu');
|
||||
|
||||
// Hide all menus
|
||||
for(var x in allMenus){
|
||||
try{
|
||||
if('style' in allMenus[x]){
|
||||
allMenus[x].style.display = 'none';
|
||||
}
|
||||
}catch(e){}
|
||||
}
|
||||
|
||||
if (!this._menu) return this;
|
||||
if (selection.isCollapsed) {
|
||||
this._menu.style.display = 'none'; //hide menu
|
||||
this._inputActive = false;
|
||||
return this;
|
||||
}
|
||||
if (this._toolbar) {
|
||||
if (!this._inputBar || !this._inputActive) return this;
|
||||
}
|
||||
var offset = this._range.getBoundingClientRect()
|
||||
, menuPadding = 10
|
||||
, top = offset.top - menuPadding
|
||||
, left = offset.left + (offset.width / 2)
|
||||
, menu = this._menu
|
||||
, menuOffset = {x: 0, y: 0}
|
||||
, stylesheet = this._stylesheet;
|
||||
|
||||
// fixes some browser double click visual discontinuity
|
||||
// if the offset has no width or height it should not be used
|
||||
if (offset.width === 0 && offset.height === 0) return this;
|
||||
|
||||
// store the stylesheet used for positioning the menu horizontally
|
||||
if (this._stylesheet === undefined) {
|
||||
var style = document.createElement("style");
|
||||
document.head.appendChild(style);
|
||||
this._stylesheet = stylesheet = style.sheet;
|
||||
}
|
||||
|
||||
// display block to caculate its width & height
|
||||
menu.style.display = 'block';
|
||||
|
||||
menuOffset.x = left - (menu.clientWidth / 2);
|
||||
menuOffset.y = top - menu.clientHeight;
|
||||
|
||||
// check to see if menu has over-extended its bounding box. if it has,
|
||||
// 1) apply a new class if overflowed on top;
|
||||
// 2) apply a new rule if overflowed on the left
|
||||
if (stylesheet.cssRules.length > 0) {
|
||||
stylesheet.deleteRule(0);
|
||||
}
|
||||
if (menuOffset.x < 0) {
|
||||
menuOffset.x = 0;
|
||||
stylesheet.insertRule('.pen-menu:after {left: ' + left + 'px;}', 0);
|
||||
} else {
|
||||
stylesheet.insertRule('.pen-menu:after {left: 50%; }', 0);
|
||||
}
|
||||
if (menuOffset.y < 0) {
|
||||
menu.classList.add('pen-menu-below');
|
||||
menuOffset.y = offset.top + offset.height + menuPadding;
|
||||
} else {
|
||||
menu.classList.remove('pen-menu-below');
|
||||
}
|
||||
|
||||
menu.style.top = menuOffset.y + 'px';
|
||||
menu.style.left = menuOffset.x + 'px';
|
||||
return this;
|
||||
};
|
||||
|
||||
Pen.prototype.stay = function(config) {
|
||||
var ctx = this;
|
||||
if (!window.onbeforeunload) {
|
||||
window.onbeforeunload = function() {
|
||||
if (!ctx._isDestroyed) return config.stayMsg;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Pen.prototype.destroy = function(isAJoke) {
|
||||
var destroy = isAJoke ? false : true
|
||||
, attr = isAJoke ? 'setAttribute' : 'removeAttribute';
|
||||
|
||||
if (!isAJoke) {
|
||||
removeAllListeners(this);
|
||||
try {
|
||||
selection.removeAllRanges();
|
||||
if (this._menu) this._menu.parentNode.removeChild(this._menu);
|
||||
} catch (e) {/* IE throws error sometimes*/}
|
||||
} else {
|
||||
initToolbar(this);
|
||||
initEvents(this);
|
||||
}
|
||||
this._isDestroyed = destroy;
|
||||
this.config.editor[attr]('contenteditable', '');
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Pen.prototype.rebuild = function() {
|
||||
return this.destroy('it\'s a joke');
|
||||
};
|
||||
|
||||
// a fallback for old browers
|
||||
root.Pen = function(config) {
|
||||
if (!config) return utils.log('can\'t find config', true);
|
||||
|
||||
var defaults = utils.merge(config)
|
||||
, klass = defaults.editor.getAttribute('class');
|
||||
|
||||
klass = klass ? klass.replace(/\bpen\b/g, '') + ' pen-textarea ' + defaults.class : 'pen pen-textarea';
|
||||
defaults.editor.setAttribute('class', klass);
|
||||
defaults.editor.innerHTML = defaults.textarea;
|
||||
return defaults.editor;
|
||||
};
|
||||
|
||||
// export content as markdown
|
||||
var regs = {
|
||||
a: [/<a\b[^>]*href=["']([^"]+|[^']+)\b[^>]*>(.*?)<\/a>/ig, '[$2]($1)'],
|
||||
img: [/<img\b[^>]*src=["']([^\"+|[^']+)[^>]*>/ig, ''],
|
||||
b: [/<b\b[^>]*>(.*?)<\/b>/ig, '**$1**'],
|
||||
i: [/<i\b[^>]*>(.*?)<\/i>/ig, '***$1***'],
|
||||
h: [/<h([1-6])\b[^>]*>(.*?)<\/h\1>/ig, function(a, b, c) {
|
||||
return '\n' + ('######'.slice(0, b)) + ' ' + c + '\n';
|
||||
}],
|
||||
li: [/<(li)\b[^>]*>(.*?)<\/\1>/ig, '* $2\n'],
|
||||
blockquote: [/<(blockquote)\b[^>]*>(.*?)<\/\1>/ig, '\n> $2\n'],
|
||||
pre: [/<pre\b[^>]*>(.*?)<\/pre>/ig, '\n```\n$1\n```\n'],
|
||||
code: [/<code\b[^>]*>(.*?)<\/code>/ig, '\n`\n$1\n`\n'],
|
||||
p: [/<p\b[^>]*>(.*?)<\/p>/ig, '\n$1\n'],
|
||||
hr: [/<hr\b[^>]*>/ig, '\n---\n']
|
||||
};
|
||||
|
||||
Pen.prototype.toMd = function() {
|
||||
var html = this.getContent()
|
||||
.replace(/\n+/g, '') // remove line break
|
||||
.replace(/<([uo])l\b[^>]*>(.*?)<\/\1l>/ig, '$2'); // remove ul/ol
|
||||
|
||||
for(var p in regs) {
|
||||
if (regs.hasOwnProperty(p))
|
||||
html = html.replace.apply(html, regs[p]);
|
||||
}
|
||||
return html.replace(/\*{5}/g, '**');
|
||||
};
|
||||
|
||||
// make it accessible
|
||||
if (doc.getSelection) {
|
||||
selection = doc.getSelection();
|
||||
root.Pen = Pen;
|
||||
}
|
||||
|
||||
}(window, document));
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,16 @@
|
||||
/*! Copyright (c) 2011 Piotr Rochala (http://rocha.la)
|
||||
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
|
||||
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
|
||||
*
|
||||
* Version: 1.3.8
|
||||
*
|
||||
*/
|
||||
(function(e){e.fn.extend({slimScroll:function(f){var a=e.extend({width:"auto",height:"250px",size:"7px",color:"#000",position:"right",distance:"1px",start:"top",opacity:.4,alwaysVisible:!1,disableFadeOut:!1,railVisible:!1,railColor:"#333",railOpacity:.2,railDraggable:!0,railClass:"slimScrollRail",barClass:"slimScrollBar",wrapperClass:"slimScrollDiv",allowPageScroll:!1,wheelStep:20,touchScrollStep:200,borderRadius:"7px",railBorderRadius:"7px"},f);this.each(function(){function v(d){if(r){d=d||window.event;
|
||||
var c=0;d.wheelDelta&&(c=-d.wheelDelta/120);d.detail&&(c=d.detail/3);e(d.target||d.srcTarget||d.srcElement).closest("."+a.wrapperClass).is(b.parent())&&n(c,!0);d.preventDefault&&!k&&d.preventDefault();k||(d.returnValue=!1)}}function n(d,g,e){k=!1;var f=b.outerHeight()-c.outerHeight();g&&(g=parseInt(c.css("top"))+d*parseInt(a.wheelStep)/100*c.outerHeight(),g=Math.min(Math.max(g,0),f),g=0<d?Math.ceil(g):Math.floor(g),c.css({top:g+"px"}));l=parseInt(c.css("top"))/(b.outerHeight()-c.outerHeight());g=
|
||||
l*(b[0].scrollHeight-b.outerHeight());e&&(g=d,d=g/b[0].scrollHeight*b.outerHeight(),d=Math.min(Math.max(d,0),f),c.css({top:d+"px"}));b.scrollTop(g);b.trigger("slimscrolling",~~g);w();p()}function x(){u=Math.max(b.outerHeight()/b[0].scrollHeight*b.outerHeight(),30);c.css({height:u+"px"});var a=u==b.outerHeight()?"none":"block";c.css({display:a})}function w(){x();clearTimeout(B);l==~~l?(k=a.allowPageScroll,C!=l&&b.trigger("slimscroll",0==~~l?"top":"bottom")):k=!1;C=l;u>=b.outerHeight()?k=!0:(c.stop(!0,
|
||||
!0).fadeIn("fast"),a.railVisible&&m.stop(!0,!0).fadeIn("fast"))}function p(){a.alwaysVisible||(B=setTimeout(function(){a.disableFadeOut&&r||y||z||(c.fadeOut("slow"),m.fadeOut("slow"))},1E3))}var r,y,z,B,A,u,l,C,k=!1,b=e(this);if(b.parent().hasClass(a.wrapperClass)){var q=b.scrollTop(),c=b.siblings("."+a.barClass),m=b.siblings("."+a.railClass);x();if(e.isPlainObject(f)){if("height"in f&&"auto"==f.height){b.parent().css("height","auto");b.css("height","auto");var h=b.parent().parent().height();b.parent().css("height",
|
||||
h);b.css("height",h)}else"height"in f&&(h=f.height,b.parent().css("height",h),b.css("height",h));if("scrollTo"in f)q=parseInt(a.scrollTo);else if("scrollBy"in f)q+=parseInt(a.scrollBy);else if("destroy"in f){c.remove();m.remove();b.unwrap();return}n(q,!1,!0)}}else if(!(e.isPlainObject(f)&&"destroy"in f)){a.height="auto"==a.height?b.parent().height():a.height;q=e("<div></div>").addClass(a.wrapperClass).css({position:"relative",overflow:"hidden",width:a.width,height:a.height});b.css({overflow:"hidden",
|
||||
width:a.width,height:a.height});var m=e("<div></div>").addClass(a.railClass).css({width:a.size,height:"100%",position:"absolute",top:0,display:a.alwaysVisible&&a.railVisible?"block":"none","border-radius":a.railBorderRadius,background:a.railColor,opacity:a.railOpacity,zIndex:90}),c=e("<div></div>").addClass(a.barClass).css({background:a.color,width:a.size,position:"absolute",top:0,opacity:a.opacity,display:a.alwaysVisible?"block":"none","border-radius":a.borderRadius,BorderRadius:a.borderRadius,MozBorderRadius:a.borderRadius,
|
||||
WebkitBorderRadius:a.borderRadius,zIndex:99}),h="right"==a.position?{right:a.distance}:{left:a.distance};m.css(h);c.css(h);b.wrap(q);b.parent().append(c);b.parent().append(m);a.railDraggable&&c.bind("mousedown",function(a){var b=c.parent();z=!0;t=parseFloat(c.css("top"));pageY=a.pageY;b.bind("mousemove.slimscroll",function(a){currTop=t+a.pageY-pageY;c.css("top",currTop);n(0,c.position().top,!1)});b.bind("mouseup.slimscroll",function(a){z=!1;p();b.unbind(".slimscroll")});return!1}).bind("selectstart.slimscroll",
|
||||
function(a){a.stopPropagation();a.preventDefault();return!1});m.hover(function(){w()},function(){p()});c.hover(function(){y=!0},function(){y=!1});b.hover(function(){r=!0;w();p()},function(){r=!1;p()});b.bind("touchstart",function(a,b){a.originalEvent.touches.length&&(A=a.originalEvent.touches[0].pageY)});b.bind("touchmove",function(b){k||b.originalEvent.preventDefault();b.originalEvent.touches.length&&(n((A-b.originalEvent.touches[0].pageY)/a.touchScrollStep,!0),A=b.originalEvent.touches[0].pageY)});
|
||||
x();"bottom"===a.start?(c.css({top:b.outerHeight()-c.outerHeight()}),n(0,!0)):"top"!==a.start&&(n(e(a.start).position().top,null,!0),a.alwaysVisible||c.hide());window.addEventListener?(this.addEventListener("DOMMouseScroll",v,!1),this.addEventListener("mousewheel",v,!1)):document.attachEvent("onmousewheel",v)}});return this}});e.fn.extend({slimscroll:e.fn.slimScroll})})(jQuery);
|
||||
@@ -0,0 +1,148 @@
|
||||
function pagelayer_tlite(getTooltipOpts) {
|
||||
document.addEventListener('mouseover', function (e) {
|
||||
var el = e.target;
|
||||
var opts = getTooltipOpts(el);
|
||||
|
||||
if (!opts) {
|
||||
el = el.parentElement;
|
||||
opts = el && getTooltipOpts(el);
|
||||
}
|
||||
|
||||
opts && pagelayer_tlite.show(el, opts, true);
|
||||
});
|
||||
}
|
||||
|
||||
pagelayer_tlite.show = function (el, opts, isAuto) {
|
||||
var fallbackAttrib = 'data-tlite';
|
||||
opts = opts || {};
|
||||
|
||||
(el.tooltip || Tooltip(el, opts)).show();
|
||||
|
||||
function Tooltip(el, opts) {
|
||||
var tooltipEl;
|
||||
var showTimer;
|
||||
var text;
|
||||
|
||||
el.addEventListener('mousedown', autoHide);
|
||||
el.addEventListener('mouseleave', autoHide);
|
||||
|
||||
function show() {
|
||||
text = el.title || el.getAttribute(fallbackAttrib) || text;
|
||||
el.title = '';
|
||||
el.setAttribute(fallbackAttrib, '');
|
||||
text && !showTimer && (showTimer = setTimeout(fadeIn, isAuto ? 150 : 1))
|
||||
}
|
||||
|
||||
function autoHide() {
|
||||
pagelayer_tlite.hide(el, true);
|
||||
}
|
||||
|
||||
function hide(isAutoHiding) {
|
||||
if (isAuto === isAutoHiding) {
|
||||
showTimer = clearTimeout(showTimer);
|
||||
var parent = tooltipEl && tooltipEl.parentNode;
|
||||
parent && parent.removeChild(tooltipEl);
|
||||
tooltipEl = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function fadeIn() {
|
||||
if (!tooltipEl) {
|
||||
tooltipEl = createTooltip(el, text, opts);
|
||||
}
|
||||
}
|
||||
|
||||
return el.tooltip = {
|
||||
show: show,
|
||||
hide: hide
|
||||
};
|
||||
}
|
||||
|
||||
function createTooltip(el, text, opts) {
|
||||
var tooltipEl = document.createElement('span');
|
||||
var grav = opts.grav || el.getAttribute('data-tlite') || 'n';
|
||||
|
||||
tooltipEl.innerHTML = text;
|
||||
|
||||
el.appendChild(tooltipEl);
|
||||
|
||||
var vertGrav = grav[0] || '';
|
||||
var horzGrav = grav[1] || '';
|
||||
|
||||
var windowInnerWidth = window.parent.innerWidth - 15;
|
||||
var windowInnerHeight = window.parent.innerHeight;
|
||||
|
||||
function positionTooltip() {
|
||||
tooltipEl.className = 'pagelayer-tlite ' + 'pagelayer-tlite-' + vertGrav + horzGrav;
|
||||
|
||||
var arrowSize = 10;
|
||||
var top = el.offsetTop;
|
||||
var left = el.offsetLeft;
|
||||
|
||||
if (tooltipEl.offsetParent === el) {
|
||||
top = left = 0;
|
||||
}
|
||||
|
||||
var width = el.offsetWidth;
|
||||
var height = el.offsetHeight;
|
||||
var tooltipHeight = tooltipEl.offsetHeight;
|
||||
var tooltipWidth = tooltipEl.offsetWidth;
|
||||
var centerEl = left + (width / 2);
|
||||
|
||||
tooltipEl.style.top = (
|
||||
vertGrav === 's' ? (top - tooltipHeight - arrowSize) :
|
||||
vertGrav === 'n' ? (top + height + arrowSize) :
|
||||
(top + (height / 2) - (tooltipHeight / 2))
|
||||
) + 'px';
|
||||
|
||||
tooltipEl.style.left = (
|
||||
horzGrav === 'w' ? left :
|
||||
horzGrav === 'e' ? left + width - tooltipWidth :
|
||||
vertGrav === 'w' ? (left + width + arrowSize) :
|
||||
vertGrav === 'e' ? (left - tooltipWidth - arrowSize) :
|
||||
(centerEl - tooltipWidth / 2)
|
||||
) + 'px';
|
||||
}
|
||||
|
||||
positionTooltip();
|
||||
|
||||
var rect = tooltipEl.getBoundingClientRect();
|
||||
|
||||
if (vertGrav === 's' && rect.top < 0) {
|
||||
vertGrav = 'n';
|
||||
positionTooltip();
|
||||
} else if (vertGrav === 'n' && rect.bottom > windowInnerHeight) {
|
||||
vertGrav = 's';
|
||||
positionTooltip();
|
||||
} else if (vertGrav === 'e' && rect.left < 0) {
|
||||
vertGrav = 'w';
|
||||
positionTooltip();
|
||||
} else if (vertGrav === 'w' && rect.right > windowInnerWidth) {
|
||||
vertGrav = 'e';
|
||||
positionTooltip();
|
||||
}
|
||||
|
||||
positionTooltip();
|
||||
|
||||
// Additional handling
|
||||
if(rect.left < 0) {
|
||||
horzGrav = 'w';
|
||||
positionTooltip();
|
||||
} else if (rect.right > windowInnerWidth) {
|
||||
horzGrav = 'e';
|
||||
positionTooltip();
|
||||
}
|
||||
|
||||
tooltipEl.className += ' pagelayer-tlite-visible';
|
||||
|
||||
return tooltipEl;
|
||||
}
|
||||
};
|
||||
|
||||
pagelayer_tlite.hide = function (el, isAuto) {
|
||||
el.tooltip && el.tooltip.hide(isAuto);
|
||||
};
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = tlite;
|
||||
}
|
||||
@@ -0,0 +1,428 @@
|
||||
(function ($) {
|
||||
'use strict';
|
||||
// jshint camelcase:true
|
||||
|
||||
|
||||
function hex(x) {
|
||||
return ('0' + parseInt(x).toString(16)).slice(-2);
|
||||
}
|
||||
|
||||
function colorToHex(rgb) {
|
||||
if (rgb.search('rgb') === -1) {
|
||||
return rgb.replace('#', '');
|
||||
} else if (rgb === 'rgba(0, 0, 0, 0)') {
|
||||
return 'transparent';
|
||||
} else {
|
||||
rgb = rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))?\)$/);
|
||||
return hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
|
||||
}
|
||||
}
|
||||
|
||||
function colorTagHandler(element, trumbowyg) {
|
||||
var tags = [];
|
||||
|
||||
if (!element.style) {
|
||||
return tags;
|
||||
}
|
||||
|
||||
// background color
|
||||
if (element.style.backgroundColor !== '') {
|
||||
var backColor = colorToHex(element.style.backgroundColor);
|
||||
if (trumbowyg.o.plugins.colors.colorList.indexOf(backColor) >= 0) {
|
||||
tags.push('backColor' + backColor);
|
||||
} else {
|
||||
tags.push('backColorFree');
|
||||
}
|
||||
}
|
||||
|
||||
// text color
|
||||
var foreColor;
|
||||
if (element.style.color !== '') {
|
||||
foreColor = colorToHex(element.style.color);
|
||||
} else if (element.hasAttribute('color')) {
|
||||
foreColor = colorToHex(element.getAttribute('color'));
|
||||
}
|
||||
if (foreColor) {
|
||||
if (trumbowyg.o.plugins.colors.colorList.indexOf(foreColor) >= 0) {
|
||||
tags.push('foreColor' + foreColor);
|
||||
} else {
|
||||
tags.push('foreColorFree');
|
||||
}
|
||||
}
|
||||
|
||||
return tags;
|
||||
}
|
||||
|
||||
var defaultOptions = {
|
||||
colorList: ['ffffff', '000000', 'eeece1', '1f497d', '4f81bd', 'c0504d', '9bbb59', '8064a2', '4bacc6', 'f79646', 'ffff00', 'f2f2f2', '7f7f7f', 'ddd9c3', 'c6d9f0', 'dbe5f1', 'f2dcdb', 'ebf1dd', 'e5e0ec', 'dbeef3', 'fdeada', 'fff2ca', 'd8d8d8', '595959', 'c4bd97', '8db3e2', 'b8cce4', 'e5b9b7', 'd7e3bc', 'ccc1d9', 'b7dde8', 'fbd5b5', 'ffe694', 'bfbfbf', '3f3f3f', '938953', '548dd4', '95b3d7', 'd99694', 'c3d69b', 'b2a2c7', 'b7dde8', 'fac08f', 'f2c314', 'a5a5a5', '262626', '494429', '17365d', '366092', '953734', '76923c', '5f497a', '92cddc', 'e36c09', 'c09100', '7f7f7f', '0c0c0c', '1d1b10', '0f243e', '244061', '632423', '4f6128', '3f3151', '31859b', '974806', '7f6000']
|
||||
};
|
||||
|
||||
// Default Options for font-size
|
||||
var fontSizedefaultOptions = {
|
||||
sizeList: ['x-small', 'small', 'medium', 'large', 'x-large'],
|
||||
allowCustomSize: true
|
||||
};
|
||||
|
||||
// Default Options for line height
|
||||
var lineHeightOptions = {
|
||||
sizeList: ['0.9', '1', '1.5', '2.0', '2.5','3.0', '3.5', '4.0', '4.5', '5.0'],
|
||||
allowCustomSize: true
|
||||
};
|
||||
|
||||
// If WP media is a button
|
||||
function openwpmediaDef(trumbowyg) {
|
||||
return {
|
||||
fn: function() {
|
||||
// WP media button logic
|
||||
|
||||
var func_media = window['pagelayer_select_frame'];
|
||||
|
||||
if(typeof func_media == 'function'){
|
||||
|
||||
// Load the frame
|
||||
var frame = pagelayer_select_frame('image');
|
||||
|
||||
// On select update the stuff
|
||||
frame.on({'select': function(){
|
||||
var state = frame.state();
|
||||
var url = '', alt = '', id = '';
|
||||
|
||||
// External URL
|
||||
if('props' in state){
|
||||
|
||||
url = state.props.attributes.url;
|
||||
alt = state.props.attributes.alt;
|
||||
|
||||
// Internal from gallery
|
||||
}else{
|
||||
|
||||
var attachment = frame.state().get('selection').first().toJSON();
|
||||
//console.log(attachment);
|
||||
|
||||
// Set the new and URL
|
||||
url = attachment.url;
|
||||
alt = attachment.alt;
|
||||
id = attachment.id;
|
||||
|
||||
}
|
||||
|
||||
trumbowyg.execCmd('insertImage', url, false, true);
|
||||
var $img = $('img[src="' + url + '"]:not([alt])', trumbowyg.$box);
|
||||
|
||||
$img.attr('alt', alt);
|
||||
$img.attr('pl-media-id', id);
|
||||
|
||||
trumbowyg.syncCode;
|
||||
trumbowyg.$c.trigger('tbwchange');
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
frame.open();
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
ico: 'insert-image'
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$.extend(true, $.trumbowyg, {
|
||||
// Add some translations
|
||||
langs: {
|
||||
en: {
|
||||
wpmedia: 'Insert Image',
|
||||
foreColor: 'Text color',
|
||||
backColor: 'Background color',
|
||||
fontsize: 'Font size',
|
||||
fontsizes: {
|
||||
'x-small': 'Extra small',
|
||||
'small': 'Small',
|
||||
'medium': 'Regular',
|
||||
'large': 'Large',
|
||||
'x-large': 'Extra large',
|
||||
'custom': 'Custom'
|
||||
},
|
||||
fontCustomSize: {
|
||||
title: 'Custom Font Size',
|
||||
label: 'Font Size',
|
||||
value: '48px'
|
||||
},
|
||||
lineheight: 'Line Height',
|
||||
lineCustomHeight: {
|
||||
title: 'Custom Line Height',
|
||||
label: 'Line Height',
|
||||
value: '7.0'
|
||||
},
|
||||
lineheights: {
|
||||
'normal': 'Normal',
|
||||
'custom': 'Custom',
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
// Add our plugin to Trumbowyg registred plugins
|
||||
plugins: {
|
||||
wpmedia: {
|
||||
init: function(trumbowyg) {
|
||||
var t = $(this);
|
||||
// Fill current Trumbowyg instance with WP media default options
|
||||
trumbowyg.o.plugins.wpmedia = $.extend(true, {},
|
||||
defaultOptions,
|
||||
trumbowyg.o.plugins.wpmedia || {}
|
||||
);
|
||||
|
||||
// If WP media is a
|
||||
trumbowyg.addBtnDef('wpmedia', openwpmediaDef(trumbowyg));
|
||||
|
||||
},
|
||||
},
|
||||
color: {
|
||||
init: function (trumbowyg) {
|
||||
trumbowyg.o.plugins.colors = trumbowyg.o.plugins.colors || defaultOptions;
|
||||
var foreColorBtnDef = {
|
||||
dropdown: buildDropdown('foreColor', trumbowyg)
|
||||
},
|
||||
backColorBtnDef = {
|
||||
dropdown: buildDropdown('backColor', trumbowyg)
|
||||
};
|
||||
|
||||
trumbowyg.addBtnDef('foreColor', foreColorBtnDef);
|
||||
trumbowyg.addBtnDef('backColor', backColorBtnDef);
|
||||
},
|
||||
tagHandler: colorTagHandler
|
||||
},
|
||||
pasteImage: {
|
||||
init: function (trumbowyg) {
|
||||
trumbowyg.pasteHandlers.push(function (pasteEvent) {
|
||||
|
||||
var pagelayer_ajax_func = {};
|
||||
|
||||
// This function for ajax success call back
|
||||
pagelayer_ajax_func['success'] = function(obj){
|
||||
//alert(obj);
|
||||
if(obj['success']){
|
||||
trumbowyg.execCmd('insertImage', obj['data']['url'], false, true);
|
||||
}else{
|
||||
alert(obj['data']['message']);
|
||||
}
|
||||
}
|
||||
|
||||
// This function for ajax before send call back
|
||||
pagelayer_ajax_func['beforeSend'] = function(xhr){
|
||||
trumbowyg.showOverlay();
|
||||
}
|
||||
|
||||
// This function for ajax complete call back
|
||||
pagelayer_ajax_func['complete'] = function(xhr){
|
||||
trumbowyg.hideOverlay();
|
||||
}
|
||||
|
||||
pagelayer_editable_paste_handler(pasteEvent, pagelayer_ajax_func);
|
||||
});
|
||||
}
|
||||
},
|
||||
fontsize: {
|
||||
init: function (trumbowyg) {
|
||||
trumbowyg.o.plugins.fontsize = $.extend({},
|
||||
fontSizedefaultOptions,
|
||||
trumbowyg.o.plugins.fontsize || {}
|
||||
);
|
||||
trumbowyg.addBtnDef('fontsize', {
|
||||
dropdown: fontSizeBuildDropdown(trumbowyg)
|
||||
});
|
||||
}
|
||||
},
|
||||
lineheight: {
|
||||
init: function (trumbowyg) {
|
||||
trumbowyg.o.plugins.lineheight = $.extend({},
|
||||
lineHeightOptions,
|
||||
trumbowyg.o.plugins.lineheight || {}
|
||||
);
|
||||
|
||||
trumbowyg.addBtnDef('lineheight', {
|
||||
dropdown: lineHeightDropdown(trumbowyg)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function buildDropdown(fn, trumbowyg) {
|
||||
var dropdown = [];
|
||||
|
||||
$.each(trumbowyg.o.plugins.colors.colorList, function (i, color) {
|
||||
var btn = fn + color,
|
||||
btnDef = {
|
||||
fn: fn,
|
||||
forceCss: true,
|
||||
param: '#' + color,
|
||||
style: 'background-color: #' + color + ';'
|
||||
};
|
||||
trumbowyg.addBtnDef(btn, btnDef);
|
||||
dropdown.push(btn);
|
||||
});
|
||||
|
||||
var removeColorButtonName = fn + 'Remove',
|
||||
removeColorBtnDef = {
|
||||
fn: 'removeFormat',
|
||||
param: fn,
|
||||
style: 'background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAYAAACp8Z5+AAAAG0lEQVQIW2NkQAAfEJMRmwBYhoGBYQtMBYoAADziAp0jtJTgAAAAAElFTkSuQmCC);'
|
||||
};
|
||||
trumbowyg.addBtnDef(removeColorButtonName, removeColorBtnDef);
|
||||
dropdown.push(removeColorButtonName);
|
||||
|
||||
// add free color btn
|
||||
var freeColorButtonName = fn + 'Free',
|
||||
freeColorBtnDef = {
|
||||
fn: function () {
|
||||
trumbowyg.openModalInsert(trumbowyg.lang[fn],
|
||||
{
|
||||
color: {
|
||||
label: fn,
|
||||
forceCss: true,
|
||||
type: 'color',
|
||||
value: '#FFFFFF'
|
||||
}
|
||||
},
|
||||
// callback
|
||||
function (values) {
|
||||
trumbowyg.execCmd(fn, values.color);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
},
|
||||
text: '#',
|
||||
// style adjust for displaying the text
|
||||
style: 'text-indent: 0;line-height: 20px;padding: 0 5px;'
|
||||
};
|
||||
trumbowyg.addBtnDef(freeColorButtonName, freeColorBtnDef);
|
||||
dropdown.push(freeColorButtonName);
|
||||
|
||||
return dropdown;
|
||||
}
|
||||
|
||||
// Functions for font-size widget
|
||||
function setFontSize(trumbowyg, size) {
|
||||
trumbowyg.$ed.focus();
|
||||
trumbowyg.saveRange();
|
||||
var text = trumbowyg.range.startContainer.parentElement;
|
||||
var selectedText = trumbowyg.getRangeText();
|
||||
if ($(text).html() === selectedText) {
|
||||
$(text).css('font-size', size);
|
||||
} else {
|
||||
trumbowyg.range.deleteContents();
|
||||
var html = '<span style="font-size: ' + size + ';">' + selectedText + '</span>';
|
||||
var node = $(html)[0];
|
||||
trumbowyg.range.insertNode(node);
|
||||
}
|
||||
}
|
||||
|
||||
function fontSizeBuildDropdown(trumbowyg) {
|
||||
var dropdown = [];
|
||||
|
||||
$.each(trumbowyg.o.plugins.fontsize.sizeList, function (index, size) {
|
||||
trumbowyg.addBtnDef('fontsize_' + size, {
|
||||
text: '<span style="font-size: ' + size + ';">' + (trumbowyg.lang.fontsizes[size] || size) + '</span>',
|
||||
hasIcon: false,
|
||||
fn: function () {
|
||||
setFontSize(trumbowyg, size);
|
||||
trumbowyg.syncCode();
|
||||
trumbowyg.$c.trigger('tbwchange');
|
||||
}
|
||||
});
|
||||
dropdown.push('fontsize_' + size);
|
||||
});
|
||||
|
||||
if (trumbowyg.o.plugins.fontsize.allowCustomSize) {
|
||||
var customSizeButtonName = 'fontsize_custom';
|
||||
var customSizeBtnDef = {
|
||||
fn: function () {
|
||||
trumbowyg.openModalInsert(trumbowyg.lang.fontCustomSize.title,
|
||||
{
|
||||
size: {
|
||||
label: trumbowyg.lang.fontCustomSize.label,
|
||||
value: trumbowyg.lang.fontCustomSize.value
|
||||
}
|
||||
},
|
||||
function (form) {
|
||||
setFontSize(trumbowyg, form.size);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
},
|
||||
text: '<span style="font-size: medium;">' + trumbowyg.lang.fontsizes.custom + '</span>',
|
||||
hasIcon: false
|
||||
};
|
||||
trumbowyg.addBtnDef(customSizeButtonName, customSizeBtnDef);
|
||||
dropdown.push(customSizeButtonName);
|
||||
}
|
||||
|
||||
return dropdown;
|
||||
}
|
||||
|
||||
// Build the dropdown for line-height
|
||||
function lineHeightDropdown(trumbowyg) {
|
||||
var dropdown = [];
|
||||
|
||||
$.each(trumbowyg.o.plugins.lineheight.sizeList, function(index, size) {
|
||||
trumbowyg.addBtnDef('lineheight_' + size, {
|
||||
text: trumbowyg.lang.lineheights[size] || size,
|
||||
hasIcon: false,
|
||||
fn: function(){
|
||||
setLineHight(trumbowyg, size);
|
||||
}
|
||||
});
|
||||
dropdown.push('lineheight_' + size);
|
||||
});
|
||||
|
||||
if (trumbowyg.o.plugins.lineheight.allowCustomSize) {
|
||||
var customSizeButtonName = 'lineheight_custom';
|
||||
var customSizeBtnDef = {
|
||||
fn: function () {
|
||||
trumbowyg.openModalInsert(trumbowyg.lang.lineCustomHeight.title,
|
||||
{
|
||||
size: {
|
||||
label: trumbowyg.lang.lineCustomHeight.label,
|
||||
value: trumbowyg.lang.lineCustomHeight.value
|
||||
}
|
||||
},
|
||||
function (form) {
|
||||
setLineHight(trumbowyg, form.size);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
},
|
||||
text: '<span style="font-size: medium;">' + trumbowyg.lang.lineheights.custom + '</span>',
|
||||
hasIcon: false
|
||||
};
|
||||
trumbowyg.addBtnDef(customSizeButtonName, customSizeBtnDef);
|
||||
dropdown.push(customSizeButtonName);
|
||||
}
|
||||
|
||||
return dropdown;
|
||||
}
|
||||
|
||||
// Set line-height
|
||||
function setLineHight(trumbowyg, size) {
|
||||
trumbowyg.$ed.focus();
|
||||
trumbowyg.saveRange();
|
||||
var parent = trumbowyg.range.startContainer.parentElement;
|
||||
var text = trumbowyg.getRangeText();
|
||||
if ($(parent).html() === text) {
|
||||
$(parent).css('line-height', size);
|
||||
} else {
|
||||
trumbowyg.range.deleteContents();
|
||||
var html = '<span style="line-height: ' + size + ';">' + text + '</span>';
|
||||
var node = $(html)[0];
|
||||
trumbowyg.range.insertNode(node);
|
||||
}
|
||||
trumbowyg.syncCode();
|
||||
trumbowyg.$c.trigger('tbwchange');
|
||||
|
||||
}
|
||||
|
||||
})(jQuery);
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
(function ($) {
|
||||
'use strict';
|
||||
|
||||
$.extend(true, $.trumbowyg, {
|
||||
langs: {
|
||||
// jshint camelcase:false
|
||||
en: {
|
||||
fontFamily: 'Font'
|
||||
},
|
||||
da: {
|
||||
fontFamily: 'Skrifttype'
|
||||
},
|
||||
fr: {
|
||||
fontFamily: 'Police'
|
||||
},
|
||||
de: {
|
||||
fontFamily: 'Schriftart'
|
||||
},
|
||||
nl: {
|
||||
fontFamily: 'Lettertype'
|
||||
},
|
||||
tr: {
|
||||
fontFamily: 'Yazı Tipi'
|
||||
},
|
||||
zh_tw: {
|
||||
fontFamily: '字體',
|
||||
},
|
||||
pt_br: {
|
||||
fontFamily: 'Fonte',
|
||||
}
|
||||
}
|
||||
});
|
||||
// jshint camelcase:true
|
||||
|
||||
var defaultOptions = {
|
||||
fontList: [
|
||||
{name: 'Arial', family: 'Arial, Helvetica, sans-serif'},
|
||||
{name: 'Arial Black', family: '\'Arial Black\', Gadget, sans-serif'},
|
||||
{name: 'Comic Sans', family: '\'Comic Sans MS\', Textile, cursive, sans-serif'},
|
||||
{name: 'Courier New', family: '\'Courier New\', Courier, monospace'},
|
||||
{name: 'Georgia', family: 'Georgia, serif'},
|
||||
{name: 'Impact', family: 'Impact, Charcoal, sans-serif'},
|
||||
{name: 'Lucida Console', family: '\'Lucida Console\', Monaco, monospace'},
|
||||
{name: 'Lucida Sans', family: '\'Lucida Sans Uncide\', \'Lucida Grande\', sans-serif'},
|
||||
{name: 'Palatino', family: '\'Palatino Linotype\', \'Book Antiqua\', Palatino, serif'},
|
||||
{name: 'Tahoma', family: 'Tahoma, Geneva, sans-serif'},
|
||||
{name: 'Times New Roman', family: '\'Times New Roman\', Times, serif'},
|
||||
{name: 'Trebuchet', family: '\'Trebuchet MS\', Helvetica, sans-serif'},
|
||||
{name: 'Verdana', family: 'Verdana, Geneva, sans-serif'}
|
||||
]
|
||||
};
|
||||
|
||||
// Add dropdown with web safe fonts
|
||||
$.extend(true, $.trumbowyg, {
|
||||
plugins: {
|
||||
fontfamily: {
|
||||
init: function (trumbowyg) {
|
||||
trumbowyg.o.plugins.fontfamily = trumbowyg.o.plugins.fontfamily || defaultOptions;
|
||||
trumbowyg.addBtnDef('fontfamily', {
|
||||
dropdown: buildDropdown(trumbowyg),
|
||||
hasIcon: false,
|
||||
text: trumbowyg.lang.fontFamily
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function buildDropdown(trumbowyg) {
|
||||
var dropdown = [];
|
||||
|
||||
$.each(trumbowyg.o.plugins.fontfamily.fontList, function (index, font) {
|
||||
trumbowyg.addBtnDef('fontfamily_' + index, {
|
||||
title: '<span style="font-family: ' + font.family + ';">' + font.name + '</span>',
|
||||
hasIcon: false,
|
||||
fn: function () {
|
||||
trumbowyg.execCmd('fontName', font.family, true);
|
||||
}
|
||||
});
|
||||
dropdown.push('fontfamily_' + index);
|
||||
});
|
||||
|
||||
return dropdown;
|
||||
}
|
||||
})(jQuery);
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user