theme.js 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679
  1. (function () {
  2. var defs = {}; // id -> {dependencies, definition, instance (possibly undefined)}
  3. // Used when there is no 'main' module.
  4. // The name is probably (hopefully) unique so minification removes for releases.
  5. var register_3795 = function (id) {
  6. var module = dem(id);
  7. var fragments = id.split('.');
  8. var target = Function('return this;')();
  9. for (var i = 0; i < fragments.length - 1; ++i) {
  10. if (target[fragments[i]] === undefined)
  11. target[fragments[i]] = {};
  12. target = target[fragments[i]];
  13. }
  14. target[fragments[fragments.length - 1]] = module;
  15. };
  16. var instantiate = function (id) {
  17. var actual = defs[id];
  18. var dependencies = actual.deps;
  19. var definition = actual.defn;
  20. var len = dependencies.length;
  21. var instances = new Array(len);
  22. for (var i = 0; i < len; ++i)
  23. instances[i] = dem(dependencies[i]);
  24. var defResult = definition.apply(null, instances);
  25. if (defResult === undefined)
  26. throw 'module [' + id + '] returned undefined';
  27. actual.instance = defResult;
  28. };
  29. var def = function (id, dependencies, definition) {
  30. if (typeof id !== 'string')
  31. throw 'module id must be a string';
  32. else if (dependencies === undefined)
  33. throw 'no dependencies for ' + id;
  34. else if (definition === undefined)
  35. throw 'no definition function for ' + id;
  36. defs[id] = {
  37. deps: dependencies,
  38. defn: definition,
  39. instance: undefined
  40. };
  41. };
  42. var dem = function (id) {
  43. var actual = defs[id];
  44. if (actual === undefined)
  45. throw 'module [' + id + '] was undefined';
  46. else if (actual.instance === undefined)
  47. instantiate(id);
  48. return actual.instance;
  49. };
  50. var req = function (ids, callback) {
  51. var len = ids.length;
  52. var instances = new Array(len);
  53. for (var i = 0; i < len; ++i)
  54. instances.push(dem(ids[i]));
  55. callback.apply(null, callback);
  56. };
  57. var ephox = {};
  58. ephox.bolt = {
  59. module: {
  60. api: {
  61. define: def,
  62. require: req,
  63. demand: dem
  64. }
  65. }
  66. };
  67. var define = def;
  68. var require = req;
  69. var demand = dem;
  70. // this helps with minificiation when using a lot of global references
  71. var defineGlobal = function (id, ref) {
  72. define(id, [], function () { return ref; });
  73. };
  74. /*jsc
  75. ["tinymce/inlite/Theme","global!tinymce.ThemeManager","global!tinymce.util.Delay","tinymce/inlite/ui/Panel","tinymce/inlite/ui/Buttons","tinymce/inlite/core/SkinLoader","tinymce/inlite/core/SelectionMatcher","tinymce/inlite/core/ElementMatcher","tinymce/inlite/core/Matcher","tinymce/inlite/alien/Arr","tinymce/inlite/core/PredicateId","global!tinymce.util.Tools","global!tinymce.ui.Factory","global!tinymce.DOM","tinymce/inlite/ui/Toolbar","tinymce/inlite/ui/Forms","tinymce/inlite/core/Measure","tinymce/inlite/core/Layout","tinymce/inlite/file/Conversions","tinymce/inlite/file/Picker","tinymce/inlite/core/Actions","global!tinymce.EditorManager","global!tinymce.util.Promise","tinymce/inlite/alien/Uuid","tinymce/inlite/alien/Unlink","tinymce/inlite/core/UrlType","global!tinymce.geom.Rect","tinymce/inlite/core/Convert","tinymce/inlite/alien/Bookmark","global!tinymce.dom.TreeWalker","global!tinymce.dom.RangeUtils"]
  76. jsc*/
  77. defineGlobal("global!tinymce.ThemeManager", tinymce.ThemeManager);
  78. defineGlobal("global!tinymce.util.Delay", tinymce.util.Delay);
  79. defineGlobal("global!tinymce.util.Tools", tinymce.util.Tools);
  80. defineGlobal("global!tinymce.ui.Factory", tinymce.ui.Factory);
  81. defineGlobal("global!tinymce.DOM", tinymce.DOM);
  82. /**
  83. * Toolbar.js
  84. *
  85. * Released under LGPL License.
  86. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  87. *
  88. * License: http://www.tinymce.com/license
  89. * Contributing: http://www.tinymce.com/contributing
  90. */
  91. define('tinymce/inlite/ui/Toolbar', [
  92. 'global!tinymce.util.Tools',
  93. 'global!tinymce.ui.Factory'
  94. ], function (Tools, Factory) {
  95. var setActiveItem = function (item, name) {
  96. return function(state, args) {
  97. var nodeName, i = args.parents.length;
  98. while (i--) {
  99. nodeName = args.parents[i].nodeName;
  100. if (nodeName == 'OL' || nodeName == 'UL') {
  101. break;
  102. }
  103. }
  104. item.active(state && nodeName == name);
  105. };
  106. };
  107. var getSelectorStateResult = function (itemName, item) {
  108. var result = function (selector, handler) {
  109. return {
  110. selector: selector,
  111. handler: handler
  112. };
  113. };
  114. var activeHandler = function(state) {
  115. item.active(state);
  116. };
  117. var disabledHandler = function (state) {
  118. item.disabled(state);
  119. };
  120. if (itemName == 'bullist') {
  121. return result('ul > li', setActiveItem(item, 'UL'));
  122. }
  123. if (itemName == 'numlist') {
  124. return result('ol > li', setActiveItem(item, 'OL'));
  125. }
  126. if (item.settings.stateSelector) {
  127. return result(item.settings.stateSelector, activeHandler);
  128. }
  129. if (item.settings.disabledStateSelector) {
  130. return result(item.settings.disabledStateSelector, disabledHandler);
  131. }
  132. return null;
  133. };
  134. var bindSelectorChanged = function (editor, itemName, item) {
  135. return function () {
  136. var result = getSelectorStateResult(itemName, item);
  137. if (result !== null) {
  138. editor.selection.selectorChanged(result.selector, result.handler);
  139. }
  140. };
  141. };
  142. var create = function (editor, name, items) {
  143. var toolbarItems = [], buttonGroup;
  144. if (!items) {
  145. return;
  146. }
  147. Tools.each(items.split(/[ ,]/), function(item) {
  148. var itemName;
  149. if (item == '|') {
  150. buttonGroup = null;
  151. } else {
  152. if (Factory.has(item)) {
  153. item = {type: item};
  154. toolbarItems.push(item);
  155. buttonGroup = null;
  156. } else {
  157. if (!buttonGroup) {
  158. buttonGroup = {type: 'buttongroup', items: []};
  159. toolbarItems.push(buttonGroup);
  160. }
  161. if (editor.buttons[item]) {
  162. itemName = item;
  163. item = editor.buttons[itemName];
  164. if (typeof item == 'function') {
  165. item = item();
  166. }
  167. item.type = item.type || 'button';
  168. item = Factory.create(item);
  169. item.on('postRender', bindSelectorChanged(editor, itemName, item));
  170. buttonGroup.items.push(item);
  171. }
  172. }
  173. }
  174. });
  175. return Factory.create({
  176. type: 'toolbar',
  177. layout: 'flow',
  178. name: name,
  179. items: toolbarItems
  180. });
  181. };
  182. return {
  183. create: create
  184. };
  185. });
  186. defineGlobal("global!tinymce.util.Promise", tinymce.util.Promise);
  187. /**
  188. * Uuid.js
  189. *
  190. * Released under LGPL License.
  191. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  192. *
  193. * License: http://www.tinymce.com/license
  194. * Contributing: http://www.tinymce.com/contributing
  195. */
  196. /**
  197. * Generates unique ids this is the same as in core but since
  198. * it's not exposed as a global we can't access it.
  199. */
  200. define("tinymce/inlite/alien/Uuid", [
  201. ], function() {
  202. var count = 0;
  203. var seed = function () {
  204. var rnd = function () {
  205. return Math.round(Math.random() * 0xFFFFFFFF).toString(36);
  206. };
  207. return 's' + Date.now().toString(36) + rnd() + rnd() + rnd();
  208. };
  209. var uuid = function (prefix) {
  210. return prefix + (count++) + seed();
  211. };
  212. return {
  213. uuid: uuid
  214. };
  215. });
  216. /**
  217. * Bookmark.js
  218. *
  219. * Released under LGPL License.
  220. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  221. *
  222. * License: http://www.tinymce.com/license
  223. * Contributing: http://www.tinymce.com/contributing
  224. */
  225. define('tinymce/inlite/alien/Bookmark', [
  226. ], function () {
  227. /**
  228. * Returns a range bookmark. This will convert indexed bookmarks into temporary span elements with
  229. * index 0 so that they can be restored properly after the DOM has been modified. Text bookmarks will not have spans
  230. * added to them since they can be restored after a dom operation.
  231. *
  232. * So this: <p><b>|</b><b>|</b></p>
  233. * becomes: <p><b><span data-mce-type="bookmark">|</span></b><b data-mce-type="bookmark">|</span></b></p>
  234. *
  235. * @param {DOMRange} rng DOM Range to get bookmark on.
  236. * @return {Object} Bookmark object.
  237. */
  238. var create = function (dom, rng) {
  239. var bookmark = {};
  240. function setupEndPoint(start) {
  241. var offsetNode, container, offset;
  242. container = rng[start ? 'startContainer' : 'endContainer'];
  243. offset = rng[start ? 'startOffset' : 'endOffset'];
  244. if (container.nodeType == 1) {
  245. offsetNode = dom.create('span', {'data-mce-type': 'bookmark'});
  246. if (container.hasChildNodes()) {
  247. offset = Math.min(offset, container.childNodes.length - 1);
  248. if (start) {
  249. container.insertBefore(offsetNode, container.childNodes[offset]);
  250. } else {
  251. dom.insertAfter(offsetNode, container.childNodes[offset]);
  252. }
  253. } else {
  254. container.appendChild(offsetNode);
  255. }
  256. container = offsetNode;
  257. offset = 0;
  258. }
  259. bookmark[start ? 'startContainer' : 'endContainer'] = container;
  260. bookmark[start ? 'startOffset' : 'endOffset'] = offset;
  261. }
  262. setupEndPoint(true);
  263. if (!rng.collapsed) {
  264. setupEndPoint();
  265. }
  266. return bookmark;
  267. };
  268. /**
  269. * Moves the selection to the current bookmark and removes any selection container wrappers.
  270. *
  271. * @param {Object} bookmark Bookmark object to move selection to.
  272. */
  273. var resolve = function (dom, bookmark) {
  274. function restoreEndPoint(start) {
  275. var container, offset, node;
  276. function nodeIndex(container) {
  277. var node = container.parentNode.firstChild, idx = 0;
  278. while (node) {
  279. if (node == container) {
  280. return idx;
  281. }
  282. // Skip data-mce-type=bookmark nodes
  283. if (node.nodeType != 1 || node.getAttribute('data-mce-type') != 'bookmark') {
  284. idx++;
  285. }
  286. node = node.nextSibling;
  287. }
  288. return -1;
  289. }
  290. container = node = bookmark[start ? 'startContainer' : 'endContainer'];
  291. offset = bookmark[start ? 'startOffset' : 'endOffset'];
  292. if (!container) {
  293. return;
  294. }
  295. if (container.nodeType == 1) {
  296. offset = nodeIndex(container);
  297. container = container.parentNode;
  298. dom.remove(node);
  299. }
  300. bookmark[start ? 'startContainer' : 'endContainer'] = container;
  301. bookmark[start ? 'startOffset' : 'endOffset'] = offset;
  302. }
  303. restoreEndPoint(true);
  304. restoreEndPoint();
  305. var rng = dom.createRng();
  306. rng.setStart(bookmark.startContainer, bookmark.startOffset);
  307. if (bookmark.endContainer) {
  308. rng.setEnd(bookmark.endContainer, bookmark.endOffset);
  309. }
  310. return rng;
  311. };
  312. return {
  313. create: create,
  314. resolve: resolve
  315. };
  316. });
  317. defineGlobal("global!tinymce.dom.TreeWalker", tinymce.dom.TreeWalker);
  318. defineGlobal("global!tinymce.dom.RangeUtils", tinymce.dom.RangeUtils);
  319. /**
  320. * Unlink.js
  321. *
  322. * Released under LGPL License.
  323. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  324. *
  325. * License: http://www.tinymce.com/license
  326. * Contributing: http://www.tinymce.com/contributing
  327. */
  328. /**
  329. * Unlink implementation that doesn't leave partial links for example it would produce:
  330. * a[b<a href="x">c]d</a>e -> a[bc]de
  331. * instead of:
  332. * a[b<a href="x">c]d</a>e -> a[bc]<a href="x">d</a>e
  333. */
  334. define("tinymce/inlite/alien/Unlink", [
  335. 'tinymce/inlite/alien/Bookmark',
  336. 'global!tinymce.util.Tools',
  337. 'global!tinymce.dom.TreeWalker',
  338. 'global!tinymce.dom.RangeUtils'
  339. ], function (Bookmark, Tools, TreeWalker, RangeUtils) {
  340. var getSelectedElements = function (rootElm, startNode, endNode) {
  341. var walker, node, elms = [];
  342. walker = new TreeWalker(startNode, rootElm);
  343. for (node = startNode; node; node = walker.next()) {
  344. if (node.nodeType === 1) {
  345. elms.push(node);
  346. }
  347. if (node === endNode) {
  348. break;
  349. }
  350. }
  351. return elms;
  352. };
  353. var unwrapElements = function (editor, elms) {
  354. var bookmark, dom, selection;
  355. dom = editor.dom;
  356. selection = editor.selection;
  357. bookmark = Bookmark.create(dom, selection.getRng());
  358. Tools.each(elms, function (elm) {
  359. editor.dom.remove(elm, true);
  360. });
  361. selection.setRng(Bookmark.resolve(dom, bookmark));
  362. };
  363. var isLink = function (elm) {
  364. return elm.nodeName === 'A' && elm.hasAttribute('href');
  365. };
  366. var getParentAnchorOrSelf = function (dom, elm) {
  367. var anchorElm = dom.getParent(elm, isLink);
  368. return anchorElm ? anchorElm : elm;
  369. };
  370. var getSelectedAnchors = function (editor) {
  371. var startElm, endElm, rootElm, anchorElms, selection, dom, rng;
  372. selection = editor.selection;
  373. dom = editor.dom;
  374. rng = selection.getRng();
  375. startElm = getParentAnchorOrSelf(dom, RangeUtils.getNode(rng.startContainer, rng.startOffset));
  376. endElm = RangeUtils.getNode(rng.endContainer, rng.endOffset);
  377. rootElm = editor.getBody();
  378. anchorElms = Tools.grep(getSelectedElements(rootElm, startElm, endElm), isLink);
  379. return anchorElms;
  380. };
  381. var unlinkSelection = function (editor) {
  382. unwrapElements(editor, getSelectedAnchors(editor));
  383. };
  384. return {
  385. unlinkSelection: unlinkSelection
  386. };
  387. });
  388. /**
  389. * Actions.js
  390. *
  391. * Released under LGPL License.
  392. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  393. *
  394. * License: http://www.tinymce.com/license
  395. * Contributing: http://www.tinymce.com/contributing
  396. */
  397. define('tinymce/inlite/core/Actions', [
  398. 'tinymce/inlite/alien/Uuid',
  399. 'tinymce/inlite/alien/Unlink'
  400. ], function (Uuid, Unlink) {
  401. var createTableHtml = function (cols, rows) {
  402. var x, y, html;
  403. html = '<table data-mce-id="mce" style="width: 100%">';
  404. html += '<tbody>';
  405. for (y = 0; y < rows; y++) {
  406. html += '<tr>';
  407. for (x = 0; x < cols; x++) {
  408. html += '<td><br></td>';
  409. }
  410. html += '</tr>';
  411. }
  412. html += '</tbody>';
  413. html += '</table>';
  414. return html;
  415. };
  416. var getInsertedElement = function (editor) {
  417. var elms = editor.dom.select('*[data-mce-id]');
  418. return elms[0];
  419. };
  420. var insertTable = function (editor, cols, rows) {
  421. editor.undoManager.transact(function () {
  422. var tableElm, cellElm;
  423. editor.insertContent(createTableHtml(cols, rows));
  424. tableElm = getInsertedElement(editor);
  425. tableElm.removeAttribute('data-mce-id');
  426. cellElm = editor.dom.select('td,th', tableElm);
  427. editor.selection.setCursorLocation(cellElm[0], 0);
  428. });
  429. };
  430. var formatBlock = function (editor, formatName) {
  431. editor.execCommand('FormatBlock', false, formatName);
  432. };
  433. var insertBlob = function (editor, base64, blob) {
  434. var blobCache, blobInfo;
  435. blobCache = editor.editorUpload.blobCache;
  436. blobInfo = blobCache.create(Uuid.uuid('mceu'), blob, base64);
  437. blobCache.add(blobInfo);
  438. editor.insertContent(editor.dom.createHTML('img', {src: blobInfo.blobUri()}));
  439. };
  440. var collapseSelectionToEnd = function (editor) {
  441. editor.selection.collapse(false);
  442. };
  443. var unlink = function (editor) {
  444. editor.focus();
  445. Unlink.unlinkSelection(editor);
  446. collapseSelectionToEnd(editor);
  447. };
  448. var changeHref = function (editor, elm, url) {
  449. editor.focus();
  450. editor.dom.setAttrib(elm, 'href', url);
  451. collapseSelectionToEnd(editor);
  452. };
  453. var insertLink = function (editor, url) {
  454. editor.execCommand('mceInsertLink', false, {href: url});
  455. collapseSelectionToEnd(editor);
  456. };
  457. var updateOrInsertLink = function (editor, url) {
  458. var elm = editor.dom.getParent(editor.selection.getStart(), 'a[href]');
  459. elm ? changeHref(editor, elm, url) : insertLink(editor, url);
  460. };
  461. var createLink = function (editor, url) {
  462. url.trim().length === 0 ? unlink(editor) : updateOrInsertLink(editor, url);
  463. };
  464. return {
  465. insertTable: insertTable,
  466. formatBlock: formatBlock,
  467. insertBlob: insertBlob,
  468. createLink: createLink,
  469. unlink: unlink
  470. };
  471. });
  472. /**
  473. * UrlType.js
  474. *
  475. * Released under LGPL License.
  476. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  477. *
  478. * License: http://www.tinymce.com/license
  479. * Contributing: http://www.tinymce.com/contributing
  480. */
  481. define('tinymce/inlite/core/UrlType', [
  482. ], function () {
  483. var isDomainLike = function (href) {
  484. return /^www\.|\.(com|org|edu|gov|uk|net|ca|de|jp|fr|au|us|ru|ch|it|nl|se|no|es|mil)$/i.test(href.trim());
  485. };
  486. var isAbsolute = function (href) {
  487. return /^https?:\/\//.test(href.trim());
  488. };
  489. return {
  490. isDomainLike: isDomainLike,
  491. isAbsolute: isAbsolute
  492. };
  493. });
  494. /**
  495. * Forms.js
  496. *
  497. * Released under LGPL License.
  498. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  499. *
  500. * License: http://www.tinymce.com/license
  501. * Contributing: http://www.tinymce.com/contributing
  502. */
  503. define('tinymce/inlite/ui/Forms', [
  504. 'global!tinymce.util.Tools',
  505. 'global!tinymce.ui.Factory',
  506. 'global!tinymce.util.Promise',
  507. 'tinymce/inlite/core/Actions',
  508. 'tinymce/inlite/core/UrlType'
  509. ], function (Tools, Factory, Promise, Actions, UrlType) {
  510. var focusFirstTextBox = function (form) {
  511. form.find('textbox').eq(0).each(function (ctrl) {
  512. ctrl.focus();
  513. });
  514. };
  515. var createForm = function (name, spec) {
  516. var form = Factory.create(
  517. Tools.extend({
  518. type: 'form',
  519. layout: 'flex',
  520. direction: 'row',
  521. padding: 5,
  522. name: name,
  523. spacing: 3
  524. }, spec)
  525. );
  526. form.on('show', function () {
  527. focusFirstTextBox(form);
  528. });
  529. return form;
  530. };
  531. var toggleVisibility = function (ctrl, state) {
  532. return state ? ctrl.show() : ctrl.hide();
  533. };
  534. var askAboutPrefix = function (editor, href) {
  535. return new Promise(function (resolve) {
  536. editor.windowManager.confirm(
  537. 'The URL you entered seems to be an external link. Do you want to add the required http:// prefix?',
  538. function (result) {
  539. var output = result === true ? 'http://' + href : href;
  540. resolve(output);
  541. }
  542. );
  543. });
  544. };
  545. var convertLinkToAbsolute = function (editor, href) {
  546. return !UrlType.isAbsolute(href) && UrlType.isDomainLike(href) ? askAboutPrefix(editor, href) : Promise.resolve(href);
  547. };
  548. var createQuickLinkForm = function (editor, hide) {
  549. var unlink = function () {
  550. editor.focus();
  551. Actions.unlink(editor);
  552. hide();
  553. };
  554. return createForm('quicklink', {
  555. items: [
  556. {type: 'button', name: 'unlink', icon: 'unlink', onclick: unlink, tooltip: 'Remove link'},
  557. {type: 'textbox', name: 'linkurl', placeholder: 'Paste or type a link'},
  558. {type: 'button', icon: 'checkmark', subtype: 'primary', tooltip: 'Ok', onclick: 'submit'}
  559. ],
  560. onshow: function () {
  561. var elm, linkurl = '';
  562. elm = editor.dom.getParent(editor.selection.getStart(), 'a[href]');
  563. if (elm) {
  564. linkurl = editor.dom.getAttrib(elm, 'href');
  565. }
  566. this.fromJSON({
  567. linkurl: linkurl
  568. });
  569. toggleVisibility(this.find('#unlink'), elm);
  570. },
  571. onsubmit: function (e) {
  572. convertLinkToAbsolute(editor, e.data.linkurl).then(function (url) {
  573. Actions.createLink(editor, url);
  574. hide();
  575. });
  576. }
  577. });
  578. };
  579. return {
  580. createQuickLinkForm: createQuickLinkForm
  581. };
  582. });
  583. defineGlobal("global!tinymce.geom.Rect", tinymce.geom.Rect);
  584. /**
  585. * Convert.js
  586. *
  587. * Released under LGPL License.
  588. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  589. *
  590. * License: http://www.tinymce.com/license
  591. * Contributing: http://www.tinymce.com/contributing
  592. */
  593. define('tinymce/inlite/core/Convert', [
  594. ], function () {
  595. var fromClientRect = function (clientRect) {
  596. return {
  597. x: clientRect.left,
  598. y: clientRect.top,
  599. w: clientRect.width,
  600. h: clientRect.height
  601. };
  602. };
  603. var toClientRect = function (geomRect) {
  604. return {
  605. left: geomRect.x,
  606. top: geomRect.y,
  607. width: geomRect.w,
  608. height: geomRect.h,
  609. right: geomRect.x + geomRect.w,
  610. bottom: geomRect.y + geomRect.h
  611. };
  612. };
  613. return {
  614. fromClientRect: fromClientRect,
  615. toClientRect: toClientRect
  616. };
  617. });
  618. /**
  619. * Measure.js
  620. *
  621. * Released under LGPL License.
  622. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  623. *
  624. * License: http://www.tinymce.com/license
  625. * Contributing: http://www.tinymce.com/contributing
  626. */
  627. define('tinymce/inlite/core/Measure', [
  628. 'global!tinymce.DOM',
  629. 'global!tinymce.geom.Rect',
  630. 'tinymce/inlite/core/Convert'
  631. ], function (DOM, Rect, Convert) {
  632. var toAbsolute = function (rect) {
  633. var vp = DOM.getViewPort();
  634. return {
  635. x: rect.x + vp.x,
  636. y: rect.y + vp.y,
  637. w: rect.w,
  638. h: rect.h
  639. };
  640. };
  641. var measureElement = function (elm) {
  642. var clientRect = elm.getBoundingClientRect();
  643. return toAbsolute({
  644. x: clientRect.left,
  645. y: clientRect.top,
  646. w: Math.max(elm.clientWidth, elm.offsetWidth),
  647. h: Math.max(elm.clientHeight, elm.offsetHeight)
  648. });
  649. };
  650. var getElementRect = function (editor, elm) {
  651. return measureElement(elm);
  652. };
  653. var getPageAreaRect = function (editor) {
  654. return measureElement(editor.getElement().ownerDocument.body);
  655. };
  656. var getContentAreaRect = function (editor) {
  657. return measureElement(editor.getContentAreaContainer() || editor.getBody());
  658. };
  659. var getSelectionRect = function (editor) {
  660. var clientRect = editor.selection.getBoundingClientRect();
  661. return clientRect ? toAbsolute(Convert.fromClientRect(clientRect)) : null;
  662. };
  663. return {
  664. getElementRect: getElementRect,
  665. getPageAreaRect: getPageAreaRect,
  666. getContentAreaRect: getContentAreaRect,
  667. getSelectionRect: getSelectionRect
  668. };
  669. });
  670. /**
  671. * Layout.js
  672. *
  673. * Released under LGPL License.
  674. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  675. *
  676. * License: http://www.tinymce.com/license
  677. * Contributing: http://www.tinymce.com/contributing
  678. */
  679. define('tinymce/inlite/core/Layout', [
  680. 'global!tinymce.geom.Rect',
  681. 'tinymce/inlite/core/Convert'
  682. ], function (Rect, Convert) {
  683. var result = function (rect, position) {
  684. return {
  685. rect: rect,
  686. position: position
  687. };
  688. };
  689. var moveTo = function (rect, toRect) {
  690. return {x: toRect.x, y: toRect.y, w: rect.w, h: rect.h};
  691. };
  692. var calcByPositions = function (testPositions1, testPositions2, targetRect, contentAreaRect, panelRect) {
  693. var relPos, relRect, outputPanelRect;
  694. relPos = Rect.findBestRelativePosition(panelRect, targetRect, contentAreaRect, testPositions1);
  695. targetRect = Rect.clamp(targetRect, contentAreaRect);
  696. if (relPos) {
  697. relRect = Rect.relativePosition(panelRect, targetRect, relPos);
  698. outputPanelRect = moveTo(panelRect, relRect);
  699. return result(outputPanelRect, relPos);
  700. }
  701. targetRect = Rect.intersect(contentAreaRect, targetRect);
  702. if (targetRect) {
  703. relPos = Rect.findBestRelativePosition(panelRect, targetRect, contentAreaRect, testPositions2);
  704. if (relPos) {
  705. relRect = Rect.relativePosition(panelRect, targetRect, relPos);
  706. outputPanelRect = moveTo(panelRect, relRect);
  707. return result(outputPanelRect, relPos);
  708. }
  709. outputPanelRect = moveTo(panelRect, targetRect);
  710. return result(outputPanelRect, relPos);
  711. }
  712. return null;
  713. };
  714. var calcInsert = function (targetRect, contentAreaRect, panelRect) {
  715. return calcByPositions(
  716. ['cr-cl', 'cl-cr'],
  717. ['bc-tc', 'bl-tl', 'br-tr'],
  718. targetRect,
  719. contentAreaRect,
  720. panelRect
  721. );
  722. };
  723. var calc = function (targetRect, contentAreaRect, panelRect) {
  724. return calcByPositions(
  725. ['tc-bc', 'bc-tc', 'tl-bl', 'bl-tl', 'tr-br', 'br-tr'],
  726. ['bc-tc', 'bl-tl', 'br-tr'],
  727. targetRect,
  728. contentAreaRect,
  729. panelRect
  730. );
  731. };
  732. var userConstrain = function (handler, targetRect, contentAreaRect, panelRect) {
  733. var userConstrainedPanelRect;
  734. if (typeof handler === 'function') {
  735. userConstrainedPanelRect = handler({
  736. elementRect: Convert.toClientRect(targetRect),
  737. contentAreaRect: Convert.toClientRect(contentAreaRect),
  738. panelRect: Convert.toClientRect(panelRect)
  739. });
  740. return Convert.fromClientRect(userConstrainedPanelRect);
  741. }
  742. return panelRect;
  743. };
  744. return {
  745. calcInsert: calcInsert,
  746. calc: calc,
  747. userConstrain: userConstrain
  748. };
  749. });
  750. /**
  751. * Panel.js
  752. *
  753. * Released under LGPL License.
  754. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  755. *
  756. * License: http://www.tinymce.com/license
  757. * Contributing: http://www.tinymce.com/contributing
  758. */
  759. define('tinymce/inlite/ui/Panel', [
  760. 'global!tinymce.util.Tools',
  761. 'global!tinymce.ui.Factory',
  762. 'global!tinymce.DOM',
  763. 'tinymce/inlite/ui/Toolbar',
  764. 'tinymce/inlite/ui/Forms',
  765. 'tinymce/inlite/core/Measure',
  766. 'tinymce/inlite/core/Layout'
  767. ], function (Tools, Factory, DOM, Toolbar, Forms, Measure, Layout) {
  768. return function () {
  769. var DEFAULT_TEXT_SELECTION_ITEMS = 'bold italic | quicklink h2 h3 blockquote';
  770. var DEFAULT_INSERT_TOOLBAR_ITEMS = 'quickimage quicktable';
  771. var panel, currentRect;
  772. var createToolbars = function (editor, toolbars) {
  773. return Tools.map(toolbars, function (toolbar) {
  774. return Toolbar.create(editor, toolbar.id, toolbar.items);
  775. });
  776. };
  777. var getTextSelectionToolbarItems = function (settings) {
  778. var value = settings.selection_toolbar;
  779. return value ? value : DEFAULT_TEXT_SELECTION_ITEMS;
  780. };
  781. var getInsertToolbarItems = function (settings) {
  782. var value = settings.insert_toolbar;
  783. return value ? value : DEFAULT_INSERT_TOOLBAR_ITEMS;
  784. };
  785. var create = function (editor, toolbars) {
  786. var items, settings = editor.settings;
  787. items = createToolbars(editor, toolbars);
  788. items = items.concat([
  789. Toolbar.create(editor, 'text', getTextSelectionToolbarItems(settings)),
  790. Toolbar.create(editor, 'insert', getInsertToolbarItems(settings)),
  791. Forms.createQuickLinkForm(editor, hide)
  792. ]);
  793. return Factory.create({
  794. type: 'floatpanel',
  795. role: 'dialog',
  796. classes: 'tinymce tinymce-inline arrow',
  797. ariaLabel: 'Inline toolbar',
  798. layout: 'flex',
  799. direction: 'column',
  800. align: 'stretch',
  801. autohide: false,
  802. autofix: true,
  803. fixed: true,
  804. border: 1,
  805. items: items,
  806. oncancel: function() {
  807. editor.focus();
  808. }
  809. });
  810. };
  811. var showPanel = function (panel) {
  812. if (panel) {
  813. panel.show();
  814. }
  815. };
  816. var movePanelTo = function (panel, pos) {
  817. panel.moveTo(pos.x, pos.y);
  818. };
  819. var togglePositionClass = function (panel, relPos) {
  820. relPos = relPos ? relPos.substr(0, 2) : '';
  821. Tools.each({
  822. t: 'down',
  823. b: 'up',
  824. c: 'center'
  825. }, function(cls, pos) {
  826. panel.classes.toggle('arrow-' + cls, pos === relPos.substr(0, 1));
  827. });
  828. if (relPos === 'cr') {
  829. panel.classes.toggle('arrow-left', true);
  830. panel.classes.toggle('arrow-right', false);
  831. } else if (relPos === 'cl') {
  832. panel.classes.toggle('arrow-left', true);
  833. panel.classes.toggle('arrow-right', true);
  834. } else {
  835. Tools.each({
  836. l: 'left',
  837. r: 'right'
  838. }, function(cls, pos) {
  839. panel.classes.toggle('arrow-' + cls, pos === relPos.substr(1, 1));
  840. });
  841. }
  842. };
  843. var showToolbar = function (panel, id) {
  844. var toolbars = panel.items().filter('#' + id);
  845. if (toolbars.length > 0) {
  846. toolbars[0].show();
  847. panel.reflow();
  848. }
  849. };
  850. var showPanelAt = function (panel, id, editor, targetRect) {
  851. var contentAreaRect, panelRect, result, userConstainHandler;
  852. showPanel(panel);
  853. panel.items().hide();
  854. showToolbar(panel, id);
  855. userConstainHandler = editor.settings.inline_toolbar_position_handler;
  856. contentAreaRect = Measure.getContentAreaRect(editor);
  857. panelRect = DOM.getRect(panel.getEl());
  858. if (id === 'insert') {
  859. result = Layout.calcInsert(targetRect, contentAreaRect, panelRect);
  860. } else {
  861. result = Layout.calc(targetRect, contentAreaRect, panelRect);
  862. }
  863. if (result) {
  864. panelRect = result.rect;
  865. currentRect = targetRect;
  866. movePanelTo(panel, Layout.userConstrain(userConstainHandler, targetRect, contentAreaRect, panelRect));
  867. togglePositionClass(panel, result.position);
  868. } else {
  869. hide(panel);
  870. }
  871. };
  872. var hasFormVisible = function () {
  873. return panel.items().filter('form:visible').length > 0;
  874. };
  875. var showForm = function (editor, id) {
  876. if (panel) {
  877. panel.items().hide();
  878. showToolbar(panel, id);
  879. var contentAreaRect, panelRect, result, userConstainHandler;
  880. showPanel(panel);
  881. panel.items().hide();
  882. showToolbar(panel, id);
  883. userConstainHandler = editor.settings.inline_toolbar_position_handler;
  884. contentAreaRect = Measure.getContentAreaRect(editor);
  885. panelRect = DOM.getRect(panel.getEl());
  886. result = Layout.calc(currentRect, contentAreaRect, panelRect);
  887. if (result) {
  888. panelRect = result.rect;
  889. movePanelTo(panel, Layout.userConstrain(userConstainHandler, currentRect, contentAreaRect, panelRect));
  890. togglePositionClass(panel, result.position);
  891. }
  892. }
  893. };
  894. var show = function (editor, id, targetRect, toolbars) {
  895. if (!panel) {
  896. panel = create(editor, toolbars);
  897. panel.renderTo(document.body).reflow().moveTo(targetRect.x, targetRect.y);
  898. editor.nodeChanged();
  899. }
  900. showPanelAt(panel, id, editor, targetRect);
  901. };
  902. var hide = function () {
  903. if (panel) {
  904. panel.hide();
  905. }
  906. };
  907. var focus = function () {
  908. if (panel) {
  909. panel.find('toolbar:visible').eq(0).each(function (item) {
  910. item.focus(true);
  911. });
  912. }
  913. };
  914. var remove = function () {
  915. if (panel) {
  916. panel.remove();
  917. panel = null;
  918. }
  919. };
  920. var inForm = function () {
  921. return panel && panel.visible() && hasFormVisible();
  922. };
  923. return {
  924. show: show,
  925. showForm: showForm,
  926. inForm: inForm,
  927. hide: hide,
  928. focus: focus,
  929. remove: remove
  930. };
  931. };
  932. });
  933. /**
  934. * Conversions.js
  935. *
  936. * Released under LGPL License.
  937. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  938. *
  939. * License: http://www.tinymce.com/license
  940. * Contributing: http://www.tinymce.com/contributing
  941. */
  942. define('tinymce/inlite/file/Conversions', [
  943. 'global!tinymce.util.Promise'
  944. ], function (Promise) {
  945. var blobToBase64 = function (blob) {
  946. return new Promise(function(resolve) {
  947. var reader = new FileReader();
  948. reader.onloadend = function() {
  949. resolve(reader.result.split(',')[1]);
  950. };
  951. reader.readAsDataURL(blob);
  952. });
  953. };
  954. return {
  955. blobToBase64: blobToBase64
  956. };
  957. });
  958. /**
  959. * Picker.js
  960. *
  961. * Released under LGPL License.
  962. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  963. *
  964. * License: http://www.tinymce.com/license
  965. * Contributing: http://www.tinymce.com/contributing
  966. */
  967. define('tinymce/inlite/file/Picker', [
  968. 'global!tinymce.util.Promise'
  969. ], function (Promise) {
  970. var pickFile = function () {
  971. return new Promise(function (resolve) {
  972. var fileInput;
  973. fileInput = document.createElement("input");
  974. fileInput.type = "file";
  975. fileInput.style.position = 'fixed';
  976. fileInput.style.left = 0;
  977. fileInput.style.top = 0;
  978. fileInput.style.opacity = 0.001;
  979. document.body.appendChild(fileInput);
  980. fileInput.onchange = function(e) {
  981. resolve(Array.prototype.slice.call(e.target.files));
  982. };
  983. fileInput.click();
  984. fileInput.parentNode.removeChild(fileInput);
  985. });
  986. };
  987. return {
  988. pickFile: pickFile
  989. };
  990. });
  991. /**
  992. * Buttons.js
  993. *
  994. * Released under LGPL License.
  995. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  996. *
  997. * License: http://www.tinymce.com/license
  998. * Contributing: http://www.tinymce.com/contributing
  999. */
  1000. define('tinymce/inlite/ui/Buttons', [
  1001. 'tinymce/inlite/ui/Panel',
  1002. 'tinymce/inlite/file/Conversions',
  1003. 'tinymce/inlite/file/Picker',
  1004. 'tinymce/inlite/core/Actions'
  1005. ], function (Panel, Conversions, Picker, Actions) {
  1006. var addHeaderButtons = function (editor) {
  1007. var formatBlock = function (name) {
  1008. return function () {
  1009. Actions.formatBlock(editor, name);
  1010. };
  1011. };
  1012. for (var i = 1; i < 6; i++) {
  1013. var name = 'h' + i;
  1014. editor.addButton(name, {
  1015. text: name.toUpperCase(),
  1016. tooltip: 'Heading ' + i,
  1017. stateSelector: name,
  1018. onclick: formatBlock(name),
  1019. onPostRender: function () {
  1020. // TODO: Remove this hack that produces bold H1-H6 when we have proper icons
  1021. var span = this.getEl().firstChild.firstChild;
  1022. span.style.fontWeight = 'bold';
  1023. }
  1024. });
  1025. }
  1026. };
  1027. var addToEditor = function (editor, panel) {
  1028. editor.addButton('quicklink', {
  1029. icon: 'link',
  1030. tooltip: 'Insert/Edit link',
  1031. stateSelector: 'a[href]',
  1032. onclick: function () {
  1033. panel.showForm(editor, 'quicklink');
  1034. }
  1035. });
  1036. editor.addButton('quickimage', {
  1037. icon: 'image',
  1038. tooltip: 'Insert image',
  1039. onclick: function () {
  1040. Picker.pickFile().then(function (files) {
  1041. var blob = files[0];
  1042. Conversions.blobToBase64(blob).then(function (base64) {
  1043. Actions.insertBlob(editor, base64, blob);
  1044. });
  1045. });
  1046. }
  1047. });
  1048. editor.addButton('quicktable', {
  1049. icon: 'table',
  1050. tooltip: 'Insert table',
  1051. onclick: function () {
  1052. panel.hide();
  1053. Actions.insertTable(editor, 2, 2);
  1054. }
  1055. });
  1056. addHeaderButtons(editor);
  1057. };
  1058. return {
  1059. addToEditor: addToEditor
  1060. };
  1061. });
  1062. defineGlobal("global!tinymce.EditorManager", tinymce.EditorManager);
  1063. /**
  1064. * SkinLoader.js
  1065. *
  1066. * Released under LGPL License.
  1067. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  1068. *
  1069. * License: http://www.tinymce.com/license
  1070. * Contributing: http://www.tinymce.com/contributing
  1071. */
  1072. define('tinymce/inlite/core/SkinLoader', [
  1073. 'global!tinymce.EditorManager',
  1074. 'global!tinymce.DOM'
  1075. ], function (EditorManager, DOM) {
  1076. var fireSkinLoaded = function (editor, callback) {
  1077. var done = function () {
  1078. editor.fire('SkinLoaded');
  1079. callback();
  1080. };
  1081. if (editor.initialized) {
  1082. done();
  1083. } else {
  1084. editor.on('init', done);
  1085. }
  1086. };
  1087. var load = function (editor, skin, callback) {
  1088. var baseUrl = EditorManager.baseURL;
  1089. var skinUrl = baseUrl + '/skins/' + skin;
  1090. var done = function () {
  1091. fireSkinLoaded(editor, callback);
  1092. };
  1093. DOM.styleSheetLoader.load(skinUrl + '/skin.min.css', done);
  1094. editor.contentCSS.push(skinUrl + '/content.inline.min.css');
  1095. };
  1096. return {
  1097. load: load
  1098. };
  1099. });
  1100. /**
  1101. * Matcher.js
  1102. *
  1103. * Released under LGPL License.
  1104. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  1105. *
  1106. * License: http://www.tinymce.com/license
  1107. * Contributing: http://www.tinymce.com/contributing
  1108. */
  1109. define('tinymce/inlite/core/Matcher', [
  1110. ], function () {
  1111. // result :: String, Rect -> Matcher.result
  1112. var result = function (id, rect) {
  1113. return {
  1114. id: id,
  1115. rect: rect
  1116. };
  1117. };
  1118. // match :: Editor, [(Editor -> Matcher.result | Null)] -> Matcher.result | Null
  1119. var match = function (editor, matchers) {
  1120. for (var i = 0; i < matchers.length; i++) {
  1121. var f = matchers[i];
  1122. var result = f(editor);
  1123. if (result) {
  1124. return result;
  1125. }
  1126. }
  1127. return null;
  1128. };
  1129. return {
  1130. match: match,
  1131. result: result
  1132. };
  1133. });
  1134. /**
  1135. * SelectionMatcher.js
  1136. *
  1137. * Released under LGPL License.
  1138. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  1139. *
  1140. * License: http://www.tinymce.com/license
  1141. * Contributing: http://www.tinymce.com/contributing
  1142. */
  1143. define('tinymce/inlite/core/SelectionMatcher', [
  1144. 'tinymce/inlite/core/Matcher',
  1145. 'tinymce/inlite/core/Measure'
  1146. ], function (Matcher, Measure) {
  1147. // textSelection :: String -> (Editor -> Matcher.result | Null)
  1148. var textSelection = function (id) {
  1149. return function (editor) {
  1150. if (!editor.selection.isCollapsed()) {
  1151. return Matcher.result(id, Measure.getSelectionRect(editor));
  1152. }
  1153. return null;
  1154. };
  1155. };
  1156. // emptyTextBlock :: [Elements], String -> (Editor -> Matcher.result | Null)
  1157. var emptyTextBlock = function (elements, id) {
  1158. return function (editor) {
  1159. var i, textBlockElementsMap = editor.schema.getTextBlockElements();
  1160. for (i = 0; i < elements.length; i++) {
  1161. if (elements[i].nodeName === 'TABLE') {
  1162. return null;
  1163. }
  1164. }
  1165. for (i = 0; i < elements.length; i++) {
  1166. if (elements[i].nodeName in textBlockElementsMap) {
  1167. if (editor.dom.isEmpty(elements[i])) {
  1168. return Matcher.result(id, Measure.getSelectionRect(editor));
  1169. }
  1170. return null;
  1171. }
  1172. }
  1173. return null;
  1174. };
  1175. };
  1176. return {
  1177. textSelection: textSelection,
  1178. emptyTextBlock: emptyTextBlock
  1179. };
  1180. });
  1181. /**
  1182. * ElementMatcher.js
  1183. *
  1184. * Released under LGPL License.
  1185. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  1186. *
  1187. * License: http://www.tinymce.com/license
  1188. * Contributing: http://www.tinymce.com/contributing
  1189. */
  1190. define('tinymce/inlite/core/ElementMatcher', [
  1191. 'tinymce/inlite/core/Matcher',
  1192. 'tinymce/inlite/core/Measure'
  1193. ], function (Matcher, Measure) {
  1194. // element :: Element, [PredicateId] -> (Editor -> Matcher.result | Null)
  1195. var element = function (element, predicateIds) {
  1196. return function (editor) {
  1197. for (var i = 0; i < predicateIds.length; i++) {
  1198. if (predicateIds[i].predicate(element)) {
  1199. return Matcher.result(predicateIds[i].id, Measure.getElementRect(editor, element));
  1200. }
  1201. }
  1202. return null;
  1203. };
  1204. };
  1205. // parent :: [Elements], [PredicateId] -> (Editor -> Matcher.result | Null)
  1206. var parent = function (elements, predicateIds) {
  1207. return function (editor) {
  1208. for (var i = 0; i < elements.length; i++) {
  1209. for (var x = 0; x < predicateIds.length; x++) {
  1210. if (predicateIds[x].predicate(elements[i])) {
  1211. return Matcher.result(predicateIds[x].id, Measure.getElementRect(editor, elements[i]));
  1212. }
  1213. }
  1214. }
  1215. return null;
  1216. };
  1217. };
  1218. return {
  1219. element: element,
  1220. parent: parent
  1221. };
  1222. });
  1223. /**
  1224. * Arr.js
  1225. *
  1226. * Released under LGPL License.
  1227. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  1228. *
  1229. * License: http://www.tinymce.com/license
  1230. * Contributing: http://www.tinymce.com/contributing
  1231. */
  1232. define('tinymce/inlite/alien/Arr', [
  1233. ], function () {
  1234. var flatten = function (arr) {
  1235. return arr.reduce(function (results, item) {
  1236. return Array.isArray(item) ? results.concat(flatten(item)) : results.concat(item);
  1237. }, []);
  1238. };
  1239. return {
  1240. flatten: flatten
  1241. };
  1242. });
  1243. /**
  1244. * PredicateId.js
  1245. *
  1246. * Released under LGPL License.
  1247. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  1248. *
  1249. * License: http://www.tinymce.com/license
  1250. * Contributing: http://www.tinymce.com/contributing
  1251. */
  1252. define('tinymce/inlite/core/PredicateId', [
  1253. 'global!tinymce.util.Tools'
  1254. ], function (Tools) {
  1255. var create = function (id, predicate) {
  1256. return {
  1257. id: id,
  1258. predicate: predicate
  1259. };
  1260. };
  1261. // fromContextToolbars :: [ContextToolbar] -> [PredicateId]
  1262. var fromContextToolbars = function (toolbars) {
  1263. return Tools.map(toolbars, function (toolbar) {
  1264. return create(toolbar.id, toolbar.predicate);
  1265. });
  1266. };
  1267. return {
  1268. create: create,
  1269. fromContextToolbars: fromContextToolbars
  1270. };
  1271. });
  1272. /**
  1273. * Theme.js
  1274. *
  1275. * Released under LGPL License.
  1276. * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
  1277. *
  1278. * License: http://www.tinymce.com/license
  1279. * Contributing: http://www.tinymce.com/contributing
  1280. */
  1281. define('tinymce/inlite/Theme', [
  1282. 'global!tinymce.ThemeManager',
  1283. 'global!tinymce.util.Delay',
  1284. 'tinymce/inlite/ui/Panel',
  1285. 'tinymce/inlite/ui/Buttons',
  1286. 'tinymce/inlite/core/SkinLoader',
  1287. 'tinymce/inlite/core/SelectionMatcher',
  1288. 'tinymce/inlite/core/ElementMatcher',
  1289. 'tinymce/inlite/core/Matcher',
  1290. 'tinymce/inlite/alien/Arr',
  1291. 'tinymce/inlite/core/PredicateId'
  1292. ], function(ThemeManager, Delay, Panel, Buttons, SkinLoader, SelectionMatcher, ElementMatcher, Matcher, Arr, PredicateId) {
  1293. var getSelectionElements = function (editor) {
  1294. var node = editor.selection.getNode();
  1295. var elms = editor.dom.getParents(node);
  1296. return elms;
  1297. };
  1298. var createToolbar = function (editor, selector, id, items) {
  1299. var selectorPredicate = function (elm) {
  1300. return editor.dom.is(elm, selector);
  1301. };
  1302. return {
  1303. predicate: selectorPredicate,
  1304. id: id,
  1305. items: items
  1306. };
  1307. };
  1308. var getToolbars = function (editor) {
  1309. var contextToolbars = editor.contextToolbars;
  1310. return Arr.flatten([
  1311. contextToolbars ? contextToolbars : [],
  1312. createToolbar(editor, 'img', 'image', 'alignleft aligncenter alignright')
  1313. ]);
  1314. };
  1315. var findMatchResult = function (editor, toolbars) {
  1316. var result, elements, contextToolbarsPredicateIds;
  1317. elements = getSelectionElements(editor);
  1318. contextToolbarsPredicateIds = PredicateId.fromContextToolbars(toolbars);
  1319. result = Matcher.match(editor, [
  1320. ElementMatcher.element(elements[0], contextToolbarsPredicateIds),
  1321. SelectionMatcher.textSelection('text'),
  1322. SelectionMatcher.emptyTextBlock(elements, 'insert'),
  1323. ElementMatcher.parent(elements, contextToolbarsPredicateIds)
  1324. ]);
  1325. return result && result.rect ? result : null;
  1326. };
  1327. var togglePanel = function (editor, panel) {
  1328. var toggle = function () {
  1329. var toolbars = getToolbars(editor);
  1330. var result = findMatchResult(editor, toolbars);
  1331. if (result) {
  1332. panel.show(editor, result.id, result.rect, toolbars);
  1333. } else {
  1334. panel.hide();
  1335. }
  1336. };
  1337. return function () {
  1338. if (!editor.removed) {
  1339. toggle();
  1340. }
  1341. };
  1342. };
  1343. var ignoreWhenFormIsVisible = function (panel, f) {
  1344. return function () {
  1345. if (!panel.inForm()) {
  1346. f();
  1347. }
  1348. };
  1349. };
  1350. var bindContextualToolbarsEvents = function (editor, panel) {
  1351. var throttledTogglePanel = Delay.throttle(togglePanel(editor, panel), 0);
  1352. var throttledTogglePanelWhenNotInForm = Delay.throttle(ignoreWhenFormIsVisible(panel, togglePanel(editor, panel)), 0);
  1353. editor.on('blur hide ObjectResizeStart', panel.hide);
  1354. editor.on('click', throttledTogglePanel);
  1355. editor.on('nodeChange mouseup', throttledTogglePanelWhenNotInForm);
  1356. editor.on('ResizeEditor ResizeWindow keyup', throttledTogglePanel);
  1357. editor.on('remove', panel.remove);
  1358. editor.shortcuts.add('Alt+F10', '', panel.focus);
  1359. };
  1360. var overrideLinkShortcut = function (editor, panel) {
  1361. editor.shortcuts.remove('meta+k');
  1362. editor.shortcuts.add('meta+k', '', function () {
  1363. var toolbars = getToolbars(editor);
  1364. var result = result = Matcher.match(editor, [
  1365. SelectionMatcher.textSelection('quicklink')
  1366. ]);
  1367. if (result) {
  1368. panel.show(editor, result.id, result.rect, toolbars);
  1369. }
  1370. });
  1371. };
  1372. var renderInlineUI = function (editor, panel) {
  1373. var skinName = editor.settings.skin || 'lightgray';
  1374. SkinLoader.load(editor, skinName, function () {
  1375. bindContextualToolbarsEvents(editor, panel);
  1376. overrideLinkShortcut(editor, panel);
  1377. });
  1378. return {};
  1379. };
  1380. var fail = function (message) {
  1381. throw new Error(message);
  1382. };
  1383. ThemeManager.add('inlite', function (editor) {
  1384. var panel = new Panel();
  1385. Buttons.addToEditor(editor, panel);
  1386. var renderUI = function () {
  1387. return editor.inline ? renderInlineUI(editor, panel) : fail('inlite theme only supports inline mode.');
  1388. };
  1389. return {
  1390. renderUI: renderUI
  1391. };
  1392. });
  1393. return function() {};
  1394. });
  1395. dem('tinymce/inlite/Theme')();
  1396. })();