popup or tooltip called from pagemod, using css from pagemod

<<

enxdtw

Posts: 23

Joined: Fri Sep 30, 2011 3:50 pm

Post Sat Nov 12, 2011 4:47 pm

popup or tooltip called from pagemod, using css from pagemod

Hi,

I would like to get a tooltip displayed from a content script that reads and changes the DOM of a web page (therefore page-mod must be used). The tooltip uses the DOM element and creates a tooltip at that location in the document. The tooltip uses CSS to create the tooltip. It seems that pagemod's can't use CSS (I am right in this thought, if so that is a pretty serious limitation). Anyway I could like the annotater example pass the data out of the page-mod but then I would still have to display the tooltip in the right location next to the text, maybe I could pass out the coordinates relative to the window and and use these coordinates however i dont think this will work as my tooltip code relies on the DOM to create an DOM element on the current page that is formatted to act as the tooltip, however maybe the DOM could come from a panel DOM. Anyway I notice that the annotator addon example code avoids this problem by always having the annotation panel appear in the centre of the window regardless of the highlighted paragraph!

Anyway, Any ideas would be welcome.

Cheers

Dave
<<

enxdtw

Posts: 23

Joined: Fri Sep 30, 2011 3:50 pm

Post Sat Nov 12, 2011 5:53 pm

Re: popup or tooltip called from pagemod, using css from pag

update, I tried to add the css file dynamically to the page-mod using the example here

http://www.javascriptkit.com/javatutors ... tcss.shtml

however still not working
<<

enxdtw

Posts: 23

Joined: Fri Sep 30, 2011 3:50 pm

Post Sun Nov 13, 2011 2:13 am

Re: popup or tooltip called from pagemod, using css from pag

I have discovered that the css does not work, and instead the popup word is simply displayed at the end of the web page with no css formatting (ie popup behaviour) applied.
<<

nagle

Posts: 188

Joined: Fri Oct 23, 2009 10:14 am

Post Sun Nov 13, 2011 11:43 am

Re: popup or tooltip called from pagemod, using css from pag

Try this in your content script:
  Code:
//
//  addGlobalStyle -- add a string of CSS to a document as a global style.
//
function addGlobalStyle(doc, css) {
    var head = doc.getElementsByTagName('head')[0];         // find head element, which should exist
    if (!head) { return; }                                  // defective HTML document
    var style = doc.createElement('style');                 // create <style> element
    style.type = 'text/css';   
    if (style.styleSheet)                                   // for some cross-browser problem
    {   style.styleSheet.cssText = css;                     // attach CSS text to style elt
    } else {
        style.appendChild(document.createTextNode(css));    // attach CSS text to style elt
    }
    head.appendChild(style);                                // attach style element to head
}

//
//  CSS to be added.  Your CSS goes here.
var csstext = ".strating { \
    border-style: dotted; \
    border-width: 1px; \
    position: relative; \
}";

addGlobalStyle(doc, csstext);  // Attach CSS text to head of document

This will attach a string of CSS to the document.
<<

enxdtw

Posts: 23

Joined: Fri Sep 30, 2011 3:50 pm

Post Sun Nov 13, 2011 1:37 pm

Re: popup or tooltip called from pagemod, using css from pag

HI john,

That works great, Million thanks

Cheers

Dave

Return to Add-on SDK & Add-on Builder

Who is online

Users browsing this forum: No registered users

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
CA Gen2 style designed by Vjacheslav Trushkin.