[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 /** 2 * Copyright (c) Tiny Technologies, Inc. All rights reserved. 3 * Licensed under the LGPL or a commercial license. 4 * For LGPL see License.txt in the project root for license information. 5 * For commercial licenses see https://www.tiny.cloud/ 6 * 7 * Version: 5.10.5 (2022-05-25) 8 */ 9 (function () { 10 'use strict'; 11 12 var Cell = function (initial) { 13 var value = initial; 14 var get = function () { 15 return value; 16 }; 17 var set = function (v) { 18 value = v; 19 }; 20 return { 21 get: get, 22 set: set 23 }; 24 }; 25 26 var global$4 = tinymce.util.Tools.resolve('tinymce.PluginManager'); 27 28 var __assign = function () { 29 __assign = Object.assign || function __assign(t) { 30 for (var s, i = 1, n = arguments.length; i < n; i++) { 31 s = arguments[i]; 32 for (var p in s) 33 if (Object.prototype.hasOwnProperty.call(s, p)) 34 t[p] = s[p]; 35 } 36 return t; 37 }; 38 return __assign.apply(this, arguments); 39 }; 40 41 var global$3 = tinymce.util.Tools.resolve('tinymce.util.Tools'); 42 43 var global$2 = tinymce.util.Tools.resolve('tinymce.html.DomParser'); 44 45 var global$1 = tinymce.util.Tools.resolve('tinymce.html.Node'); 46 47 var global = tinymce.util.Tools.resolve('tinymce.html.Serializer'); 48 49 var shouldHideInSourceView = function (editor) { 50 return editor.getParam('fullpage_hide_in_source_view'); 51 }; 52 var getDefaultXmlPi = function (editor) { 53 return editor.getParam('fullpage_default_xml_pi'); 54 }; 55 var getDefaultEncoding = function (editor) { 56 return editor.getParam('fullpage_default_encoding'); 57 }; 58 var getDefaultFontFamily = function (editor) { 59 return editor.getParam('fullpage_default_font_family'); 60 }; 61 var getDefaultFontSize = function (editor) { 62 return editor.getParam('fullpage_default_font_size'); 63 }; 64 var getDefaultTextColor = function (editor) { 65 return editor.getParam('fullpage_default_text_color'); 66 }; 67 var getDefaultTitle = function (editor) { 68 return editor.getParam('fullpage_default_title'); 69 }; 70 var getDefaultDocType = function (editor) { 71 return editor.getParam('fullpage_default_doctype', '<!DOCTYPE html>'); 72 }; 73 var getProtect = function (editor) { 74 return editor.getParam('protect'); 75 }; 76 77 var parseHeader = function (editor, head) { 78 return global$2({ 79 validate: false, 80 root_name: '#document' 81 }, editor.schema).parse(head, { format: 'xhtml' }); 82 }; 83 var htmlToData = function (editor, head) { 84 var headerFragment = parseHeader(editor, head); 85 var data = {}; 86 var elm, matches; 87 var getAttr = function (elm, name) { 88 var value = elm.attr(name); 89 return value || ''; 90 }; 91 data.fontface = getDefaultFontFamily(editor); 92 data.fontsize = getDefaultFontSize(editor); 93 elm = headerFragment.firstChild; 94 if (elm.type === 7) { 95 data.xml_pi = true; 96 matches = /encoding="([^"]+)"/.exec(elm.value); 97 if (matches) { 98 data.docencoding = matches[1]; 99 } 100 } 101 elm = headerFragment.getAll('#doctype')[0]; 102 if (elm) { 103 data.doctype = '<!DOCTYPE' + elm.value + '>'; 104 } 105 elm = headerFragment.getAll('title')[0]; 106 if (elm && elm.firstChild) { 107 data.title = elm.firstChild.value; 108 } 109 global$3.each(headerFragment.getAll('meta'), function (meta) { 110 var name = meta.attr('name'); 111 var httpEquiv = meta.attr('http-equiv'); 112 var matches; 113 if (name) { 114 data[name.toLowerCase()] = meta.attr('content'); 115 } else if (httpEquiv === 'Content-Type') { 116 matches = /charset\s*=\s*(.*)\s*/gi.exec(meta.attr('content')); 117 if (matches) { 118 data.docencoding = matches[1]; 119 } 120 } 121 }); 122 elm = headerFragment.getAll('html')[0]; 123 if (elm) { 124 data.langcode = getAttr(elm, 'lang') || getAttr(elm, 'xml:lang'); 125 } 126 data.stylesheets = []; 127 global$3.each(headerFragment.getAll('link'), function (link) { 128 if (link.attr('rel') === 'stylesheet') { 129 data.stylesheets.push(link.attr('href')); 130 } 131 }); 132 elm = headerFragment.getAll('body')[0]; 133 if (elm) { 134 data.langdir = getAttr(elm, 'dir'); 135 data.style = getAttr(elm, 'style'); 136 data.visited_color = getAttr(elm, 'vlink'); 137 data.link_color = getAttr(elm, 'link'); 138 data.active_color = getAttr(elm, 'alink'); 139 } 140 return data; 141 }; 142 var dataToHtml = function (editor, data, head) { 143 var headElement, elm; 144 var dom = editor.dom; 145 var setAttr = function (elm, name, value) { 146 elm.attr(name, value ? value : undefined); 147 }; 148 var addHeadNode = function (node) { 149 if (headElement.firstChild) { 150 headElement.insert(node, headElement.firstChild); 151 } else { 152 headElement.append(node); 153 } 154 }; 155 var headerFragment = parseHeader(editor, head); 156 headElement = headerFragment.getAll('head')[0]; 157 if (!headElement) { 158 elm = headerFragment.getAll('html')[0]; 159 headElement = new global$1('head', 1); 160 if (elm.firstChild) { 161 elm.insert(headElement, elm.firstChild, true); 162 } else { 163 elm.append(headElement); 164 } 165 } 166 elm = headerFragment.firstChild; 167 if (data.xml_pi) { 168 var value = 'version="1.0"'; 169 if (data.docencoding) { 170 value += ' encoding="' + data.docencoding + '"'; 171 } 172 if (elm.type !== 7) { 173 elm = new global$1('xml', 7); 174 headerFragment.insert(elm, headerFragment.firstChild, true); 175 } 176 elm.value = value; 177 } else if (elm && elm.type === 7) { 178 elm.remove(); 179 } 180 elm = headerFragment.getAll('#doctype')[0]; 181 if (data.doctype) { 182 if (!elm) { 183 elm = new global$1('#doctype', 10); 184 if (data.xml_pi) { 185 headerFragment.insert(elm, headerFragment.firstChild); 186 } else { 187 addHeadNode(elm); 188 } 189 } 190 elm.value = data.doctype.substring(9, data.doctype.length - 1); 191 } else if (elm) { 192 elm.remove(); 193 } 194 elm = null; 195 global$3.each(headerFragment.getAll('meta'), function (meta) { 196 if (meta.attr('http-equiv') === 'Content-Type') { 197 elm = meta; 198 } 199 }); 200 if (data.docencoding) { 201 if (!elm) { 202 elm = new global$1('meta', 1); 203 elm.attr('http-equiv', 'Content-Type'); 204 elm.shortEnded = true; 205 addHeadNode(elm); 206 } 207 elm.attr('content', 'text/html; charset=' + data.docencoding); 208 } else if (elm) { 209 elm.remove(); 210 } 211 elm = headerFragment.getAll('title')[0]; 212 if (data.title) { 213 if (!elm) { 214 elm = new global$1('title', 1); 215 addHeadNode(elm); 216 } else { 217 elm.empty(); 218 } 219 elm.append(new global$1('#text', 3)).value = data.title; 220 } else if (elm) { 221 elm.remove(); 222 } 223 global$3.each('keywords,description,author,copyright,robots'.split(','), function (name) { 224 var nodes = headerFragment.getAll('meta'); 225 var i, meta; 226 var value = data[name]; 227 for (i = 0; i < nodes.length; i++) { 228 meta = nodes[i]; 229 if (meta.attr('name') === name) { 230 if (value) { 231 meta.attr('content', value); 232 } else { 233 meta.remove(); 234 } 235 return; 236 } 237 } 238 if (value) { 239 elm = new global$1('meta', 1); 240 elm.attr('name', name); 241 elm.attr('content', value); 242 elm.shortEnded = true; 243 addHeadNode(elm); 244 } 245 }); 246 var currentStyleSheetsMap = {}; 247 global$3.each(headerFragment.getAll('link'), function (stylesheet) { 248 if (stylesheet.attr('rel') === 'stylesheet') { 249 currentStyleSheetsMap[stylesheet.attr('href')] = stylesheet; 250 } 251 }); 252 global$3.each(data.stylesheets, function (stylesheet) { 253 if (!currentStyleSheetsMap[stylesheet]) { 254 elm = new global$1('link', 1); 255 elm.attr({ 256 rel: 'stylesheet', 257 text: 'text/css', 258 href: stylesheet 259 }); 260 elm.shortEnded = true; 261 addHeadNode(elm); 262 } 263 delete currentStyleSheetsMap[stylesheet]; 264 }); 265 global$3.each(currentStyleSheetsMap, function (stylesheet) { 266 stylesheet.remove(); 267 }); 268 elm = headerFragment.getAll('body')[0]; 269 if (elm) { 270 setAttr(elm, 'dir', data.langdir); 271 setAttr(elm, 'style', data.style); 272 setAttr(elm, 'vlink', data.visited_color); 273 setAttr(elm, 'link', data.link_color); 274 setAttr(elm, 'alink', data.active_color); 275 dom.setAttribs(editor.getBody(), { 276 style: data.style, 277 dir: data.dir, 278 vLink: data.visited_color, 279 link: data.link_color, 280 aLink: data.active_color 281 }); 282 } 283 elm = headerFragment.getAll('html')[0]; 284 if (elm) { 285 setAttr(elm, 'lang', data.langcode); 286 setAttr(elm, 'xml:lang', data.langcode); 287 } 288 if (!headElement.firstChild) { 289 headElement.remove(); 290 } 291 var html = global({ 292 validate: false, 293 indent: true, 294 indent_before: 'head,html,body,meta,title,script,link,style', 295 indent_after: 'head,html,body,meta,title,script,link,style' 296 }).serialize(headerFragment); 297 return html.substring(0, html.indexOf('</body>')); 298 }; 299 300 var open = function (editor, headState) { 301 var data = htmlToData(editor, headState.get()); 302 var defaultData = { 303 title: '', 304 keywords: '', 305 description: '', 306 robots: '', 307 author: '', 308 docencoding: '' 309 }; 310 var initialData = __assign(__assign({}, defaultData), data); 311 editor.windowManager.open({ 312 title: 'Metadata and Document Properties', 313 size: 'normal', 314 body: { 315 type: 'panel', 316 items: [ 317 { 318 name: 'title', 319 type: 'input', 320 label: 'Title' 321 }, 322 { 323 name: 'keywords', 324 type: 'input', 325 label: 'Keywords' 326 }, 327 { 328 name: 'description', 329 type: 'input', 330 label: 'Description' 331 }, 332 { 333 name: 'robots', 334 type: 'input', 335 label: 'Robots' 336 }, 337 { 338 name: 'author', 339 type: 'input', 340 label: 'Author' 341 }, 342 { 343 name: 'docencoding', 344 type: 'input', 345 label: 'Encoding' 346 } 347 ] 348 }, 349 buttons: [ 350 { 351 type: 'cancel', 352 name: 'cancel', 353 text: 'Cancel' 354 }, 355 { 356 type: 'submit', 357 name: 'save', 358 text: 'Save', 359 primary: true 360 } 361 ], 362 initialData: initialData, 363 onSubmit: function (api) { 364 var nuData = api.getData(); 365 var headHtml = dataToHtml(editor, global$3.extend(data, nuData), headState.get()); 366 headState.set(headHtml); 367 api.close(); 368 } 369 }); 370 }; 371 372 var register$1 = function (editor, headState) { 373 editor.addCommand('mceFullPageProperties', function () { 374 open(editor, headState); 375 }); 376 }; 377 378 var protectHtml = function (protect, html) { 379 global$3.each(protect, function (pattern) { 380 html = html.replace(pattern, function (str) { 381 return '<!--mce:protected ' + escape(str) + '-->'; 382 }); 383 }); 384 return html; 385 }; 386 var unprotectHtml = function (html) { 387 return html.replace(/<!--mce:protected ([\s\S]*?)-->/g, function (a, m) { 388 return unescape(m); 389 }); 390 }; 391 392 var each = global$3.each; 393 var low = function (s) { 394 return s.replace(/<\/?[A-Z]+/g, function (a) { 395 return a.toLowerCase(); 396 }); 397 }; 398 var handleSetContent = function (editor, headState, footState, evt) { 399 var startPos, endPos, content, styles = ''; 400 var dom = editor.dom; 401 if (evt.selection) { 402 return; 403 } 404 content = protectHtml(getProtect(editor), evt.content); 405 if (evt.format === 'raw' && headState.get()) { 406 return; 407 } 408 if (evt.source_view && shouldHideInSourceView(editor)) { 409 return; 410 } 411 if (content.length === 0 && !evt.source_view) { 412 content = global$3.trim(headState.get()) + '\n' + global$3.trim(content) + '\n' + global$3.trim(footState.get()); 413 } 414 content = content.replace(/<(\/?)BODY/gi, '<$1body'); 415 startPos = content.indexOf('<body'); 416 if (startPos !== -1) { 417 startPos = content.indexOf('>', startPos); 418 headState.set(low(content.substring(0, startPos + 1))); 419 endPos = content.indexOf('</body', startPos); 420 if (endPos === -1) { 421 endPos = content.length; 422 } 423 evt.content = global$3.trim(content.substring(startPos + 1, endPos)); 424 footState.set(low(content.substring(endPos))); 425 } else { 426 headState.set(getDefaultHeader(editor)); 427 footState.set('\n</body>\n</html>'); 428 } 429 var headerFragment = parseHeader(editor, headState.get()); 430 each(headerFragment.getAll('style'), function (node) { 431 if (node.firstChild) { 432 styles += node.firstChild.value; 433 } 434 }); 435 var bodyElm = headerFragment.getAll('body')[0]; 436 if (bodyElm) { 437 dom.setAttribs(editor.getBody(), { 438 style: bodyElm.attr('style') || '', 439 dir: bodyElm.attr('dir') || '', 440 vLink: bodyElm.attr('vlink') || '', 441 link: bodyElm.attr('link') || '', 442 aLink: bodyElm.attr('alink') || '' 443 }); 444 } 445 dom.remove('fullpage_styles'); 446 var headElm = editor.getDoc().getElementsByTagName('head')[0]; 447 if (styles) { 448 var styleElm = dom.add(headElm, 'style', { id: 'fullpage_styles' }); 449 styleElm.appendChild(document.createTextNode(styles)); 450 } 451 var currentStyleSheetsMap = {}; 452 global$3.each(headElm.getElementsByTagName('link'), function (stylesheet) { 453 if (stylesheet.rel === 'stylesheet' && stylesheet.getAttribute('data-mce-fullpage')) { 454 currentStyleSheetsMap[stylesheet.href] = stylesheet; 455 } 456 }); 457 global$3.each(headerFragment.getAll('link'), function (stylesheet) { 458 var href = stylesheet.attr('href'); 459 if (!href) { 460 return true; 461 } 462 if (!currentStyleSheetsMap[href] && stylesheet.attr('rel') === 'stylesheet') { 463 dom.add(headElm, 'link', { 464 'rel': 'stylesheet', 465 'text': 'text/css', 466 href: href, 467 'data-mce-fullpage': '1' 468 }); 469 } 470 delete currentStyleSheetsMap[href]; 471 }); 472 global$3.each(currentStyleSheetsMap, function (stylesheet) { 473 stylesheet.parentNode.removeChild(stylesheet); 474 }); 475 }; 476 var getDefaultHeader = function (editor) { 477 var header = '', value, styles = ''; 478 if (getDefaultXmlPi(editor)) { 479 var piEncoding = getDefaultEncoding(editor); 480 header += '<?xml version="1.0" encoding="' + (piEncoding ? piEncoding : 'ISO-8859-1') + '" ?>\n'; 481 } 482 header += getDefaultDocType(editor); 483 header += '\n<html>\n<head>\n'; 484 if (value = getDefaultTitle(editor)) { 485 header += '<title>' + value + '</title>\n'; 486 } 487 if (value = getDefaultEncoding(editor)) { 488 header += '<meta http-equiv="Content-Type" content="text/html; charset=' + value + '" />\n'; 489 } 490 if (value = getDefaultFontFamily(editor)) { 491 styles += 'font-family: ' + value + ';'; 492 } 493 if (value = getDefaultFontSize(editor)) { 494 styles += 'font-size: ' + value + ';'; 495 } 496 if (value = getDefaultTextColor(editor)) { 497 styles += 'color: ' + value + ';'; 498 } 499 header += '</head>\n<body' + (styles ? ' style="' + styles + '"' : '') + '>\n'; 500 return header; 501 }; 502 var handleGetContent = function (editor, head, foot, evt) { 503 if (evt.format === 'html' && !evt.selection && (!evt.source_view || !shouldHideInSourceView(editor))) { 504 evt.content = unprotectHtml(global$3.trim(head) + '\n' + global$3.trim(evt.content) + '\n' + global$3.trim(foot)); 505 } 506 }; 507 var setup = function (editor, headState, footState) { 508 editor.on('BeforeSetContent', function (evt) { 509 handleSetContent(editor, headState, footState, evt); 510 }); 511 editor.on('GetContent', function (evt) { 512 handleGetContent(editor, headState.get(), footState.get(), evt); 513 }); 514 }; 515 516 var register = function (editor) { 517 editor.ui.registry.addButton('fullpage', { 518 tooltip: 'Metadata and document properties', 519 icon: 'document-properties', 520 onAction: function () { 521 editor.execCommand('mceFullPageProperties'); 522 } 523 }); 524 editor.ui.registry.addMenuItem('fullpage', { 525 text: 'Metadata and document properties', 526 icon: 'document-properties', 527 onAction: function () { 528 editor.execCommand('mceFullPageProperties'); 529 } 530 }); 531 }; 532 533 function Plugin () { 534 global$4.add('fullpage', function (editor) { 535 var headState = Cell(''), footState = Cell(''); 536 register$1(editor, headState); 537 register(editor); 538 setup(editor, headState, footState); 539 }); 540 } 541 542 Plugin(); 543 544 }());
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |