Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Question Firefox toolbar not working after slight modification

    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:
    Code:
    <?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:
    Code:
    /*
    	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:
    Code:
    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!

  • #2
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    need help ASAP please???

  • #3
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    can anyone here help me>?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •