My favorite feature of dqsd is the mwd popup feature when mapped to the
postfix operator :.  It's small, handy and unobtrusive.  It's important to
me that a simple definition lookup doesn't switch context from what I want
to be doing, that it not bring up a browser window.  I've mentioned it
before here:

http://dblume.livejournal.com/65402.html

That feature is broken yet again, and not worth fixing anymore.  MWD's
changed the format of their page so much I've given up trying to make mwd
work anymore.  They'll just break it again.  So here's a replacement
search.  It's called "df", short for definition.  Here's how I use it.  I
add:

:|df

to localaliases.txt, and now when I need the definition of a word, I type
the word with a colon, and the definition pops up in a little window in the
corner.

Please note:  I don't know any JavaScript, XML, CSS, HTML or web servicey
stuff.  I only did this because it was too useful a feature not to have.
Nothing would delight me more than somebody who knows what they're doing
taking it over and cleaning it up.

Enjoy,
--David

PS.  If anybody does look at the code, you'll see that I only look for
definitions in at most two dictionaries.  My selection was based on
experimentation and is quite arbitrary.  I wrote the search for me, after
all.  But it'd be great to make that customizable, or when a word is
misspelled, to attempt a Match from
http://services.aonaware.com/DictService/DictService.asmx/Match?word=string&strategy=...
with a strategy from
http://services.aonaware.com/DictService/DictService.asmx/StrategyList.
That'd be nice.

PPS.  There are probably glaring problems with the submitted file.  I
apologize in advance.  It was only tested on my Windows Vista machine with
launchmode=1, and my default browser is Firefox.  Please, go ahead and fix
it so it works for you, too.
<search function="df">
  <name>DictService from Aonaware</name>
  <description>
    Search for word definitions.  Recommended it is used with ":|df" in localaliases.txt, so that "word:" brings up its definition.
    <div class="helpboxDescLabels">Switches:</div>
    <div class="helpboxDescLabels">Examples:</div>
    <table class="helpboxDescTable">
      <tr><td>df idempotent</td></tr>
      <tr><td>idempotent:</td></tr>
    </table>
  </description>
  <category>Reference<category>Language</category></category>
  <link>http://www.aonaware.com/services.htm</link>
  
  <form name="dff"
        action="http://services.aonaware.com";
        method="post">
    <input type="hidden" name="book" value="Dictionary"/>
    <input type="hidden" name="va"/>
  </form>
  
  <script>
   <![CDATA[
  
    function df(q)
    {
      var dicts = ["foldoc","gcide"];
      var definitions;
      try
      {
        var xmlHttp = new ActiveXObject("Microsoft.XmlHttp");
        for( var d in dicts ) {
          xmlHttp.open("GET", "http://services.aonaware.com/DictService/DictService.asmx/DefineInDict?dictId="; + dicts[d] + "&word=" + q, false);
          xmlHttp.send();      
          var xmlDoc = xmlHttp.responseXML.documentElement;
          definitions = xmlDoc.getElementsByTagName("WordDefinition")          
          if( definitions.length > 0 )
            break;
        }
      }
      catch ( e )
      {
        alert( "Exception thrown: " + e.description );
        return;
      }
      
      var windowW = 500;

      if ( definitions.length > 0 ) {
          var html = '<p><b>' + q + '</b></p>';
          for( var i=0; i < definitions.length; i++ ) {
            html += '<p>' + definitions[i].text + '</p>';
          }
      }
      else
      {
          var html = '<center><b>' + q + '</b> not found</center><br/>';
          alert( html );
      }

      if ( typeof dictPopup == 'undefined' )
        dictPopup = window.createPopup();
      var dictPopupBody = dictPopup.document.body;

      // Let's concat on a local variable first for easier debugging - let's also copy over a couple of styles from linked "entry.css"
      var dictPopupBodyInnerHTML = '<table id=dfTable style="font-size: 70%; border: inset 2px" height="100%" width="100%"><style type="text/css">img { border-width: 0 } .variant { font-weight: bold; } .verb_class { display: block; } .unicode{font-family:"Lucida Sans Unicode";}</style><tr><td style="padding: 5px 20px 5px 5px">' + html + "</td></tr></table>";

      // This assignment will reformat the HTML extensively
      dictPopupBody.innerHTML = dictPopupBodyInnerHTML;

      dictPopup.document.body.style.border="outset 2px";
      dictPopup.document.body.style.padding="1px 1px; background: navy";
      dictPopup.document.body.style.background='menu';
      dictPopup.document.body.style.overflowY='auto';
      dictPopup.document.body.style.fontFamily='Verdana';
      dictPopup.document.body.attachEvent('onmouseup',dfCopySelection);

      // Temporarily show the popup to determine the proper final height for the popup.
      dictPopup.show(0, 0, windowW, 0);
      var windowH = dictPopupBody.scrollHeight + 6;
      dictPopup.hide();
      dictPopup.document.all.dfTable.style.width = windowW - 5;
      windowH = windowH > window.screen.height/2 ? window.screen.height/2 : windowH;
      dictPopup_x = (buttonalign == "left" ? 0 : document.body.clientWidth - windowW);
      dictPopup_y = -windowH;
      dictPopup_width = windowW;
      dictPopup_height = windowH;
      if ( typeof dictPopup_ring == 'undefined' )
        dictPopup_ring = new Array();
      dictPopup_ring.push( { x:dictPopup_x, y:dictPopup_y, width:dictPopup_width, height:dictPopup_height, html:dictPopupBody.innerHTML } );
      dictPopup_sp = dictPopup_ring.length - 1;
      dictPopup.show(dictPopup_x, dictPopup_y, dictPopup_width, dictPopup_height, document.body);
    }
    
    function dfCopySelection()
    {
      dictPopup.document.execCommand( "Copy" );
      dictPopup.document.selection.empty();
    }
    
    function dfGoToWord(w)
    {
      if ( dictPopup.document.selection.type == "Text" )
      {
        dfCopySelection();
      }
      else
      {
        df(w);
      }
    }
  ]]></script>
  <copyright>
  Copyright (c) 2009 David Blume
  Distributed under the terms of the
  GNU Public License, Version 2 (http://www.gnu.org/copyleft/gpl.txt)
  </copyright>
</search>
------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations 
Conference from O'Reilly Media. Velocity features a full day of 
expert-led, hands-on workshops and two days of sessions from industry 
leaders in dedicated Performance & Operations tracks. Use code vel09scf 
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
To unsubscribe visit:
https://lists.sourceforge.net/lists/listinfo/dqsd-users
DQSD-Users@lists.sourceforge.net
http://sourceforge.net/mailarchive/forum.php?forum_id=8601

Reply via email to