...

View Full Version : Firefox toolbar not working after slight modification



jarv
09-04-2008, 04:08 PM
a collegue of mine built a firefox toolbar which works, he used the tutorial from here:

http://www.borngeek.com/firefox/toolbar-tutorial/

I slightly modified it today and by removing a toolbarbutton I then repackaged the toolbar as stated how to in chapter 7 of the tutorial reinstalled it and now it doesn't work?!

XUL file:


<?xml version="1.0"?>
<?xml-stylesheet href="chrome://cmstoolbar/skin/cmstoolbar.css"
type="text/css"?>
<overlay id="CmsTB-Overlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<script type="application/x-javascript" src="chrome://cmstoolbar/content/cmstoolbar.js" />

<toolbox id="navigator-toolbox">
<toolbar id="CmsTB-Toolbar" toolbarname="CMS Toolbar" accesskey="T"
class="chromeclass-toolbar" context="toolbar-context-menu"
hidden="false" persist="hidden">

<toolbarbutton id="CmsTB-AVERT-Button" tooltiptext="AVERT"
label="AVERT" oncommand="CmsTB_LoadURL('http://www.avert.org')" />
<toolbarseparator />

<toolbarbutton id="CmsTB-CMS-Button" tooltiptext="CMS"
label="CMS" oncommand="CmsTB_LoadURL('http://cms.avert.org')" />
<toolbarseparator />

<toolbarbutton id="CmsTB-Switch-Button" tooltiptext="Local Content"
label="Switch (not enabled)" oncommand="CmsTB_SwapLocalContent(event, 'web')" disabled="true" />
<toolbarseparator />

</toolbar>
</toolbox>

</overlay>


JavaScript file:


/*
Event listener, waits for page to load. When it does, triggers function CmsTB_OnPageLoad()
*/
window.addEventListener("load", function() { myExtension.init(); }, false);

var myExtension = {
init: function() {
var appcontent = document.getElementById("appcontent"); // browser
if(appcontent)
appcontent.addEventListener("DOMContentLoaded", this.onPageLoad, true);
},

onPageLoad: function(aEvent) {
var doc = aEvent.originalTarget; // doc is document that triggered "onload" event
CmsTB_OnPageLoad(doc.location);
}
}

/*
Triggered when a page loads (see above)
If the url is avert.org
*/
function CmsTB_OnPageLoad(url_object) {

url = url_object.toString();

//if the url is www.avert.org, enable the switch button, set text to local-content switch
if(url.indexOf("www.avert.org") != -1) {

var CmsTB_button = document.getElementById("CmsTB-Switch-Button");
CmsTB_button.disabled = false;
CmsTB_button.label = "Switch to local content";

//hide edit button
var CmsTB_edit_button = document.getElementById("CmsTB-Edit-Page-Button");
CmsTB_edit_button.disabled = true;
CmsTB_edit_button.label = "Edit this page (not enabled)";
}
//if the url is local-content.avert.org, enable the switch button, set text to www switch
else if(url.indexOf("local-content.avert.org") != -1) {
var CmsTB_button = document.getElementById("CmsTB-Switch-Button");
CmsTB_button.disabled = false;
CmsTB_button.label = "Switch to live site";

//show edit button
var CmsTB_edit_button = document.getElementById("CmsTB-Edit-Page-Button");
CmsTB_edit_button.disabled = false;
CmsTB_edit_button.label = "Edit this page";
}
//otherwise ensure button is disabled
else {
var CmsTB_button = document.getElementById("CmsTB-Switch-Button");
CmsTB_button.disabled = true;
CmsTB_button.label = "Switch (not enabled)";

//hide edit button
var CmsTB_edit_button = document.getElementById("CmsTB-Edit-Page-Button");
CmsTB_edit_button.disabled = true;
CmsTB_edit_button.label = "Edit this page (not enabled)";

}

}

function CmsTB_SwapLocalContent()
{
//get url in current window
url_object = window._content.document.location;
url = url_object.toString();

//change the url from www to local-content if its www.avert.org
if(url.indexOf("www.avert.org") != -1) {
new_url = url.replace('www', 'local-content');
window.content.document.location = new_url;
} else if(url.indexOf("local-content.avert.org") != -1) {
new_url = url.replace('local-content', 'www');
window.content.document.location = new_url;
}
}

/*
Takes the current url on local_content.avert.org and forwards it to the CMS for editing
*/
function CmsTB_EditPage()
{
//get url in current window
url_object = window._content.document.location;
url = url_object.toString();

//url should now be http://local-content.avert.org/pagename.htm

//change the url for local-content to cms
if(url.indexOf("local-content.avert.org") != -1) {
//replace local-content with cms
new_url = url.replace('local-content', 'cms');
//add the path webpages/edit/ after avert.org
new_url = new_url.replace('.org/', '.org/webpages/edit/');
//send the new url to the window
window.content.document.location = new_url;
}
}

/*
Button disabled
*/

////////////////////////////////////////////////////////////////////////////////
// The CmsTB_LoadURL() function loads the specified URL in the browser.
////////////////////////////////////////////////////////////////////////////////
function CmsTB_LoadURL(url)
{
// Set the browser window's location to the incoming URL
window._content.document.location = url;

// Make sure that we get the focus
window.content.focus();
}



chrome manifest file:


content cmstoolbar chrome/content/
overlay chrome://browser/content/browser.xul chrome://cmstoolbar/content/cmstoolbar.xul
skin cmstoolbar classic/1.0 chrome/skin/

Can someone please help me, I have been trying to do this all day!

jarv
09-04-2008, 05:06 PM
need help ASAP please???

jarv
09-05-2008, 09:26 AM
can anyone here help me>?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum