2006-09-14 09:58:52 +04:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Doron Rosenberg (doronr@naboonline.com)
|
|
|
|
*/
|
|
|
|
|
2006-09-14 09:57:50 +04:00
|
|
|
var gBrowser = null;
|
2006-09-14 09:49:26 +04:00
|
|
|
var appCore = null;
|
2006-09-14 10:00:16 +04:00
|
|
|
var gPrefs = null;
|
|
|
|
|
|
|
|
try {
|
2006-09-14 10:00:46 +04:00
|
|
|
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
|
2006-09-14 10:00:45 +04:00
|
|
|
.getService(Components.interfaces.nsIPrefService);
|
|
|
|
gPrefs = prefService.getBranch(null);
|
2006-09-14 10:00:16 +04:00
|
|
|
} catch (ex) {
|
|
|
|
}
|
2006-09-14 09:49:26 +04:00
|
|
|
|
2006-09-14 09:49:25 +04:00
|
|
|
function onLoadViewSource()
|
|
|
|
{
|
2006-09-14 09:54:56 +04:00
|
|
|
viewSource(window.arguments[0]);
|
2006-09-14 09:58:52 +04:00
|
|
|
window._content.focus();
|
2006-09-14 09:54:56 +04:00
|
|
|
}
|
1999-09-02 08:08:22 +04:00
|
|
|
|
2006-09-14 09:57:50 +04:00
|
|
|
function getBrowser()
|
|
|
|
{
|
|
|
|
if (!gBrowser)
|
|
|
|
gBrowser = document.getElementById("content");
|
|
|
|
return gBrowser;
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:54:56 +04:00
|
|
|
function viewSource(url)
|
|
|
|
{
|
|
|
|
if (!url)
|
2006-09-14 09:55:24 +04:00
|
|
|
return false; // throw Components.results.NS_ERROR_FAILURE;
|
2006-09-14 09:55:55 +04:00
|
|
|
|
2006-09-14 09:54:56 +04:00
|
|
|
try {
|
2006-09-14 09:55:55 +04:00
|
|
|
appCore = Components.classes["@mozilla.org/appshell/component/browser/instance;1"]
|
|
|
|
.createInstance(Components.interfaces.nsIBrowserInstance);
|
2006-09-14 09:55:50 +04:00
|
|
|
|
|
|
|
// Initialize browser instance..
|
|
|
|
appCore.setWebShellWindow(window);
|
2006-09-14 09:55:55 +04:00
|
|
|
} catch(ex) {
|
|
|
|
// Give up.
|
|
|
|
window.close();
|
|
|
|
return false;
|
2006-09-14 09:54:56 +04:00
|
|
|
}
|
2006-09-14 09:49:26 +04:00
|
|
|
|
2006-09-14 09:54:56 +04:00
|
|
|
try {
|
2006-09-14 09:55:55 +04:00
|
|
|
if ("arguments" in window && window.arguments.length >= 2) {
|
|
|
|
if (window.arguments[1].indexOf('charset=') != -1) {
|
|
|
|
var arrayArgComponents = window.arguments[1].split('=');
|
|
|
|
if (arrayArgComponents) {
|
2006-09-14 10:02:22 +04:00
|
|
|
//we should "inherit" the charset menu setting in a new window
|
|
|
|
getMarkupDocumentViewer().defaultCharacterSet = arrayArgComponents[1];
|
2006-09-14 09:55:55 +04:00
|
|
|
}
|
2006-09-14 09:54:56 +04:00
|
|
|
}
|
2006-09-14 09:55:55 +04:00
|
|
|
}
|
|
|
|
} catch(ex) {
|
2006-09-14 09:54:56 +04:00
|
|
|
}
|
2006-09-14 09:49:26 +04:00
|
|
|
|
2006-09-14 09:54:56 +04:00
|
|
|
var loadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
|
2006-09-14 09:56:46 +04:00
|
|
|
var viewSrcUrl = "view-source:" + url;
|
2006-09-14 10:01:32 +04:00
|
|
|
getBrowser().webNavigation.loadURI(viewSrcUrl, loadFlags, null, null, null);
|
2006-09-14 10:00:16 +04:00
|
|
|
|
|
|
|
//check the view_source.wrap_long_lines pref and set the menuitem's checked attribute accordingly
|
2006-09-14 10:00:45 +04:00
|
|
|
if (gPrefs) {
|
2006-09-14 10:00:16 +04:00
|
|
|
try {
|
2006-09-14 10:00:45 +04:00
|
|
|
var wraplonglinesPrefValue = gPrefs.getBoolPref("view_source.wrap_long_lines");
|
2006-09-14 10:00:16 +04:00
|
|
|
|
|
|
|
if (wraplonglinesPrefValue)
|
|
|
|
document.getElementById('menu_wrapLongLines').setAttribute("checked", "true");
|
|
|
|
} catch (ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:58:51 +04:00
|
|
|
window._content.focus();
|
2006-09-14 09:54:56 +04:00
|
|
|
return true;
|
|
|
|
}
|
2006-09-14 09:49:26 +04:00
|
|
|
|
2006-09-14 10:01:41 +04:00
|
|
|
function ViewSourceClose()
|
2006-09-14 09:51:57 +04:00
|
|
|
{
|
2006-09-14 10:01:41 +04:00
|
|
|
window.close();
|
2006-09-14 09:51:57 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 09:58:52 +04:00
|
|
|
// Strips the |view-source:| for editPage()
|
|
|
|
function ViewSourceEditPage()
|
2006-09-14 09:57:50 +04:00
|
|
|
{
|
2006-09-14 09:58:52 +04:00
|
|
|
var url = window._content.location.href;
|
|
|
|
url = url.substring(12,url.length);
|
|
|
|
editPage(url,window, false);
|
2006-09-14 09:57:50 +04:00
|
|
|
}
|
2006-09-14 10:00:16 +04:00
|
|
|
|
2006-09-14 10:02:06 +04:00
|
|
|
// Strips the |view-source:| for saveURL()
|
|
|
|
function ViewSourceSavePage()
|
|
|
|
{
|
|
|
|
var url = window._content.document.location.href;
|
|
|
|
url = url.substring(12,url.length);
|
|
|
|
|
|
|
|
saveURL(url, null, "SaveLinkTitle");
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:00:16 +04:00
|
|
|
//function to toggle long-line wrapping and set the view_source.wrap_long_lines
|
|
|
|
//pref to persist the last state
|
|
|
|
function wrapLongLines()
|
|
|
|
{
|
|
|
|
//get the first pre tag which surrounds the entire viewsource content
|
|
|
|
var myWrap = window._content.document.getElementById('viewsource');
|
|
|
|
|
|
|
|
if (myWrap.className == '')
|
|
|
|
myWrap.className = 'wrap';
|
|
|
|
else myWrap.className = '';
|
|
|
|
|
|
|
|
//since multiple viewsource windows are possible, another window could have
|
|
|
|
//affected the pref, so instead of determining the new pref value via the current
|
|
|
|
//pref value, we use myWrap.className
|
|
|
|
if (gPrefs){
|
|
|
|
try {
|
2006-09-14 10:00:45 +04:00
|
|
|
if (myWrap.className == '') {
|
|
|
|
gPrefs.setBoolPref("view_source.wrap_long_lines", false);
|
2006-09-14 10:00:16 +04:00
|
|
|
}
|
|
|
|
else {
|
2006-09-14 10:00:45 +04:00
|
|
|
gPrefs.setBoolPref("view_source.wrap_long_lines", true);
|
2006-09-14 10:00:16 +04:00
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|