/** * $Id$ * * @author Moxiecode * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved. * * The contents of this file will be wrapped in a class later on. */ /**#@+ * @member TinyMCE_Engine * @method */ tinyMCE.add(TinyMCE_Engine, { /** * Parses a URL in to its diffrent components. * * @param {string} url_str URL string to parse into a URL object. * @return URL object based on input string. * @type TinyMCE_URL_Item */ parseURL : function(url_str) { var urlParts = [], i, pos, lastPos, chr; if (url_str) { // Parse protocol part pos = url_str.indexOf('://'); if (pos != -1) { urlParts.protocol = url_str.substring(0, pos); lastPos = pos + 3; } // Find port or path start for (i=lastPos; i= strTok2.length) { for (i=0; i= strTok2.length || strTok1[i] != strTok2[i]) { breakPoint = i + 1; break; } } } if (strTok1.length < strTok2.length) { for (i=0; i= strTok1.length || strTok1[i] != strTok2[i]) { breakPoint = i + 1; break; } } } if (breakPoint == 1) return targetURL.path; for (i=0; i<(strTok1.length-(breakPoint-1)); i++) outPath += "../"; for (i=breakPoint-1; i=0; i--) { if (baseURLParts[i].length == 0) continue; newBaseURLParts[newBaseURLParts.length] = baseURLParts[i]; } baseURLParts = newBaseURLParts.reverse(); // Merge relURLParts chunks newRelURLParts = []; numBack = 0; for (i=relURLParts.length-1; i>=0; i--) { if (relURLParts[i].length == 0 || relURLParts[i] == ".") continue; if (relURLParts[i] == '..') { numBack++; continue; } if (numBack > 0) { numBack--; continue; } newRelURLParts[newRelURLParts.length] = relURLParts[i]; } relURLParts = newRelURLParts.reverse(); // Remove end from absolute path len = baseURLParts.length-numBack; absPath = (len <= 0 ? "" : "/") + baseURLParts.slice(0, len).join('/') + "/" + relURLParts.join('/'); start = ""; end = ""; // Build output URL relURL.protocol = baseURL.protocol; relURL.host = baseURL.host; relURL.port = baseURL.port; // Re-add trailing slash if it's removed if (relURL.path.charAt(relURL.path.length-1) == "/") absPath += "/"; relURL.path = absPath; return this.serializeURL(relURL); }, /** * Converts the specified URL based in TinyMCE configuration settings. * * @param {string} url URL to convert based on config. * @param {HTMLElement} node HTML element that holds the URL. * @param {boolean} on_save Is this convertion the final output URL. * @return Converted URL string. * @type string */ convertURL : function(url, node, on_save) { var dl = document.location, start, portPart, urlParts, baseUrlParts, tmpUrlParts, curl; var prot = dl.protocol, host = dl.hostname, port = dl.port; // Pass through file protocol if (prot == "file:") return url; // Something is wrong, remove weirdness url = tinyMCE.regexpReplace(url, '(http|https):///', '/'); // Mailto link or anchor (Pass through) if (url.indexOf('mailto:') != -1 || url.indexOf('javascript:') != -1 || /^[ \t\r\n\+]*[#\?]/.test(url)) return url; // Fix relative/Mozilla if (!tinyMCE.isIE && !on_save && url.indexOf("://") == -1 && url.charAt(0) != '/') return tinyMCE.settings.base_href + url; // Handle relative URLs if (on_save && tinyMCE.getParam('relative_urls')) { curl = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, url); if (curl.charAt(0) == '/') curl = tinyMCE.settings.document_base_prefix + curl; urlParts = tinyMCE.parseURL(curl); tmpUrlParts = tinyMCE.parseURL(tinyMCE.settings.document_base_url); // Force relative if (urlParts.host == tmpUrlParts.host && (urlParts.port == tmpUrlParts.port)) return tinyMCE.convertAbsoluteURLToRelativeURL(tinyMCE.settings.document_base_url, curl); } // Handle absolute URLs if (!tinyMCE.getParam('relative_urls')) { urlParts = tinyMCE.parseURL(url); baseUrlParts = tinyMCE.parseURL(tinyMCE.settings.base_href); // Force absolute URLs from relative URLs url = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, url); // If anchor and path is the same page if (urlParts.anchor && urlParts.path == baseUrlParts.path) return "#" + urlParts.anchor; } // Remove current domain if (tinyMCE.getParam('remove_script_host')) { start = ""; portPart = ""; if (port !== '') portPart = ":" + port; start = prot + "//" + host + portPart + "/"; if (url.indexOf(start) == 0) url = url.substring(start.length-1); } return url; }, /** * Converts all img and a element URLs to absolute URLs. This will use the mce_src or mce_href attribute values * if they are provided. This function is used when the editor is initialized. * * @param {HTMLElement} body HTML element to convert all URLs in. */ convertAllRelativeURLs : function(body) { var i, elms, src, href, mhref, msrc; // Convert all image URL:s to absolute URL elms = body.getElementsByTagName("img"); for (i=0; i