[open-ils-commits] r17211 - trunk/Open-ILS/xul/staff_client/chrome/content/util (phasefx)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Aug 13 10:48:03 EDT 2010
Author: phasefx
Date: 2010-08-13 10:48:01 -0400 (Fri, 13 Aug 2010)
New Revision: 17211
Modified:
trunk/Open-ILS/xul/staff_client/chrome/content/util/browser.js
trunk/Open-ILS/xul/staff_client/chrome/content/util/browser.xul
trunk/Open-ILS/xul/staff_client/chrome/content/util/rbrowser.xul
Log:
playing around with Find in Page functionality; the recent dojo highlighter commit prompted me to share this
Modified: trunk/Open-ILS/xul/staff_client/chrome/content/util/browser.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/chrome/content/util/browser.js 2010-08-13 12:25:56 UTC (rev 17210)
+++ trunk/Open-ILS/xul/staff_client/chrome/content/util/browser.js 2010-08-13 14:48:01 UTC (rev 17211)
@@ -108,6 +108,13 @@
obj.error.sdump('D_ERROR',err);
}
}
+ ],
+ 'cmd_find' : [
+ ['command'],
+ function() {
+ var text = window.prompt('Enter text to find:');
+ obj.find(text);
+ }
]
}
}
@@ -135,6 +142,71 @@
}
},
+ 'find' : function(text) {
+ var obj = this;
+ try {
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+
+ function getBrowser() {
+ return obj.controller.view.browser_browser;
+ }
+
+ function getFocusedSelCtrl() {
+ var ds = getBrowser().docShell;
+ var dsEnum = ds.getDocShellEnumerator(Components.interfaces.nsIDocShellTreeItem.typeContent,
+ Components.interfaces.nsIDocShell.ENUMERATE_FORWARDS);
+ while (dsEnum.hasMoreElements()) {
+ ds = dsEnum.getNext().QueryInterface(Components.interfaces.nsIDocShell);
+ if (ds.hasFocus) {
+ var display = ds.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsISelectionDisplay);
+ if (!display) return null;
+ return display.QueryInterface(Components.interfaces.nsISelectionController);
+ }
+ }
+
+ // One last try
+ return getBrowser().docShell
+ .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+ .getInterface(Components.interfaces.nsISelectionDisplay)
+ .QueryInterface(Components.interfaces.nsISelectionController);
+ }
+
+ function setSelection(range) {
+ try {
+ var selctrlcomp = Components.interfaces.nsISelectionController;
+ var selctrl = getFocusedSelCtrl();
+ var sel = selctrl.getSelection(selctrlcomp.SELECTION_NORMAL);
+ sel.removeAllRanges();
+ sel.addRange(range.cloneRange());
+
+ selctrl.scrollSelectionIntoView(selctrlcomp.SELECTION_NORMAL,
+ selctrlcomp.SELECTION_FOCUS_REGION,
+ true);
+ } catch(e) {alert("setSelection: " + e);}
+ }
+
+ var doc = obj.get_content().document;
+ var body = doc.body;
+ var count = body.childNodes.length;
+ var finder = Components.classes["@mozilla.org/embedcomp/rangefind;1"].createInstance()
+ .QueryInterface(Components.interfaces.nsIFind);
+ var searchRange = doc.createRange();
+ var startPt = doc.createRange();
+ var endPt = doc.createRange();
+ searchRange.setStart(body,0);
+ searchRange.setEnd(body, count);
+ startPt.setStart(body, 0);
+ startPt.setEnd(body, 0);
+ endPt.setStart(body, count);
+ endPt.setEnd(body, count);
+ var retRange = finder.Find(text, searchRange, startPt, endPt);
+ alert('retRange = ' + retRange );
+ setSelection(retRange);
+ } catch(E) {
+ alert('Error in browser.js, find(): ' + E);
+ }
+ },
+
'get_content' : function() {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
Modified: trunk/Open-ILS/xul/staff_client/chrome/content/util/browser.xul
===================================================================
--- trunk/Open-ILS/xul/staff_client/chrome/content/util/browser.xul 2010-08-13 12:25:56 UTC (rev 17210)
+++ trunk/Open-ILS/xul/staff_client/chrome/content/util/browser.xul 2010-08-13 14:48:01 UTC (rev 17211)
@@ -106,6 +106,7 @@
<command id="cmd_broken" />
<command id="cmd_print" label="&common.browser.print.label;" accesskey="&common.browser.print.accesskey;" />
<command id="cmd_debug" />
+ <command id="cmd_find" />
<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;" />
<command id="cmd_forward" label="&common.browser.forward.label;" accesskey="&common.browser.forward.accesskey;" />
@@ -119,6 +120,7 @@
<spacer flex="1"/>
<label id="debug" value="Debug" disabled="true" command="cmd_debug" onclick="this.doCommand();" />
<button id="browser_print" command="cmd_print" hidden="true"/>
+ <button id="browser_find" label="Find in Page" command="cmd_find" hidden="false"/>
</hbox>
<browser id="browser_browser" flex="1" autoscroll="false" type="content"/>
</vbox>
Modified: trunk/Open-ILS/xul/staff_client/chrome/content/util/rbrowser.xul
===================================================================
--- trunk/Open-ILS/xul/staff_client/chrome/content/util/rbrowser.xul 2010-08-13 12:25:56 UTC (rev 17210)
+++ trunk/Open-ILS/xul/staff_client/chrome/content/util/rbrowser.xul 2010-08-13 14:48:01 UTC (rev 17211)
@@ -109,6 +109,7 @@
<command id="cmd_broken" />
<command id="cmd_print" label="&common.browser.print.label;" accesskey="&common.browser.print.accesskey;" />
<command id="cmd_debug" />
+ <command id="cmd_find" />
<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;" />
<command id="cmd_forward" label="&common.browser.forward.label;" accesskey="&common.browser.forward.accesskey;" />
@@ -122,6 +123,7 @@
<spacer flex="1"/>
<label id="debug" value="Debug" disabled="true" command="cmd_debug" onclick="this.doCommand();" />
<button id="browser_print" command="cmd_print" hidden="true"/>
+ <button id="browser_find" label="Find in Page" command="cmd_find" hidden="false"/>
</hbox>
<browser id="browser_browser" flex="1" autoscroll="false" type="content"/>
</vbox>
More information about the open-ils-commits
mailing list