1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192 |
- /**
- * Copyright (c) Tiny Technologies, Inc. All rights reserved.
- * Licensed under the LGPL or a commercial license.
- * For LGPL see License.txt in the project root for license information.
- * For commercial licenses see https://www.tiny.cloud/
- *
- * Version: 5.2.0 (2020-02-13)
- */
- (function (domGlobals) {
- 'use strict';
- var Cell = function (initial) {
- var value = initial;
- var get = function () {
- return value;
- };
- var set = function (v) {
- value = v;
- };
- var clone = function () {
- return Cell(get());
- };
- return {
- get: get,
- set: set,
- clone: clone
- };
- };
- var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
- var get = function (fullscreenState) {
- return {
- isFullscreen: function () {
- return fullscreenState.get() !== null;
- }
- };
- };
- var Api = { get: get };
- var noop = function () {
- };
- var compose = function (fa, fb) {
- return function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- return fa(fb.apply(null, args));
- };
- };
- var constant = function (value) {
- return function () {
- return value;
- };
- };
- var never = constant(false);
- var always = constant(true);
- var none = function () {
- return NONE;
- };
- var NONE = function () {
- var eq = function (o) {
- return o.isNone();
- };
- var call = function (thunk) {
- return thunk();
- };
- var id = function (n) {
- return n;
- };
- var me = {
- fold: function (n, s) {
- return n();
- },
- is: never,
- isSome: never,
- isNone: always,
- getOr: id,
- getOrThunk: call,
- getOrDie: function (msg) {
- throw new Error(msg || 'error: getOrDie called on none.');
- },
- getOrNull: constant(null),
- getOrUndefined: constant(undefined),
- or: id,
- orThunk: call,
- map: none,
- each: noop,
- bind: none,
- exists: never,
- forall: always,
- filter: none,
- equals: eq,
- equals_: eq,
- toArray: function () {
- return [];
- },
- toString: constant('none()')
- };
- if (Object.freeze) {
- Object.freeze(me);
- }
- return me;
- }();
- var some = function (a) {
- var constant_a = constant(a);
- var self = function () {
- return me;
- };
- var bind = function (f) {
- return f(a);
- };
- var me = {
- fold: function (n, s) {
- return s(a);
- },
- is: function (v) {
- return a === v;
- },
- isSome: always,
- isNone: never,
- getOr: constant_a,
- getOrThunk: constant_a,
- getOrDie: constant_a,
- getOrNull: constant_a,
- getOrUndefined: constant_a,
- or: self,
- orThunk: self,
- map: function (f) {
- return some(f(a));
- },
- each: function (f) {
- f(a);
- },
- bind: bind,
- exists: bind,
- forall: bind,
- filter: function (f) {
- return f(a) ? me : NONE;
- },
- toArray: function () {
- return [a];
- },
- toString: function () {
- return 'some(' + a + ')';
- },
- equals: function (o) {
- return o.is(a);
- },
- equals_: function (o, elementEq) {
- return o.fold(never, function (b) {
- return elementEq(a, b);
- });
- }
- };
- return me;
- };
- var from = function (value) {
- return value === null || value === undefined ? NONE : some(value);
- };
- var Option = {
- some: some,
- none: none,
- from: from
- };
- var revocable = function (doRevoke) {
- var subject = Cell(Option.none());
- var revoke = function () {
- subject.get().each(doRevoke);
- };
- var clear = function () {
- revoke();
- subject.set(Option.none());
- };
- var set = function (s) {
- revoke();
- subject.set(Option.some(s));
- };
- var isSet = function () {
- return subject.get().isSome();
- };
- return {
- clear: clear,
- isSet: isSet,
- set: set
- };
- };
- var unbindable = function () {
- return revocable(function (s) {
- s.unbind();
- });
- };
- var value = function () {
- var subject = Cell(Option.none());
- var clear = function () {
- subject.set(Option.none());
- };
- var set = function (s) {
- subject.set(Option.some(s));
- };
- var on = function (f) {
- subject.get().each(f);
- };
- var isSet = function () {
- return subject.get().isSome();
- };
- return {
- clear: clear,
- set: set,
- isSet: isSet,
- on: on
- };
- };
- var typeOf = function (x) {
- if (x === null) {
- return 'null';
- }
- var t = typeof x;
- if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
- return 'array';
- }
- if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
- return 'string';
- }
- return t;
- };
- var isType = function (type) {
- return function (value) {
- return typeOf(value) === type;
- };
- };
- var isString = isType('string');
- var isArray = isType('array');
- var isBoolean = isType('boolean');
- var isFunction = isType('function');
- var isNumber = isType('number');
- var nativeSlice = Array.prototype.slice;
- var nativePush = Array.prototype.push;
- var map = function (xs, f) {
- var len = xs.length;
- var r = new Array(len);
- for (var i = 0; i < len; i++) {
- var x = xs[i];
- r[i] = f(x, i);
- }
- return r;
- };
- var each = function (xs, f) {
- for (var i = 0, len = xs.length; i < len; i++) {
- var x = xs[i];
- f(x, i);
- }
- };
- var filter = function (xs, pred) {
- var r = [];
- for (var i = 0, len = xs.length; i < len; i++) {
- var x = xs[i];
- if (pred(x, i)) {
- r.push(x);
- }
- }
- return r;
- };
- var find = function (xs, pred) {
- for (var i = 0, len = xs.length; i < len; i++) {
- var x = xs[i];
- if (pred(x, i)) {
- return Option.some(x);
- }
- }
- return Option.none();
- };
- var flatten = function (xs) {
- var r = [];
- for (var i = 0, len = xs.length; i < len; ++i) {
- if (!isArray(xs[i])) {
- throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
- }
- nativePush.apply(r, xs[i]);
- }
- return r;
- };
- var bind = function (xs, f) {
- return flatten(map(xs, f));
- };
- var from$1 = isFunction(Array.from) ? Array.from : function (x) {
- return nativeSlice.call(x);
- };
- var keys = Object.keys;
- var each$1 = function (obj, f) {
- var props = keys(obj);
- for (var k = 0, len = props.length; k < len; k++) {
- var i = props[k];
- var x = obj[i];
- f(x, i);
- }
- };
- var contains = function (str, substr) {
- return str.indexOf(substr) !== -1;
- };
- var isSupported = function (dom) {
- return dom.style !== undefined && isFunction(dom.style.getPropertyValue);
- };
- var fromHtml = function (html, scope) {
- var doc = scope || domGlobals.document;
- var div = doc.createElement('div');
- div.innerHTML = html;
- if (!div.hasChildNodes() || div.childNodes.length > 1) {
- domGlobals.console.error('HTML does not have a single root node', html);
- throw new Error('HTML must have a single root node');
- }
- return fromDom(div.childNodes[0]);
- };
- var fromTag = function (tag, scope) {
- var doc = scope || domGlobals.document;
- var node = doc.createElement(tag);
- return fromDom(node);
- };
- var fromText = function (text, scope) {
- var doc = scope || domGlobals.document;
- var node = doc.createTextNode(text);
- return fromDom(node);
- };
- var fromDom = function (node) {
- if (node === null || node === undefined) {
- throw new Error('Node cannot be null or undefined');
- }
- return { dom: constant(node) };
- };
- var fromPoint = function (docElm, x, y) {
- var doc = docElm.dom();
- return Option.from(doc.elementFromPoint(x, y)).map(fromDom);
- };
- var Element = {
- fromHtml: fromHtml,
- fromTag: fromTag,
- fromText: fromText,
- fromDom: fromDom,
- fromPoint: fromPoint
- };
- var ATTRIBUTE = domGlobals.Node.ATTRIBUTE_NODE;
- var CDATA_SECTION = domGlobals.Node.CDATA_SECTION_NODE;
- var COMMENT = domGlobals.Node.COMMENT_NODE;
- var DOCUMENT = domGlobals.Node.DOCUMENT_NODE;
- var DOCUMENT_TYPE = domGlobals.Node.DOCUMENT_TYPE_NODE;
- var DOCUMENT_FRAGMENT = domGlobals.Node.DOCUMENT_FRAGMENT_NODE;
- var ELEMENT = domGlobals.Node.ELEMENT_NODE;
- var TEXT = domGlobals.Node.TEXT_NODE;
- var PROCESSING_INSTRUCTION = domGlobals.Node.PROCESSING_INSTRUCTION_NODE;
- var ENTITY_REFERENCE = domGlobals.Node.ENTITY_REFERENCE_NODE;
- var ENTITY = domGlobals.Node.ENTITY_NODE;
- var NOTATION = domGlobals.Node.NOTATION_NODE;
- var Global = typeof domGlobals.window !== 'undefined' ? domGlobals.window : Function('return this;')();
- var type = function (element) {
- return element.dom().nodeType;
- };
- var isType$1 = function (t) {
- return function (element) {
- return type(element) === t;
- };
- };
- var isText = isType$1(TEXT);
- var inBody = function (element) {
- var dom = isText(element) ? element.dom().parentNode : element.dom();
- return dom !== undefined && dom !== null && dom.ownerDocument.body.contains(dom);
- };
- var rawSet = function (dom, key, value) {
- if (isString(value) || isBoolean(value) || isNumber(value)) {
- dom.setAttribute(key, value + '');
- } else {
- domGlobals.console.error('Invalid call to Attr.set. Key ', key, ':: Value ', value, ':: Element ', dom);
- throw new Error('Attribute value was not simple');
- }
- };
- var set = function (element, key, value) {
- rawSet(element.dom(), key, value);
- };
- var get$1 = function (element, key) {
- var v = element.dom().getAttribute(key);
- return v === null ? undefined : v;
- };
- var remove = function (element, key) {
- element.dom().removeAttribute(key);
- };
- var internalSet = function (dom, property, value) {
- if (!isString(value)) {
- domGlobals.console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom);
- throw new Error('CSS value must be a string: ' + value);
- }
- if (isSupported(dom)) {
- dom.style.setProperty(property, value);
- }
- };
- var setAll = function (element, css) {
- var dom = element.dom();
- each$1(css, function (v, k) {
- internalSet(dom, k, v);
- });
- };
- var get$2 = function (element, property) {
- var dom = element.dom();
- var styles = domGlobals.window.getComputedStyle(dom);
- var r = styles.getPropertyValue(property);
- var v = r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r;
- return v === null ? undefined : v;
- };
- var getUnsafeProperty = function (dom, property) {
- return isSupported(dom) ? dom.style.getPropertyValue(property) : '';
- };
- var mkEvent = function (target, x, y, stop, prevent, kill, raw) {
- return {
- target: constant(target),
- x: constant(x),
- y: constant(y),
- stop: stop,
- prevent: prevent,
- kill: kill,
- raw: constant(raw)
- };
- };
- var fromRawEvent = function (rawEvent) {
- var target = Element.fromDom(rawEvent.target);
- var stop = function () {
- rawEvent.stopPropagation();
- };
- var prevent = function () {
- rawEvent.preventDefault();
- };
- var kill = compose(prevent, stop);
- return mkEvent(target, rawEvent.clientX, rawEvent.clientY, stop, prevent, kill, rawEvent);
- };
- var firstMatch = function (regexes, s) {
- for (var i = 0; i < regexes.length; i++) {
- var x = regexes[i];
- if (x.test(s)) {
- return x;
- }
- }
- return undefined;
- };
- var find$1 = function (regexes, agent) {
- var r = firstMatch(regexes, agent);
- if (!r) {
- return {
- major: 0,
- minor: 0
- };
- }
- var group = function (i) {
- return Number(agent.replace(r, '$' + i));
- };
- return nu(group(1), group(2));
- };
- var detect = function (versionRegexes, agent) {
- var cleanedAgent = String(agent).toLowerCase();
- if (versionRegexes.length === 0) {
- return unknown();
- }
- return find$1(versionRegexes, cleanedAgent);
- };
- var unknown = function () {
- return nu(0, 0);
- };
- var nu = function (major, minor) {
- return {
- major: major,
- minor: minor
- };
- };
- var Version = {
- nu: nu,
- detect: detect,
- unknown: unknown
- };
- var edge = 'Edge';
- var chrome = 'Chrome';
- var ie = 'IE';
- var opera = 'Opera';
- var firefox = 'Firefox';
- var safari = 'Safari';
- var isBrowser = function (name, current) {
- return function () {
- return current === name;
- };
- };
- var unknown$1 = function () {
- return nu$1({
- current: undefined,
- version: Version.unknown()
- });
- };
- var nu$1 = function (info) {
- var current = info.current;
- var version = info.version;
- return {
- current: current,
- version: version,
- isEdge: isBrowser(edge, current),
- isChrome: isBrowser(chrome, current),
- isIE: isBrowser(ie, current),
- isOpera: isBrowser(opera, current),
- isFirefox: isBrowser(firefox, current),
- isSafari: isBrowser(safari, current)
- };
- };
- var Browser = {
- unknown: unknown$1,
- nu: nu$1,
- edge: constant(edge),
- chrome: constant(chrome),
- ie: constant(ie),
- opera: constant(opera),
- firefox: constant(firefox),
- safari: constant(safari)
- };
- var windows = 'Windows';
- var ios = 'iOS';
- var android = 'Android';
- var linux = 'Linux';
- var osx = 'OSX';
- var solaris = 'Solaris';
- var freebsd = 'FreeBSD';
- var chromeos = 'ChromeOS';
- var isOS = function (name, current) {
- return function () {
- return current === name;
- };
- };
- var unknown$2 = function () {
- return nu$2({
- current: undefined,
- version: Version.unknown()
- });
- };
- var nu$2 = function (info) {
- var current = info.current;
- var version = info.version;
- return {
- current: current,
- version: version,
- isWindows: isOS(windows, current),
- isiOS: isOS(ios, current),
- isAndroid: isOS(android, current),
- isOSX: isOS(osx, current),
- isLinux: isOS(linux, current),
- isSolaris: isOS(solaris, current),
- isFreeBSD: isOS(freebsd, current),
- isChromeOS: isOS(chromeos, current)
- };
- };
- var OperatingSystem = {
- unknown: unknown$2,
- nu: nu$2,
- windows: constant(windows),
- ios: constant(ios),
- android: constant(android),
- linux: constant(linux),
- osx: constant(osx),
- solaris: constant(solaris),
- freebsd: constant(freebsd),
- chromeos: constant(chromeos)
- };
- var DeviceType = function (os, browser, userAgent, mediaMatch) {
- var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
- var isiPhone = os.isiOS() && !isiPad;
- var isMobile = os.isiOS() || os.isAndroid();
- var isTouch = isMobile || mediaMatch('(pointer:coarse)');
- var isTablet = isiPad || !isiPhone && isMobile && mediaMatch('(min-device-width:768px)');
- var isPhone = isiPhone || isMobile && !isTablet;
- var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
- var isDesktop = !isPhone && !isTablet && !iOSwebview;
- return {
- isiPad: constant(isiPad),
- isiPhone: constant(isiPhone),
- isTablet: constant(isTablet),
- isPhone: constant(isPhone),
- isTouch: constant(isTouch),
- isAndroid: os.isAndroid,
- isiOS: os.isiOS,
- isWebView: constant(iOSwebview),
- isDesktop: constant(isDesktop)
- };
- };
- var detect$1 = function (candidates, userAgent) {
- var agent = String(userAgent).toLowerCase();
- return find(candidates, function (candidate) {
- return candidate.search(agent);
- });
- };
- var detectBrowser = function (browsers, userAgent) {
- return detect$1(browsers, userAgent).map(function (browser) {
- var version = Version.detect(browser.versionRegexes, userAgent);
- return {
- current: browser.name,
- version: version
- };
- });
- };
- var detectOs = function (oses, userAgent) {
- return detect$1(oses, userAgent).map(function (os) {
- var version = Version.detect(os.versionRegexes, userAgent);
- return {
- current: os.name,
- version: version
- };
- });
- };
- var UaString = {
- detectBrowser: detectBrowser,
- detectOs: detectOs
- };
- var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
- var checkContains = function (target) {
- return function (uastring) {
- return contains(uastring, target);
- };
- };
- var browsers = [
- {
- name: 'Edge',
- versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
- search: function (uastring) {
- return contains(uastring, 'edge/') && contains(uastring, 'chrome') && contains(uastring, 'safari') && contains(uastring, 'applewebkit');
- }
- },
- {
- name: 'Chrome',
- versionRegexes: [
- /.*?chrome\/([0-9]+)\.([0-9]+).*/,
- normalVersionRegex
- ],
- search: function (uastring) {
- return contains(uastring, 'chrome') && !contains(uastring, 'chromeframe');
- }
- },
- {
- name: 'IE',
- versionRegexes: [
- /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
- /.*?rv:([0-9]+)\.([0-9]+).*/
- ],
- search: function (uastring) {
- return contains(uastring, 'msie') || contains(uastring, 'trident');
- }
- },
- {
- name: 'Opera',
- versionRegexes: [
- normalVersionRegex,
- /.*?opera\/([0-9]+)\.([0-9]+).*/
- ],
- search: checkContains('opera')
- },
- {
- name: 'Firefox',
- versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
- search: checkContains('firefox')
- },
- {
- name: 'Safari',
- versionRegexes: [
- normalVersionRegex,
- /.*?cpu os ([0-9]+)_([0-9]+).*/
- ],
- search: function (uastring) {
- return (contains(uastring, 'safari') || contains(uastring, 'mobile/')) && contains(uastring, 'applewebkit');
- }
- }
- ];
- var oses = [
- {
- name: 'Windows',
- search: checkContains('win'),
- versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
- },
- {
- name: 'iOS',
- search: function (uastring) {
- return contains(uastring, 'iphone') || contains(uastring, 'ipad');
- },
- versionRegexes: [
- /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
- /.*cpu os ([0-9]+)_([0-9]+).*/,
- /.*cpu iphone os ([0-9]+)_([0-9]+).*/
- ]
- },
- {
- name: 'Android',
- search: checkContains('android'),
- versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
- },
- {
- name: 'OSX',
- search: checkContains('mac os x'),
- versionRegexes: [/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]
- },
- {
- name: 'Linux',
- search: checkContains('linux'),
- versionRegexes: []
- },
- {
- name: 'Solaris',
- search: checkContains('sunos'),
- versionRegexes: []
- },
- {
- name: 'FreeBSD',
- search: checkContains('freebsd'),
- versionRegexes: []
- },
- {
- name: 'ChromeOS',
- search: checkContains('cros'),
- versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/]
- }
- ];
- var PlatformInfo = {
- browsers: constant(browsers),
- oses: constant(oses)
- };
- var detect$2 = function (userAgent, mediaMatch) {
- var browsers = PlatformInfo.browsers();
- var oses = PlatformInfo.oses();
- var browser = UaString.detectBrowser(browsers, userAgent).fold(Browser.unknown, Browser.nu);
- var os = UaString.detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
- var deviceType = DeviceType(os, browser, userAgent, mediaMatch);
- return {
- browser: browser,
- os: os,
- deviceType: deviceType
- };
- };
- var PlatformDetection = { detect: detect$2 };
- var mediaMatch = function (query) {
- return domGlobals.window.matchMedia(query).matches;
- };
- var platform = Cell(PlatformDetection.detect(domGlobals.navigator.userAgent, mediaMatch));
- var detect$3 = function () {
- return platform.get();
- };
- var Immutable = function () {
- var fields = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- fields[_i] = arguments[_i];
- }
- return function () {
- var values = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- values[_i] = arguments[_i];
- }
- if (fields.length !== values.length) {
- throw new Error('Wrong number of arguments to struct. Expected "[' + fields.length + ']", got ' + values.length + ' arguments');
- }
- var struct = {};
- each(fields, function (name, i) {
- struct[name] = constant(values[i]);
- });
- return struct;
- };
- };
- var compareDocumentPosition = function (a, b, match) {
- return (a.compareDocumentPosition(b) & match) !== 0;
- };
- var documentPositionPreceding = function (a, b) {
- return compareDocumentPosition(a, b, domGlobals.Node.DOCUMENT_POSITION_PRECEDING);
- };
- var documentPositionContainedBy = function (a, b) {
- return compareDocumentPosition(a, b, domGlobals.Node.DOCUMENT_POSITION_CONTAINED_BY);
- };
- var Node = {
- documentPositionPreceding: documentPositionPreceding,
- documentPositionContainedBy: documentPositionContainedBy
- };
- var ELEMENT$1 = ELEMENT;
- var DOCUMENT$1 = DOCUMENT;
- var is = function (element, selector) {
- var dom = element.dom();
- if (dom.nodeType !== ELEMENT$1) {
- return false;
- } else {
- var elem = dom;
- if (elem.matches !== undefined) {
- return elem.matches(selector);
- } else if (elem.msMatchesSelector !== undefined) {
- return elem.msMatchesSelector(selector);
- } else if (elem.webkitMatchesSelector !== undefined) {
- return elem.webkitMatchesSelector(selector);
- } else if (elem.mozMatchesSelector !== undefined) {
- return elem.mozMatchesSelector(selector);
- } else {
- throw new Error('Browser lacks native selectors');
- }
- }
- };
- var bypassSelector = function (dom) {
- return dom.nodeType !== ELEMENT$1 && dom.nodeType !== DOCUMENT$1 || dom.childElementCount === 0;
- };
- var all = function (selector, scope) {
- var base = scope === undefined ? domGlobals.document : scope.dom();
- return bypassSelector(base) ? [] : map(base.querySelectorAll(selector), Element.fromDom);
- };
- var eq = function (e1, e2) {
- return e1.dom() === e2.dom();
- };
- var regularContains = function (e1, e2) {
- var d1 = e1.dom();
- var d2 = e2.dom();
- return d1 === d2 ? false : d1.contains(d2);
- };
- var ieContains = function (e1, e2) {
- return Node.documentPositionContainedBy(e1.dom(), e2.dom());
- };
- var browser = detect$3().browser;
- var contains$1 = browser.isIE() ? ieContains : regularContains;
- var parent = function (element) {
- return Option.from(element.dom().parentNode).map(Element.fromDom);
- };
- var parents = function (element, isRoot) {
- var stop = isFunction(isRoot) ? isRoot : never;
- var dom = element.dom();
- var ret = [];
- while (dom.parentNode !== null && dom.parentNode !== undefined) {
- var rawParent = dom.parentNode;
- var p = Element.fromDom(rawParent);
- ret.push(p);
- if (stop(p) === true) {
- break;
- } else {
- dom = rawParent;
- }
- }
- return ret;
- };
- var siblings = function (element) {
- var filterSelf = function (elements) {
- return filter(elements, function (x) {
- return !eq(element, x);
- });
- };
- return parent(element).map(children).map(filterSelf).getOr([]);
- };
- var children = function (element) {
- return map(element.dom().childNodes, Element.fromDom);
- };
- var spot = Immutable('element', 'offset');
- var r = function (left, top) {
- var translate = function (x, y) {
- return r(left + x, top + y);
- };
- return {
- left: constant(left),
- top: constant(top),
- translate: translate
- };
- };
- var Position = r;
- var isSafari = detect$3().browser.isSafari();
- var get$3 = function (_DOC) {
- var doc = _DOC !== undefined ? _DOC.dom() : domGlobals.document;
- var x = doc.body.scrollLeft || doc.documentElement.scrollLeft;
- var y = doc.body.scrollTop || doc.documentElement.scrollTop;
- return Position(x, y);
- };
- var get$4 = function (_win) {
- var win = _win === undefined ? domGlobals.window : _win;
- return Option.from(win['visualViewport']);
- };
- var bounds = function (x, y, width, height) {
- return {
- x: constant(x),
- y: constant(y),
- width: constant(width),
- height: constant(height),
- right: constant(x + width),
- bottom: constant(y + height)
- };
- };
- var getBounds = function (_win) {
- var win = _win === undefined ? domGlobals.window : _win;
- var doc = win.document;
- var scroll = get$3(Element.fromDom(doc));
- return get$4(win).fold(function () {
- var html = win.document.documentElement;
- var width = html.clientWidth;
- var height = html.clientHeight;
- return bounds(scroll.left(), scroll.top(), width, height);
- }, function (visualViewport) {
- return bounds(Math.max(visualViewport.pageLeft, scroll.left()), Math.max(visualViewport.pageTop, scroll.top()), visualViewport.width, visualViewport.height);
- });
- };
- var bind$1 = function (name, callback, _win) {
- return get$4(_win).map(function (visualViewport) {
- var handler = function (e) {
- return fromRawEvent(e);
- };
- visualViewport.addEventListener(name, handler);
- return {
- unbind: function () {
- return visualViewport.removeEventListener(name, handler);
- }
- };
- }).getOrThunk(function () {
- return { unbind: noop };
- });
- };
- var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
- var global$2 = tinymce.util.Tools.resolve('tinymce.Env');
- var global$3 = tinymce.util.Tools.resolve('tinymce.util.Delay');
- var fireFullscreenStateChanged = function (editor, state) {
- editor.fire('FullscreenStateChanged', { state: state });
- };
- var Events = { fireFullscreenStateChanged: fireFullscreenStateChanged };
- var ancestors = function (scope, predicate, isRoot) {
- return filter(parents(scope, isRoot), predicate);
- };
- var siblings$1 = function (scope, predicate) {
- return filter(siblings(scope), predicate);
- };
- var all$1 = function (selector) {
- return all(selector);
- };
- var ancestors$1 = function (scope, selector, isRoot) {
- return ancestors(scope, function (e) {
- return is(e, selector);
- }, isRoot);
- };
- var siblings$2 = function (scope, selector) {
- return siblings$1(scope, function (e) {
- return is(e, selector);
- });
- };
- var attr = 'data-ephox-mobile-fullscreen-style';
- var siblingStyles = 'display:none!important;';
- var ancestorPosition = 'position:absolute!important;';
- var ancestorStyles = 'top:0!important;left:0!important;margin:0!important;padding:0!important;width:100%!important;height:100%!important;overflow:visible!important;';
- var bgFallback = 'background-color:rgb(255,255,255)!important;';
- var isAndroid = global$2.os.isAndroid();
- var matchColor = function (editorBody) {
- var color = get$2(editorBody, 'background-color');
- return color !== undefined && color !== '' ? 'background-color:' + color + '!important' : bgFallback;
- };
- var clobberStyles = function (dom, container, editorBody) {
- var gatherSibilings = function (element) {
- return siblings$2(element, '*:not(.tox-silver-sink)');
- };
- var clobber = function (clobberStyle) {
- return function (element) {
- var styles = get$1(element, 'style');
- var backup = styles === undefined ? 'no-styles' : styles.trim();
- if (backup === clobberStyle) {
- return;
- } else {
- set(element, attr, backup);
- setAll(element, dom.parseStyle(clobberStyle));
- }
- };
- };
- var ancestors = ancestors$1(container, '*');
- var siblings = bind(ancestors, gatherSibilings);
- var bgColor = matchColor(editorBody);
- each(siblings, clobber(siblingStyles));
- each(ancestors, clobber(ancestorPosition + ancestorStyles + bgColor));
- var containerStyles = isAndroid === true ? '' : ancestorPosition;
- clobber(containerStyles + ancestorStyles + bgColor)(container);
- };
- var restoreStyles = function (dom) {
- var clobberedEls = all$1('[' + attr + ']');
- each(clobberedEls, function (element) {
- var restore = get$1(element, attr);
- if (restore !== 'no-styles') {
- setAll(element, dom.parseStyle(restore));
- } else {
- remove(element, 'style');
- }
- remove(element, attr);
- });
- };
- var Thor = {
- clobberStyles: clobberStyles,
- restoreStyles: restoreStyles
- };
- var DOM = global$1.DOM;
- var getScrollPos = function () {
- var vp = getBounds(domGlobals.window);
- return {
- x: vp.x(),
- y: vp.y()
- };
- };
- var setScrollPos = function (pos) {
- domGlobals.window.scrollTo(pos.x, pos.y);
- };
- var viewportUpdate = get$4().fold(function () {
- return {
- bind: noop,
- unbind: noop
- };
- }, function (visualViewport) {
- var editorContainer = value();
- var resizeBinder = unbindable();
- var scrollBinder = unbindable();
- var refreshScroll = function () {
- domGlobals.document.body.scrollTop = 0;
- domGlobals.document.documentElement.scrollTop = 0;
- };
- var refreshVisualViewport = function () {
- domGlobals.window.requestAnimationFrame(function () {
- editorContainer.on(function (container) {
- return setAll(container, {
- top: visualViewport.offsetTop + 'px',
- left: visualViewport.offsetLeft + 'px',
- height: visualViewport.height + 'px',
- width: visualViewport.width + 'px'
- });
- });
- });
- };
- var update = global$3.throttle(function () {
- refreshScroll();
- refreshVisualViewport();
- }, 50);
- var bind = function (element) {
- editorContainer.set(element);
- update();
- resizeBinder.set(bind$1('resize'));
- scrollBinder.set(bind$1('scroll'));
- };
- var unbind = function () {
- editorContainer.on(function () {
- resizeBinder.clear();
- scrollBinder.clear();
- });
- editorContainer.clear();
- };
- return {
- bind: bind,
- unbind: unbind
- };
- });
- var toggleFullscreen = function (editor, fullscreenState) {
- var body = domGlobals.document.body;
- var documentElement = domGlobals.document.documentElement;
- var editorContainerStyle;
- var editorContainer, iframe, iframeStyle;
- editorContainer = editor.getContainer();
- var editorContainerS = Element.fromDom(editorContainer);
- var fullscreenInfo = fullscreenState.get();
- var editorBody = Element.fromDom(editor.getBody());
- var isTouch = global$2.deviceType.isTouch();
- editorContainerStyle = editorContainer.style;
- iframe = editor.getContentAreaContainer().firstChild;
- iframeStyle = iframe.style;
- if (!fullscreenInfo) {
- var newFullScreenInfo = {
- scrollPos: getScrollPos(),
- containerWidth: editorContainerStyle.width,
- containerHeight: editorContainerStyle.height,
- containerTop: editorContainerStyle.top,
- containerLeft: editorContainerStyle.left,
- iframeWidth: iframeStyle.width,
- iframeHeight: iframeStyle.height
- };
- if (isTouch) {
- Thor.clobberStyles(editor.dom, editorContainerS, editorBody);
- }
- iframeStyle.width = iframeStyle.height = '100%';
- editorContainerStyle.width = editorContainerStyle.height = '';
- DOM.addClass(body, 'tox-fullscreen');
- DOM.addClass(documentElement, 'tox-fullscreen');
- DOM.addClass(editorContainer, 'tox-fullscreen');
- viewportUpdate.bind(editorContainerS);
- editor.on('remove', viewportUpdate.unbind);
- fullscreenState.set(newFullScreenInfo);
- Events.fireFullscreenStateChanged(editor, true);
- } else {
- iframeStyle.width = fullscreenInfo.iframeWidth;
- iframeStyle.height = fullscreenInfo.iframeHeight;
- editorContainerStyle.width = fullscreenInfo.containerWidth;
- editorContainerStyle.height = fullscreenInfo.containerHeight;
- editorContainerStyle.top = fullscreenInfo.containerTop;
- editorContainerStyle.left = fullscreenInfo.containerLeft;
- if (isTouch) {
- Thor.restoreStyles(editor.dom);
- }
- DOM.removeClass(body, 'tox-fullscreen');
- DOM.removeClass(documentElement, 'tox-fullscreen');
- DOM.removeClass(editorContainer, 'tox-fullscreen');
- setScrollPos(fullscreenInfo.scrollPos);
- fullscreenState.set(null);
- Events.fireFullscreenStateChanged(editor, false);
- viewportUpdate.unbind();
- editor.off('remove', viewportUpdate.unbind);
- }
- };
- var Actions = { toggleFullscreen: toggleFullscreen };
- var register = function (editor, fullscreenState) {
- editor.addCommand('mceFullScreen', function () {
- Actions.toggleFullscreen(editor, fullscreenState);
- });
- };
- var Commands = { register: register };
- var makeSetupHandler = function (editor, fullscreenState) {
- return function (api) {
- api.setActive(fullscreenState.get() !== null);
- var editorEventCallback = function (e) {
- return api.setActive(e.state);
- };
- editor.on('FullscreenStateChanged', editorEventCallback);
- return function () {
- return editor.off('FullscreenStateChanged', editorEventCallback);
- };
- };
- };
- var register$1 = function (editor, fullscreenState) {
- editor.ui.registry.addToggleMenuItem('fullscreen', {
- text: 'Fullscreen',
- shortcut: 'Meta+Shift+F',
- onAction: function () {
- return editor.execCommand('mceFullScreen');
- },
- onSetup: makeSetupHandler(editor, fullscreenState)
- });
- editor.ui.registry.addToggleButton('fullscreen', {
- tooltip: 'Fullscreen',
- icon: 'fullscreen',
- onAction: function () {
- return editor.execCommand('mceFullScreen');
- },
- onSetup: makeSetupHandler(editor, fullscreenState)
- });
- };
- var Buttons = { register: register$1 };
- function Plugin () {
- global.add('fullscreen', function (editor) {
- var fullscreenState = Cell(null);
- if (editor.settings.inline) {
- return Api.get(fullscreenState);
- }
- Commands.register(editor, fullscreenState);
- Buttons.register(editor, fullscreenState);
- editor.addShortcut('Meta+Shift+F', '', 'mceFullScreen');
- return Api.get(fullscreenState);
- });
- }
- Plugin();
- }(window));
|