Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<xbl xmlns="http://www.w3.org/ns/xbl" xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:ib="http://brett-zamir.me/ns/ibrowser">
<binding element="ib|browser" id="browser">
<template allow-selectors-through="true" apply-author-sheets="true">
<div id="wrapper">
<h:div>
<h:a href="javascript:void(0);" id="back">&lt;</h:a> &#160;
<h:a href="javascript:void(0);" id="forward">&gt;</h:a> &#160;
<h:input id="urlBar" type="text" size="30" />
<h:input type="button" id="go" value="Go!" />
</h:div>
<h:iframe id="iframeBrowser" xbl:attr="class style src"></h:iframe>
</div>
</template>
<handlers></handlers>
<resources>
<style>
// add elsewhere: body { binding: url(ibrowser.xml); /* #ibrowser not needed if the first one */ }
</style>
</resources>
<!--
<script><![CDATA[
var textboxID = 'urlBar',
iframeID = 'iframeBrowser',
textbox = this.shadowTree.getElementById(textboxID),
browser = this.shadowTree.getElementById(iframeID);
function _addClick() {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
browser.addEventListener('load', function () {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var urlbarURL = browser.getUserData('urlbarURL');
var url = urlbarURL || browser.contentDocument.defaultView.location.href;
if (urlbarURL) {
browser.setUserData('urlbarURL', null, null);
}
if (browser.getUserData('backNow')) { // This load was a result of a back event, so don't increment as we normally do
browser.setUserData('backNow', false, null);
return;
}
if (browser.getUserData('forwardNow')) { // This load was a result of a forward event, so don't alter the array as we normally do
browser.setUserData('forwardNow', false, null);
return;
}
var history = browser.getUserData('history');
if (history == null) {
history = [browser.src];
browser.setUserData('history', history, null);
browser.setUserData('historyPointer', 0, null);
}
var historyPointer = browser.getUserData('historyPointer');
history.splice(historyPointer+1, null, url);
textbox.value = url;
var newPointer = historyPointer+1;
browser.setUserData('historyPointer', newPointer, null);
browser.setUserData('history', history, null);
}
catch(err) {
alert(err);
}
}, false);
browser.setUserData('hasListener', true, null);
}
catch(err) {
alert(err);
}
}
function goURL () {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if (!browser.getUserData('hasListener')) {
_addClick();
}
browser.setUserData('urlbarURL', textbox.value, null);
browser.contentDocument.defaultView.location.href = textbox.value;
}
catch(e) {
alert(e);
}
}
function _back () {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var history = browser.getUserData('history');
if (!history) {
return;
}
var historyPointer = browser.getUserData('historyPointer');
if (historyPointer >= 1) {
var newPointer = historyPointer-1;
browser.setUserData('historyPointer', newPointer, null);
browser.setUserData('backNow', true, null);
browser.contentDocument.defaultView.location.href = history[newPointer];
textbox.value = history[newPointer];
}
}
catch(e) {
alert(e);
}
}
function _forward () {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var history = browser.getUserData('history');
if (!history) {
return;
}
var historyPointer = browser.getUserData('historyPointer');
if (historyPointer < history.length-1) {
var newPointer = historyPointer+1;
browser.setUserData('historyPointer', newPointer, null);
browser.setUserData('forwardNow', true, null);
browser.contentDocument.defaultView.location.href = history[newPointer];
textbox.value = history[newPointer];
}
}
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
browser.contentDocument.addEventListener('click', _addClick, true);
}
catch(e) {
alert(e);
}
]]></script>-->
<implementation><![CDATA[
({
xblBindingAttached : function () {
this.shadowTree.getElementById('go').addEventListener('click', goURL, false);
this.shadowTree.getElementById('back').addEventListener('click', _back, false);
this.shadowTree.getElementById('forward').addEventListener('click', _forward, false);
var textboxID = 'urlBar',
iframeID = 'iframeBrowser',
textbox = this.shadowTree.getElementById(textboxID),
browser = this.shadowTree.getElementById(iframeID);
function _addClick() {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
browser.addEventListener('load', function () {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var urlbarURL = browser.getUserData('urlbarURL');
var url = urlbarURL || browser.contentDocument.defaultView.location.href;
if (urlbarURL) {
browser.setUserData('urlbarURL', null, null);
}
if (browser.getUserData('backNow')) { // This load was a result of a back event, so don't increment as we normally do
browser.setUserData('backNow', false, null);
return;
}
if (browser.getUserData('forwardNow')) { // This load was a result of a forward event, so don't alter the array as we normally do
browser.setUserData('forwardNow', false, null);
return;
}
var history = browser.getUserData('history');
if (history == null) {
history = [browser.src];
browser.setUserData('history', history, null);
browser.setUserData('historyPointer', 0, null);
textbox.value = browser.src;
}
else {
var historyPointer = browser.getUserData('historyPointer');
history.splice(historyPointer+1, history.length, url);
textbox.value = url;
var newPointer = historyPointer+1;
browser.setUserData('historyPointer', newPointer, null);
browser.setUserData('history', history, null);
}
}
catch(err) {
alert(err);
}
}, false);
browser.setUserData('hasListener', true, null);
}
catch(err) {
alert(err);
}
}
function goURL () {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if (!browser.getUserData('hasListener')) {
_addClick();
}
browser.setUserData('urlbarURL', textbox.value, null);
browser.contentDocument.defaultView.location.href = textbox.value;
}
catch(e) {
alert(e);
}
}
function _back () {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var history = browser.getUserData('history');
if (!history) {
return;
}
var historyPointer = browser.getUserData('historyPointer');
if (historyPointer >= 1) {
var newPointer = historyPointer-1;
browser.setUserData('historyPointer', newPointer, null);
browser.setUserData('backNow', true, null);
browser.contentDocument.defaultView.location.href = history[newPointer];
textbox.value = history[newPointer];
}
}
catch(e) {
alert(e);
}
}
function _forward () {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var history = browser.getUserData('history');
if (!history) {
return;
}
var historyPointer = browser.getUserData('historyPointer');
if (historyPointer < history.length-1) {
var newPointer = historyPointer+1;
browser.setUserData('historyPointer', newPointer, null);
browser.setUserData('forwardNow', true, null);
browser.contentDocument.defaultView.location.href = history[newPointer];
textbox.value = history[newPointer];
}
}
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
_addClick();
// browser.contentDocument.addEventListener('click', _addClick, true);
}
catch(e) {
alert(e);
throw e;
}
}
})
]]></implementation>
</binding>
</xbl>
<?php
header('Content-type: application/xquery;charset=utf8');
/*
Bugs in xbl.js?:
// work within .xml files: http://code.google.com/p/xbl/issues/detail?id=27
// actually need ID and hash in CSS binding? http://code.google.com/p/xbl/issues/detail?id=26
// CSS binding attachment should parse descendants, not append to it? http://code.google.com/p/xbl/issues/detail?id=26
// <script/> not working in XBL? http://code.google.com/p/xbl/issues/detail?id=25
// Doesn't support default CSS namespaces http://code.google.com/p/xbl/issues/detail?id=24
// no &#160; added? http://code.google.com/p/xbl/issues/detail?id=23
// binding whitespace and regexp http://code.google.com/p/xbl/issues/detail?id=22
when running on different domains, also need:
1) add netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); to the top of cXBLLanguage.fetch in xbl.js
2) Comment out the line in xbl.js inside fOnWindowLoad(): if (fUrisInSameDomain(sHref, sHrefDocument))
signed.applets.codebase_principal_support prefs must also be true, but only when using XBL like this (not sure why not needed in other code that also uses privilege enabling
*/
?>
declare default element namespace "http://www.w3.org/1999/xhtml";
<html xmlns:i="http://brett-zamir.me/ns/ibrowser" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Independent JavaScript Browsers</title>
<script type="text/javascript" src="http://brett-zamir.me/tests/xbl.js">&#160;</script>
<link rel="stylesheet" type="text/css" href="http://brett-zamir.me/tests/xbl-browser.css">&#160;</link>
</head>
<body>
<table border="1" style="width:100%;">
{
for $par in doc('http://bahai-library.com/writings/bahaullah/aqdas/aqdas.html')//p[substring(@id, 1, 1) = 'K' and number(substring(@id, 2)) >= 4 and number(substring(@id, 2)) <= 6]
let $id := substring($par/@id, 2)
return <tr>
<td style="width:50%;">{$par}</td>
<td>
<i:browser class="frameBrowser" src="http://bahai9.com/wiki/Kitáb-i-Aqdas{$id}" />
</td>
</tr>
}
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.