Show
Ignore:
Timestamp:
09/03/08 01:46:18 (4 months ago)
Author:
maripo
Message:

XSLT で小窓の中身を整形できるように

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/userscripts/poptip.user.js

    r18671 r18692  
    313120080824 0.0.10 Error handling (HTTP error / HTML node error) 
    3232               Add a rule (Tabelog) 
     3320080824 0.1.0 XSLT option for popup area 
     34 
     35== TODO == 
     36+ Write some XSLT examples 
     37+ Change the icon to smaller one 
     38+ Re-create as a Firefox extension 
    3339 
    3440*/ 
    3541 
    36 var VERSION = '0.0.10'; 
     42var VERSION = '0.1.0'; 
    3743var DEFAULT_DELAY_MSEC = 400; 
    3844var HIDE_DELAY_MSEC = 400; 
     
    4046var ERROR_MESSAGE_POPUP_ELEMENT_EMPTY = 'Error : No such node'; 
    4147var ERROR_MESSAGE_HTTP = 'HTTP Error'; 
    42  
    43 var popupTil = null; 
    44  
    4548 
    4649// == IMAGE == 
     
    166169        linkElement: '//a[@class="keyword"]', 
    167170        popupElement: '//div[@class="box-curve-bar"]//div[@class="section"]', 
    168         delay: 1000, 
    169         stripe: true, 
     171        delay: 1500, 
     172        stripe: false, 
    170173        style: { 
    171174            fontSize: '80%', 
     
    339342            border: '1px solid #444' 
    340343        } 
     344    }, 
     345    { 
     346        description: 'XSLT Example', 
     347        url: '^http://www\\.example\\.com/.*', 
     348        linkElement: 'id("hoge")', 
     349        popupElement: 'id("fuga")', 
     350        disabled: true, 
     351        xslt : <><![CDATA[<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> 
     352<xsl:output method='html'/> 
     353<xsl:template match='/'> 
     354<div>EXAMPLE</div> 
     355</xsl:template> 
     356</xsl:stylesheet> 
     357]]></> 
    341358    } 
    342359 
     
    427444                        style:SITEINFO[i].style, 
    428445                        containerHTML:SITEINFO[i].containerHTML, 
     446                        xslt:SITEINFO[i].xslt, 
    429447                        delay:SITEINFO[i].delay 
    430448                    }); 
     
    477495                            if (http.status == 200) { 
    478496                                var elementList = getElementsByXPath(popupElementXPath, xml); 
    479  
    480                                 if (elementList.length > 0) { 
     497                                if (option.xslt) { 
     498                                    // apply XSLT stylesheet 
     499                                    var template = new XSLTProcessor(); 
     500                                    var stylesheet = createXsltDocumtntByString(option.xslt); 
     501                                    template.importStylesheet (stylesheet.documentElement.firstChild); 
     502                                    var result = template.transformToFragment(xml, document); 
     503                                    elmContainer.appendChild(result); 
     504                                } else if (elementList.length > 0) { 
    481505                                    // "popupElement" found 
    482506                                    if (option.containerHTML) { 
     
    506530                            popupAreaObj.append(elmContainer); 
    507531                            popupAreaObj.show(targetElement); 
    508                     } catch (ex) {} 
     532                    } catch (ex) { 
     533                    } 
    509534                 } 
    510535            }; 
     
    567592 
    568593/* 
    569  Utilities (cited from AutoPagerize) 
     594 Utilities  
    570595*/ 
    571  
     596function createXsltDocumtntByString(str) { 
     597    var htmlDoc  = document.implementation.createDocument(null, 'html', null); 
     598    var range = document.createRange(); 
     599    range.selectNodeContents(htmlDoc.documentElement); 
     600    htmlDoc.documentElement.appendChild(range.createContextualFragment(str)); 
     601    return htmlDoc; 
     602} 
     603 
     604/* 
     605cited from AutoPagerize 
     606*/ 
    572607function createHTMLDocumentByString(str) { 
    573608    var html = str.replace(/^[\s\S]*?<html(?:\s[^>]*)?>\s*|\s*<\/html\s*>[\S\s]*$/ig, '');