Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
417 lines (336 sloc) 19 KB
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://tabulator/content/tabulator.css" type="text/css"?>
<!DOCTYPE overlay SYSTEM "chrome://tabulator/locale/en-US/tabulatorsidebar.dtd">
<overlay id="tabulator"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="js/tab/browserInit.js"/>
<script type="application/x-javascript" src="js/jquery/jquery-1.4.2.min.js"/>
<script type="application/x-javascript" src="js/jquery/jquery-ui-1.8rc1.custom.min.js"/>
<script type="application/x-javascript" src="js/jquery/jquery.json-1.3.min.js"/> <!-- not used at the moment-->
<script type="application/x-javascript" src="js/jquery/jquery.uri.js"/>
<script type="application/x-javascript" src="js/jquery/jquery.xmlns.js"/>
<script type="application/x-javascript" src="js/jquery/jquery.curie.js"/>
<script type="application/x-javascript" src="js/jquery/jquery.datatype.js"/>
<script type="application/x-javascript" src="js/jquery/jquery.rdf.js"/>
<script type="application/x-javascript" src="js/jquery/jquery.rdfa.js"/>
<script type="application/x-javascript" src="js/tab/sqlite.js"/> <!-- Functions to create an SQLite database-->
<script type="application/x-javascript" src="js/tab/semclip.js"/> <!-- For the Semantic Clipboard -->
<script type="application/x-javascript" src="js/tab/pusbackInterface.js"/> <!-- To talk with the pushback controller hosted at DERI -->
<script type="application/x-javascript" src="js/tab/sources-ext.js"/>
<!-- browser reload hack -->
<script type="application/x-javascript" src="js/tab/refresh_hack.js"/>
<menupopup id="viewSidebarMenu">
<menuitem key="key_openTabulatorSidebar" observes="viewTabulatorSidebar" />
</menupopup>
<keyset id="mainKeyset">
<key id="key_openTabulatorSidebar" command="viewTabulatorSidebar"
key="&openTabulatorSidebar.commandkey;"
modifiers="&openTabulatorSidebar.modifierskey;" />
</keyset>
<broadcasterset id="mainBroadcasterSet">
<broadcaster id="viewTabulatorSidebar"
label="&tabulatorsidebar.title;"
autoCheck="false"
type="checkbox"
group="sidebar"
sidebarurl="chrome://tabulator/content/tabulatorsidebar.xul"
sidebartitle="&tabulatorsidebar.title;"
oncommand="toggleSidebar('viewTabulatorSidebar');" />
</broadcasterset>
<popup id="contentAreaContextMenu">
<menuitem id="context-copyimage-License"
label="&copyImageLicenseCmd.label;"
accesskey="&copyImageLicenseCmd.accesskey;"
insertafter="context-copyimage"
oncommand="copyImageWithLicense();"/>
</popup>
<menupopup id="menu_ToolsPopup">
<menu id="menu_ToolsTabulatorMenu" label="&toolsTabulatorMenu.label;" accesskey="&toolsTabulatorMenu.accesskey;" insertafter="javascriptConsole">
<menupopup id="menu_ToolsTabulatorPopup">
<menuitem id="tabulator_setaccept" label="&tabulatorToggleHeader.label;" accesskey="&tabulatorToggleHeader.accesskey;" type="checkbox" oncommand="toggleSetHeader()"/>
<menuitem id="tabulator_saveSession" label="&tabulatorSaveSession.label;" accesskey="&tabulatorSaveSession.accesskey;" type="checkbox" oncommand="saveSession()"/>
</menupopup>
</menu>
<menuitem label="&tablog.label;" accesskey="&tablog.accesskey;" insertafter="javascriptConsole" oncommand="openTool('chrome://tabulator/content/log.xul','tabulatorlog')"/>
<menuitem label="&tamiconfig.label;" accesskey="&tamiconfig.accesskey;" insertafter="javascriptConsole" oncommand="openTool('chrome://tabulator/content/tami_config.xul','tamiconfig')"/>
</menupopup>
<menupopup id="menu_ToolsPopup">
<menu id="menu_semclip" label="&semclipToggleHeader.label;" accesskey="&semclipToggleHeader.accesskey;" insertafter="menu_ToolsTabulatorMenu">
<menupopup id="semclip">
<menuitem id="any_use" label="&semclipAnyUse.label;" accesskey="&semclipAnyUse.accesskey;" type="checkbox" oncommand="toggleSemClip(event)"/>
<menuitem id="commercial_use" label="&semclipCUse.label;" accesskey="&semclipCUse.accesskey;" type="checkbox" oncommand="toggleSemClip(event)"/>
<menuitem id="non_commercial_use" label="&semclipNCUse.label;" accesskey="&semclipNCUse.accesskey;" type="checkbox" oncommand="toggleSemClip(event)"/>
<menuitem id="derivatives" label="&semclipDUse.label;" accesskey="&semclipDUse.accesskey;" type="checkbox" oncommand="toggleSemClip(event)"/>
<menuitem id="share_alike" label="&semclipSAUse.label;" accesskey="&semclipSAUse.accesskey;" type="checkbox" oncommand="toggleSemClip(event)"/>
<menuitem id="no_use" label="&semclipNoLicense.label;" accesskey="&semclipNoLicense.accesskey;" type="checkbox" oncommand="toggleSemClip(event)"/>
<menuitem id="no_use" label="&semclipNoUse.label;" accesskey="&semclipNoUse.accesskey;" type="checkbox" oncommand="toggleSemClip(event)"/>
</menupopup>
</menu>
</menupopup>
<menupopup id="menu_viewPopup">
<menuitem label="&tabsources.label;" accesskey="&tabsources.accesskey;" insertbefore="fullScreenItem" oncommand="openTool('chrome://tabulator/content/sources.xul','tabulatorsources')"/>
<menuitem label="&tabulatorPageMetadata.label;" insertbefore="fullScreenItem" oncommand="tabulatorShowMetadata(event)"/>
<!-- This should show metdata (was DetectMetdata) timbl-->
</menupopup>
<hbox id="urlbar-icons">
<image id="tabulator-view-metadata" insertbefore="feed-button" onclick="tabulatorShowMetadata(event)"/>
</hbox>
<popupset id="mainPopupSet">
<menupopup id="tabulatorcopyuri">
<menuitem label="Copy URI" oncommand="tabulatorCopyURI()" />
<menuitem label="Load in new tab" oncommand="tabulatorLoadStatusURI()" />
</menupopup>
</popupset>
<statusbar id="status-bar">
<statusbarpanel contextmenu="tabulatorcopyuri" id="tabulator-display" insertafter="statusbar-display" style="display:none"/>
<statusbarpanel id="tabulator-source-count" insertbefore="statusbar-progresspanel" style="display:none"/>
</statusbar>
<script type="application/x-javascript"><![CDATA[
// Create a jQuery $ which will
tabulator.jQuery = $ = function(selector,context){ return new jQuery.fn.init(selector, context || window.content.document); };
$.fn = $.prototype = jQuery.fn;
function openTool(url, type, width, height)
{
width = width || 500;
height = height || 400;
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var toolWindow = wm.getMostRecentWindow(type);
if(!toolWindow)
var w = window.openDialog(url, "_blank", "all=no,width="+width+",height="+height+",scrollbars=yes,resizable=yes,dialog=no");
else
toolWindow.focus();
}
var myCheckbox;
var rdfaData;
var tabulator_init = {
//This is called when the Browser window has finished loading at startup
onLoad : function(loadEvent) {
myCheckbox = document.getElementById("tabulator_setaccept");
var prefManager = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
try {
var value = prefManager.getBoolPref("extensions.tabulator.setheader");
if(value) {
myCheckbox.setAttribute('checked','true');
}
else {
myCheckbox.setAttribute('checked','false');
}
}
catch(e) {
prefManager.setBoolPref("extensions.tabulator.setheader",true);
myCheckbox.setAttribute('checked',true);
}
var tabulatorDisplay = document.getElementById("tabulator-display");
new StatusWidget();
var appcontent = window.document.getElementById('appcontent');
//@@ jambo try to speed up by eliminating the preproc..
//appcontent.addEventListener('DOMContentLoaded', tabulator_init.onDOMContentLoaded, false);
},
//This is called every time a page finishes loading
onDOMContentLoaded : function(event) {
var doc = event.originalTarget;
dump("\npage " + gURLBar.value +" has finished loading");
//Parse RDFa from a document which does not have a DOCType
try{
//Glean all the RDFa out of the page, and cache it (so you don't have to parse the page on each tab switch)
rdfaData = $jq('body', window.content.document).rdf().databank.triples();
}
catch(e){/*no rdfa or some error*/}
}
};
var tGRDDL_NS = 'http://www.w3.org/2003/g/data-view#';
var tRDF_CONTENT_TYPE = {'application/rdf+xml':'XML', 'text/n3':'N3',
'text/turtle':'N3', 'application/x-turtle': 'N3', 'application/n3': 'N3'};
//This gets called when you switch tabs
function tabulatorDetectMetadata(e){
if (typeof tabulator == 'undefined') var tabulator = Components.classes["@dig.csail.mit.edu/tabulator;1"].getService(Components.interfaces.nsISupports).wrappedJSObject;
var kb = tabulator.kb;
var semanticIcon = document.getElementById('tabulator-view-metadata');
try{
var divs = content.document.getElementsByTagName('div');
if (divs.length && divs[0].className.search("TabulatorOutline")!=-1){
//already viewing metadata, so disable the icon
semanticIcon.removeAttribute('metadata');
return;
}
}catch(e){/*no className, etc.*/}
//also do this for HTML with hash uri...maybe don't do that
var doc = kb.sym(content.document.location.href);
var subjectIndex = kb.subjectIndex[doc.hashString()];
var objectIndex = kb.objectIndex[doc.hashString()];
//predicateIndex?? hmm...
var semantics = (subjectIndex? subjectIndex.length:0) + (objectIndex?objectIndex.length:0);
//In the future, when there are many "semantics" of a page, we can show the icon based
//on the amount of semantics
if (semantics) {
semanticIcon.setAttribute('metadata', ''+semantics);
semanticIcon.setAttribute('tooltiptext', semantics+" triples");
return;
}
//GRDDL
try{
doc = content.document; //XML GRDDL
if (doc.documentElement.hasAttributeNS(tGRDDL_NS, 'transformation') ||
doc.getElementsByTagName('head')[0].hasAttribute('profile')){ //think about <html:head> later
semanticIcon.setAttribute('metadata', 'GRDDL');
semanticIcon.setAttribute('tooltiptext', 'GRDDL');
return;
}
}catch(e){/*no doctype, or missing some elements, these are trivial */}
//XHTML+RDFa without profile
//RDFa parsing code is called only if the proper doctype is set
try{
if (doc.doctype.publicId.search('RDF') > 0 || doc.doctype.systemId.search('rdf') >0){ //don't be too strict
semanticIcon.setAttribute('metadata', 'RDFa');
semanticIcon.setAttribute('tooltiptext', 'RDFa');
return;
}
}catch(e){/*no doctype, or missing some elements, these are trivial */}
//RDFa without the DOCType
if (rdfaData && rdfaData.length >0){
for (i = 0; i < rdfaData.length; i += 1) {
t = rdfaData[i];
s = t.subject.value.toString();
p = t.property.value.toString();
o = t.object.value.toString();
dump(s + "\t" + p + "\t" + o + "\n");
var why = gURLBar.value;
kb.add(kb.sym(s), kb.sym(p), kb.sym(o), kb.sym(why));
}
semanticIcon.setAttribute('metadata', 'RDFa');
semanticIcon.setAttribute('tooltiptext', 'RDFa');
semanticIcon.addEventListener('click', pumpRDFa, false);
//Added for the Semantic Clipboard (see semclip.js) - show all the images that can be copied with a license
//findImagesThatCanBeCopied(); //@@@ this might be the source of the recursive call in jquery
return;
}
//This I(who?) consider non-standard
try{
var links = doc.getElementsByTagName('link');
for (var x=0;x < links.length; x++) {
if (links[x].getAttribute('type') in tRDF_CONTENT_TYPE){
semanticIcon.setAttribute('metadata', 'WildCard');
semanticIcon.setAttribute('tooltiptext', 'link element');
return;
}
}
}catch(e){/*no doctype, or missing some elements, these are trivial */}
//finally there's no semantics
semanticIcon.removeAttribute('metadata');
}
//@@ jambo try to speedup by eliminating the icon.
//getBrowser().tabContainer.addEventListener("TabSelect", tabulatorDetectMetadata,true);
pumpRDFa = function(e){
// if (typeof tabulator == 'undefined') var tabulator = Components.classes["@dig.csail.mit.edu/tabulator;1"].getService(Components.interfaces.nsISupports).wrappedJSObject;
var uri = gURLBar.value;
// From init/init.js
var uuidGenerator =
Components.classes["@mozilla.org/uuid-generator;1"]
.getService(Components.interfaces.nsIUUIDGenerator);
var uuid = uuidGenerator.generateUUID();
var uuidString = uuid.toString();
tabulator.requestUUIDs[uuidString] = uri;
var doc = window.content.document;
//Remove all the style sheet elements and scripts
$jq('head', doc).empty();
$jq('body', doc).empty();
$jq('html', doc).attr("id","docHTML");
// doc.innerHTML = tabulator.outlineTemplate; // Reset doc entirely
//@@ from jambo, WARNING ! the way that this code operates HAS BEEN CHANGED
// a UUID nonce is now used to identify the document to display..
// I am not sure if this will affect the execution of this code when
// it gets re-enabled. If you experience issues, feel free to email
// me and I will help resolve it.
// For refs on how to do this, see init/init.js, where
// tabulator.requestUUIDs is used.
$jq('head', doc).append("<title>Data View</title>\n"+
" <link rel=\"stylesheet\" href=\"chrome://tabulator/content/tabbedtab.css\" type=\"text/css\" />\n"+
" <link rel=\"stylesheet\" href=\"chrome://tabulator/content/js/widgets/style.css\" type=\"text/css\" />\n"
);
$jq('body', doc).append("<div class=\"TabulatorOutline\" id=\"DummyUUID\">\n"+
"<table id=\"outline\"></table>\n"+
"</div>\n"
);
//Add the Tabulator outliner
var outline = new tabulator.OutlineObject(doc)
var a =$jq('.TabulatorOutline', doc).attr('id', uuidString);
outline.init();
var nsIURI = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService).newURI(uri, null, null); //ToDo: make sure the encoding is correct
gBrowser.getBrowserForDocument(doc).webNavigation.setCurrentURI(nsIURI);
var queryButton = doc.createElement('input');
queryButton.setAttribute('id','queryButton');
queryButton.setAttribute('style','display:none;');
queryButton.setAttribute('type','button');
queryButton.setAttribute('value','Find All');
doc.body.appendChild(queryButton);
queryButton.addEventListener('click',outline.viewAndSaveQuery,false);
outline.GotoSubject(tabulator.kb.sym(uri),true);
}
// Whatever the thing is, show the tabulator outine view of it.
// Even if it is a web page which didn't load, show it in outline view
function tabulatorShowMetadata(e){
//canonizeUrl(e,{});
if (typeof tabulator == 'undefined') var tabulator = Components.classes["@dig.csail.mit.edu/tabulator;1"].getService(Components.interfaces.nsISupports).wrappedJSObject;
tabulator.metadataURI = gURLBar.value;
/*
//before I know more about how cache works in Firefox, cache the DOM
tabulator.cacheDOM = content.document;
tabulator.log.warn('storing cache %s to tabulator.cacheDOM', tabulator.cacheDOM); // @@why? timbl
*/
//handleURLBarCommand(e);
tabulator.pumpRDFa(e);
}
function tabulatorCopyURI() {
gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].
getService(Components.interfaces.nsIClipboardHelper);
gClipboardHelper.copyString(document.getElementById("tabulator-display").label);
}
function tabulatorLoadStatusURI() {
var tabURIToLoad = document.getElementById("tabulator-display").label;
gBrowser.selectedTab = gBrowser.addTab(tabURIToLoad);
}
function toggleSetHeader() {
var checked = myCheckbox.getAttribute('checked');
var prefManager = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
try {
if(checked=='true')
prefManager.setBoolPref("extensions.tabulator.setheader",true);
else
prefManager.setBoolPref("extensions.tabulator.setheader",false);
} catch(e) {
alert("Error: Could not set the HTTP Accept header preference.\n Please report error to http://dig.csail.mit.edu/issues/tabulator/");
}
}
function saveSession() {
if (typeof tabulator == 'undefined') var tabulator = Components.classes["@dig.csail.mit.edu/tabulator;1"].
getService(Components.interfaces.nsISupports).wrappedJSObject;
var sz = tabulator.rdf.Serializer(tabulator.kb);
sz.writeStore(dump); // @@ Later, chose filename to dump to
alert("Store dumped to log.");
}
window.addEventListener("load",tabulator_init.onLoad, false);
]]></script>
<script type="application/x-javascript" src="js/tab/statuswidget.js" ></script>
<!-- New Addition -->
<menupopup id="viewSidebarMenu">
<menuitem key="key_openPOLICYSidebar" observes="viewPOLICYSidebar" />
</menupopup>
<keyset id="mainKeyset">
<key id="key_openPOLICYSidebar" command="viewPOLICYSidebar"
key="&openPOLICYSidebar.commandkey;"
modifiers="&openPOLICYSidebar.modifierskey;" />
</keyset>
<broadcasterset id="mainBroadcasterSet">
<broadcaster id="viewPOLICYSidebar"
label="&policysidebar.title;"
autoCheck="false"
type="checkbox"
group="sidebar"
sidebarurl="chrome://tabulator/content/policy_parser.xul"
sidebartitle="&policysidebar.title;"
oncommand="toggleSidebar('viewPOLICYSidebar');" />
</broadcasterset>
</overlay>