From fbe57697a472743ecbfc17bb6d93e7c14ed6d48c Mon Sep 17 00:00:00 2001 From: phasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4> Date: Tue, 13 Apr 2010 18:02:25 +0000 Subject: [PATCH] tweaks to <help> widget to support non-chrome help content with chrome <help> widgets, and wiring it up into a generic Help button for embedded browser based interfaces git-svn-id: svn://svn.open-ils.org/ILS/trunk@16229 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/opac/locale/en-US/lang.dtd | 4 ++++ .../staff_client/chrome/content/main/bindings.xml | 24 +++++++++++++++------- .../staff_client/chrome/content/util/browser.js | 14 ++++++++++++- .../staff_client/chrome/content/util/browser.xul | 5 +++-- .../staff_client/chrome/content/util/rbrowser.xul | 9 ++++++-- 5 files changed, 44 insertions(+), 12 deletions(-) diff --git a/Open-ILS/web/opac/locale/en-US/lang.dtd b/Open-ILS/web/opac/locale/en-US/lang.dtd index 49c9f427e6..7dfbd5a42b 100644 --- a/Open-ILS/web/opac/locale/en-US/lang.dtd +++ b/Open-ILS/web/opac/locale/en-US/lang.dtd @@ -58,6 +58,10 @@ <!ENTITY common.browser.backward.accesskey "B"> <!ENTITY common.browser.reload.label "Reload"> <!ENTITY common.browser.reload.accesskey "l"> +<!ENTITY common.browser.print.label "Print Page"> +<!ENTITY common.browser.print.accesskey "P"> +<!ENTITY common.browser.help.label "Help"> +<!ENTITY common.browser.help.accesskey "H"> <!ENTITY common.textbox.cut "Cut"> <!ENTITY common.textbox.copy "Copy"> diff --git a/Open-ILS/xul/staff_client/chrome/content/main/bindings.xml b/Open-ILS/xul/staff_client/chrome/content/main/bindings.xml index 9216e581f2..e3bc819d39 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/bindings.xml +++ b/Open-ILS/xul/staff_client/chrome/content/main/bindings.xml @@ -34,7 +34,10 @@ // /custom_help.html // /help.html // - // If @pathname is specified, it will override the value from location.href + // If @pathname is specified, it will override the value from location.pathname + // If @hostname is specified, it will override the value from location.hostname + // If @port is specified, it will override the value from location.port + // If @protocol is specified, it will override the value from location.protocol this.addEventListener( 'command', function(ev) { this._open_window(); }, false); } catch(E) { @@ -50,23 +53,30 @@ try { var obj = this; + var protocol = obj.getAttribute('protocol') || location.protocol; + var hostname = obj.getAttribute('hostname') || location.hostname; + var port = obj.getAttribute('port') || location.port; + var pathname = obj.getAttribute('pathname') || location.pathname; function test_url(loc) { - if (!loc) { return false; } + if (loc == '/' || !loc) { return false; } var x = new XMLHttpRequest(); - x.open("HEAD",loc,false); + var url = protocol + '//' + hostname + ( port ? ':' + port : '' ) + loc; + dump('help widget: testing <'+url+'>\n'); + x.open("HEAD", url, false); x.send(null); return x.status == 200; } function open_url(loc) { - window.open(loc+'?id='+obj.id,obj.getAttribute('label'),'resizable,scrollbars'); + var url = protocol + '//' + hostname + ( port ? ':' + port : '' ) + loc +'?id='+obj.id; + dump('help widget: opening <'+url+'>\n'); + window.open(url, obj.getAttribute('label'), 'resizable,scrollbars'); } - if (test_url(this.src)) { - open_url(this.src); + if (test_url('/'+this.getAttribute('src'))) { + open_url('/'+this.getAttribute('src')); } else { - var pathname = obj.getAttribute('pathname') || location.pathname; if (test_url(pathname + '.custom_help.html')) { open_url(pathname + '.custom_help.html'); } else { diff --git a/Open-ILS/xul/staff_client/chrome/content/util/browser.js b/Open-ILS/xul/staff_client/chrome/content/util/browser.js index 5b79d06151..f543f40a8a 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/browser.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/browser.js @@ -211,8 +211,20 @@ util.browser.prototype = { } catch(E) { s += E + '\n'; } - //this.error.sdump('D_BROWSER',s); + + // Let's also update @protocol, @hostname, @port, and @pathname on the <help> widget + var help_btn = document.getElementById('help_btn'); + if (help_btn) { + try { + help_btn.setAttribute('protocol', obj.get_content().location.protocol); + help_btn.setAttribute('hostname', obj.get_content().location.hostname); + help_btn.setAttribute('port', obj.get_content().location.port); + help_btn.setAttribute('pathname', obj.get_content().location.pathname); + } catch(E) { + dump('Error in browser.js, setting location on help widget: ' + E); + } + } }, 'buildProgressListener' : function() { diff --git a/Open-ILS/xul/staff_client/chrome/content/util/browser.xul b/Open-ILS/xul/staff_client/chrome/content/util/browser.xul index d9279927b1..a9a80437bc 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/browser.xul +++ b/Open-ILS/xul/staff_client/chrome/content/util/browser.xul @@ -98,7 +98,7 @@ <commandset id="util_browser_cmds"> <command id="cmd_broken" /> - <command id="cmd_print" /> + <command id="cmd_print" label="&common.browser.print.label;" accesskey="&common.browser.print.accesskey;" /> <command id="cmd_debug" /> <command id="cmd_back" label="&common.browser.backward.label;" accesskey="&common.browser.backward.accesskey;" /> <command id="cmd_reload" label="&common.browser.reload.label;" accesskey="&common.browser.reload.accesskey;" /> @@ -112,7 +112,8 @@ <button id="forward" command="cmd_forward" disabled="true" hidden="true"/> <spacer flex="1"/> <label id="debug" value="Debug" disabled="true" command="cmd_debug" onclick="this.doCommand();" /> - <button id="browser_print" label="Print Page" command="cmd_print" hidden="true"/> + <button id="browser_print" command="cmd_print" hidden="true"/> + <help id="help_btn" label="&common.browser.help.label;" accesskey="&common.browser.help.accesskey;" /> </hbox> <browser id="browser_browser" flex="1" type="content"/> </vbox> diff --git a/Open-ILS/xul/staff_client/chrome/content/util/rbrowser.xul b/Open-ILS/xul/staff_client/chrome/content/util/rbrowser.xul index 8ba1a7055b..b8c7a52d42 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/rbrowser.xul +++ b/Open-ILS/xul/staff_client/chrome/content/util/rbrowser.xul @@ -99,7 +99,7 @@ <commandset id="util_browser_cmds"> <command id="cmd_broken" /> - <command id="cmd_print" /> + <command id="cmd_print" label="&common.browser.print.label;" accesskey="&common.browser.print.accesskey;" /> <command id="cmd_debug" /> <command id="cmd_back" label="&common.browser.backward.label;" accesskey="&common.browser.backward.accesskey;" /> <command id="cmd_reload" label="&common.browser.reload.label;" accesskey="&common.browser.reload.accesskey;" /> @@ -113,9 +113,14 @@ <button id="forward" command="cmd_forward" disabled="true" hidden="true"/> <spacer flex="1"/> <label id="debug" value="Debug" disabled="true" command="cmd_debug" onclick="this.doCommand();" /> - <button id="browser_print" label="Print Page" oldcommand="cmd_print" hidden="true" + <button id="browser_print" + label="&common.browser.print.label;" + accesskey="&common.browser.print.accesskey;" + hidden="true" + oldcommand="cmd_print" oncommand="netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); if (g.browser.alt_print) { JSAN.use('util.print'); var p = new util.print(); p.NSPrint(g.browser.get_content(),false,{}); } else { g.browser.get_content().print(); }" /> + <help id="help_btn" label="&common.browser.help.label;" accesskey="&common.browser.help.accesskey;" /> </hbox> <browser id="browser_browser" flex="1" type="content"/> </vbox> -- 2.11.0