Changeset 2770
- Timestamp:
- 11/11/07 16:12:19 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tracwysiwygplugin/0.10/tracwysiwyg/htdocs/wysiwyg.js
r2765 r2770 91 91 var l = window.location; 92 92 var css = {}; 93 css.trac = TracWysiwyg.trac BasePath + "chrome/common/css/trac.css";94 css.editor = TracWysiwyg.trac BasePath+ "chrome/tracwysiwyg/editor.css";93 css.trac = TracWysiwyg.tracPaths.htdocs + "css/trac.css"; 94 css.editor = TracWysiwyg.tracPaths.base + "chrome/tracwysiwyg/editor.css"; 95 95 var html = [ 96 96 '<!DOCTYPE html PUBLIC', … … 2598 2598 2599 2599 TracWysiwyg.count = 0; 2600 TracWysiwyg.tracBasePath = null; 2601 2602 TracWysiwyg.getTracBasePath = function() { 2603 var links = document.getElementsByTagName("link"); 2604 var length = links.length; 2605 for (var i = 0; i < length; i++) { 2600 TracWysiwyg.tracPaths = null; 2601 2602 TracWysiwyg.getTracPaths = function() { 2603 var paths = {}; 2604 2605 var d = document; 2606 var head = d.getElementsByTagName("head")[0]; 2607 var regexpPath = /^[\w.+-]+:\/\/[^\/:]+(?::\d+)?/; 2608 var length, i; 2609 2610 var scripts = head.getElementsByTagName("script"); 2611 length = scripts.length; 2612 var wysiwygjs = "/chrome/tracwysiwyg/wysiwyg.js"; 2613 for (i = 0; i < length; i++) { 2614 var src = scripts[i].src || ""; 2615 var index = src.length - wysiwygjs.length; 2616 if (src.substring(index) == wysiwygjs) { 2617 paths.base = src.substring(0, index).replace(regexpPath, "") + "/"; 2618 break; 2619 } 2620 } 2621 if (!paths.base) { 2622 return null; 2623 } 2624 2625 var links = head.getElementsByTagName("link"); 2626 var traccss = "/css/trac.css"; 2627 length = links.length; 2628 for (i = 0; i < length; i++) { 2606 2629 var link = links[i]; 2607 2630 var rel = (link.getAttribute("rel") || "").toLowerCase(); 2608 2631 var href = link.getAttribute("href") || ""; 2609 if (rel == "stylesheet" && /^(.*)\/chrome\/common\/css\/trac\.css$/.test(href)) { 2610 return RegExp.$1.replace(/[\w.+-]+:\/\/[^:]+(?::\d+)?/, "") + "/"; 2611 } 2612 } 2613 return null; 2632 var index = href.length - traccss.length; 2633 if (rel == "stylesheet" && href.substring(index) == traccss) { 2634 paths.htdocs = href.substring(0, index) + "/"; 2635 break; 2636 } 2637 } 2638 if (!paths.htdocs) { 2639 return null; 2640 } 2641 2642 return paths; 2614 2643 }; 2615 2644 … … 2654 2683 expires.setTime(expires.getTime() + 365 * 86400 * 1000); 2655 2684 var pieces = [ "tracwysiwyg=" + mode, 2656 "path=" + TracWysiwyg.trac BasePath,2685 "path=" + TracWysiwyg.tracPaths.base, 2657 2686 "expires=" + expires.toUTCString() ]; 2658 2687 document.cookie = pieces.join("; "); … … 2698 2727 TracWysiwyg.quickSearchURL = function(link) { 2699 2728 if (!/^(?:(?:https?|ftp|mailto|file):|[\/.#])/.test(link)) { 2700 link = TracWysiwyg.trac BasePath+ "search?q=" + encodeURIComponent(link);2729 link = TracWysiwyg.tracPaths.base + "search?q=" + encodeURIComponent(link); 2701 2730 } 2702 2731 return link; … … 2723 2752 return; 2724 2753 } 2725 TracWysiwyg.trac BasePath = TracWysiwyg.getTracBasePath();2726 if (!TracWysiwyg.trac BasePath) {2754 TracWysiwyg.tracPaths = TracWysiwyg.getTracPaths(); 2755 if (!TracWysiwyg.tracPaths) { 2727 2756 return; 2728 2757 } tracwysiwygplugin/0.11/tracwysiwyg/htdocs/wysiwyg.js
r2765 r2770 91 91 var l = window.location; 92 92 var css = {}; 93 css.trac = TracWysiwyg.trac BasePath + "chrome/common/css/trac.css";94 css.editor = TracWysiwyg.trac BasePath+ "chrome/tracwysiwyg/editor.css";93 css.trac = TracWysiwyg.tracPaths.htdocs + "css/trac.css"; 94 css.editor = TracWysiwyg.tracPaths.base + "chrome/tracwysiwyg/editor.css"; 95 95 var html = [ 96 96 '<!DOCTYPE html PUBLIC', … … 2598 2598 2599 2599 TracWysiwyg.count = 0; 2600 TracWysiwyg.tracBasePath = null; 2601 2602 TracWysiwyg.getTracBasePath = function() { 2603 var links = document.getElementsByTagName("link"); 2604 var length = links.length; 2605 for (var i = 0; i < length; i++) { 2600 TracWysiwyg.tracPaths = null; 2601 2602 TracWysiwyg.getTracPaths = function() { 2603 var paths = {}; 2604 2605 var d = document; 2606 var head = d.getElementsByTagName("head")[0]; 2607 var regexpPath = /^[\w.+-]+:\/\/[^\/:]+(?::\d+)?/; 2608 var length, i; 2609 2610 var scripts = head.getElementsByTagName("script"); 2611 length = scripts.length; 2612 var wysiwygjs = "/chrome/tracwysiwyg/wysiwyg.js"; 2613 for (i = 0; i < length; i++) { 2614 var src = scripts[i].src || ""; 2615 var index = src.length - wysiwygjs.length; 2616 if (src.substring(index) == wysiwygjs) { 2617 paths.base = src.substring(0, index).replace(regexpPath, "") + "/"; 2618 break; 2619 } 2620 } 2621 if (!paths.base) { 2622 return null; 2623 } 2624 2625 var links = head.getElementsByTagName("link"); 2626 var traccss = "/css/trac.css"; 2627 length = links.length; 2628 for (i = 0; i < length; i++) { 2606 2629 var link = links[i]; 2607 2630 var rel = (link.getAttribute("rel") || "").toLowerCase(); 2608 2631 var href = link.getAttribute("href") || ""; 2609 if (rel == "stylesheet" && /^(.*)\/chrome\/common\/css\/trac\.css$/.test(href)) { 2610 return RegExp.$1.replace(/[\w.+-]+:\/\/[^:]+(?::\d+)?/, "") + "/"; 2611 } 2612 } 2613 return null; 2632 var index = href.length - traccss.length; 2633 if (rel == "stylesheet" && href.substring(index) == traccss) { 2634 paths.htdocs = href.substring(0, index) + "/"; 2635 break; 2636 } 2637 } 2638 if (!paths.htdocs) { 2639 return null; 2640 } 2641 2642 return paths; 2614 2643 }; 2615 2644 … … 2654 2683 expires.setTime(expires.getTime() + 365 * 86400 * 1000); 2655 2684 var pieces = [ "tracwysiwyg=" + mode, 2656 "path=" + TracWysiwyg.trac BasePath,2685 "path=" + TracWysiwyg.tracPaths.base, 2657 2686 "expires=" + expires.toUTCString() ]; 2658 2687 document.cookie = pieces.join("; "); … … 2698 2727 TracWysiwyg.quickSearchURL = function(link) { 2699 2728 if (!/^(?:(?:https?|ftp|mailto|file):|[\/.#])/.test(link)) { 2700 link = TracWysiwyg.trac BasePath+ "search?q=" + encodeURIComponent(link);2729 link = TracWysiwyg.tracPaths.base + "search?q=" + encodeURIComponent(link); 2701 2730 } 2702 2731 return link; … … 2723 2752 return; 2724 2753 } 2725 TracWysiwyg.trac BasePath = TracWysiwyg.getTracBasePath();2726 if (!TracWysiwyg.trac BasePath) {2754 TracWysiwyg.tracPaths = TracWysiwyg.getTracPaths(); 2755 if (!TracWysiwyg.tracPaths) { 2727 2756 return; 2728 2757 }
