From: phasefx Date: Fri, 13 Aug 2010 14:48:01 +0000 (+0000) Subject: playing around with Find in Page functionality; the recent dojo highlighter commit... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=eabdbb60246cd0799027a606f3f9924664d01a0a;p=evergreen%2Fbjwebb.git playing around with Find in Page functionality; the recent dojo highlighter commit prompted me to share this git-svn-id: svn://svn.open-ils.org/ILS/trunk@17211 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- 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 c45652ee1..ed565f280 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/browser.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/browser.js @@ -108,6 +108,13 @@ util.browser.prototype = { 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 @@ util.browser.prototype = { } }, + '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"); 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 c6fc6e614..6cceebbd2 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/browser.xul +++ b/Open-ILS/xul/staff_client/chrome/content/util/browser.xul @@ -106,6 +106,7 @@ + @@ -119,6 +120,7 @@