Even since that last one that was mailed out, another change was required.
(Not using m-w.com)  Enclosed with this message is what I have in my
sandbox.

--David

On Mon, Feb 25, 2008 at 8:26 AM, Glenn Carr <[EMAIL PROTECTED]> wrote:

>  Does anyone have the latest update to the mwd.xml search?  Or was there
> even one?  I'm noticing that the regular mwd search isn't working for me,
> and I thought I remembered someone doing some work on the popup version of
> mwd, and sending it out as an attachment. ... ?
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> To unsubscribe visit:
> https://lists.sourceforge.net/lists/listinfo/dqsd-users
> DQSD-Users@lists.sourceforge.net<https://lists.sourceforge.net/lists/listinfo/[EMAIL
>  PROTECTED]>
> http://sourceforge.net/mailarchive/forum.php?forum_id=8601
>
>
<search function="mwd">
  <name>Merriam-Webster Dictionary</name>
  <description>
    Search for word definitions.
    <div class="helpboxDescLabels">Switches:</div>
    <table class="helpboxDescTable">
      <tr><td>/popup</td><td> - </td><td>Display in popup window instead of regular browser window</td></tr>
    </table>
    <div class="helpboxDescLabels">Examples:</div>
    <table class="helpboxDescTable">
      <tr><td>mwd idempotent</td></tr>
      <tr><td>mwd /p idempotent</td></tr>
    </table>
  </description>
  <category>Reference<category>Language</category></category>
  <link>http://www.merriam-webster.com/</link>
  
  <form name="mwdf"
        action="http://www.merriam-webster.com/cgi-bin/dictionary";
        method="post">
    <input type="hidden" name="book" value="Dictionary"/>
    <input type="hidden" name="va"/>
  </form>
  
  <script><![CDATA[
    function mwd(q)
    {
      var args = parseArgs(q, "popup");
      if ( typeof mwdDisplayInPopup == "undefined" )
        mwdDisplayInPopup = 0;
      if ( (args.switches.length > 0) || (mwdDisplayInPopup != 0) )
      {
        mwdx(args.q) // Display in popup window
      }
      else
      {
        if( nullArgs("mwd",q) )
          return false;

        document.mwdf.va.value = args.q;
        submitForm(mwdf); // Display in regular browser window
      }
    }
    
    function mwdx(q)
    {
      var extraArgDelim = '\1';
      var listOption = false;
      var p = q.search( extraArgDelim );
      if ( p >= 0 )
      {
        postArgs = unescape( q.substr( p + 1 ) );
        listOption = true;
        q = q.substr( 0, p );
      }
    
      try
      {
        var xmlHttp = new ActiveXObject("Microsoft.XmlHttp");
        if ( listOption )
        {
          xmlHttp.open("POST", "http://www.merriam-webster.com/cgi-bin/dictionary";, false);
          xmlHttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
          xmlHttp.send( postArgs );
        }
        else
        {
          xmlHttp.open("GET", "http://www.merriam-webster.com/dictionary/"; + q, false);
          xmlHttp.send();
        }
      }
      catch ( e )
      {
        alert( e.description );
        return;
      }
      
      if ( q == '' )
      {
        if ( typeof dictPopup != 'undefined' && dictPopup_ring.length > 0 )
        {
          if ( --dictPopup_sp < 0 )
            dictPopup_sp = dictPopup_ring.length - 1;

          var prev = dictPopup_ring[ dictPopup_sp ];
          dictPopup.document.body.innerHTML = prev.html;
          dictPopup.show(prev.x, prev.y, prev.width, prev.height, dictPopup.document.body);
        }
        else
        {
          nullArgs("mwd",q)
        }
        return;
      }

      var windowW = 500;

      var sBody = xmlHttp.responseText.replace( /[\r\n]/gi, "" );
      var re = /(<div\sclass="entry\smisc">(.+)<\/div><\/div>)/mig;
      var results = re.exec( sBody );
      if ( results != null )
      {
        var html = results[ 1 ].replace( /(src="\/)/gi, "src=\"http://www.merriam-webster.com/"; ).replace( /(href="\/)/gi, "href=\"http://www.merriam-webster.com/"; );
        var html = html.replace( /<span\sclass="sense_break"\/>/gi, "<br/>");
        var html = html.replace( /<span\sclass="sense\_label\sstart">/gi, "<br/><br/><span>");
        var html = html.replace( /javascript\:popWin\(\'\//gi, "http://www.merriam-webster.com/";);
        var html = html.replace( /\'\)"\sclass="audio"/gi, "\"");

        var optionHtml = '';
        var numOfEntriesRegex = /<form name="entry"  method=post action="\/dictionary">(Entries [0-9]+ to [0-9]+ of )?([0-9]+)( entries found)?/.exec( sBody );
        var entriesFound = 1;
        if (numOfEntriesRegex != null)
          entriesFound = parseInt( numOfEntriesRegex[ 2 ], 10 );

        if ( entriesFound > 1 )
        {
          var entryFormHTML = /(<form name="entry".*?\/form>)/.exec( sBody );
          if ( entryFormHTML != null )
          {
            var options = /(<option.*)<\/select>/.exec( entryFormHTML[1] );
            if ( options != null )
            {
              var allFormVars = entryFormHTML[1].replace( /.*<input.*name='?quer'? value="([^"]+)".*<input.*name='?list'? value="([^"]+)".*/i, 
                                              "book=Dictionary&quer=$1&list=$2" );
              options = options[ 1 ].split( '<option' );
              optionHtml += numOfEntriesRegex[ 1 ] + numOfEntriesRegex[ 2 ] + numOfEntriesRegex[ 3 ] + '<br><ul style="margin-top: 0px; margin-bottom: 0px">';
              for ( var i = 0; i < options.length; i++ )
                if ( options[ i ] != "" )
                {
                  options[ i ] = options[ i ].replace(/.*>/, '');
                  var words = /([^[]+)(.*)/.exec( options[ i ] );
                  var formVars = 'jump=' + options[ i ] + '&' + allFormVars;
                  optionHtml += '<li><a href="" onMouseUp=parent.mwdx("' + escape( words[ 1 ] ) + extraArgDelim + escape( formVars ) + '");>' + options[ i ] + '</a></li>';
                }

              // Also add the "Next 10" (or "Next nn") link if the submit button exists
              var nextEntries = /value='(Next [0-9]+)' name='incr'/.exec( entryFormHTML[1] );
              if ( nextEntries != null )
              {
                var formVars = 'incr=' + nextEntries[ 1 ] + '&' + allFormVars;
                optionHtml += '<br><li><a href="" onMouseUp=parent.mwdx("' + q + extraArgDelim + escape( formVars ) + '");>' + nextEntries[ 1 ] + '</a></li>';                  
              }
              optionHtml += '</ul>';
            }
          }
          
          html = optionHtml + html;
        }

        html = html.replace( new RegExp( String.fromCharCode(65535), "g" ), '-' ); // weirdness
        html = html.replace( /(<a\s+)href="http:\/\/www.merriam-webster.com\/dictionary\/([^"]+)"([^>]*>)/gi, '$1 href="" onMouseUp=parent.mwdGoToWord("$2"); $3' );
        html = html.replace( /<a href="javascript:popWin\('\/cgi-bin\/(audio.pl[^'>]+)'\)">/gi, '<a href="" onMouseUp=parent.openSearchWindow("http://www.merriam-webster.com/cgi-bin/$1";);>' );
        html = html.replace( /(<a\s+)href=("http:\/\/www.merriam-webster.com\/([^"]+)")([^>]*>)/gi, '$1 href="" onMouseUp=parent.openSearchWindow($2);>' );
        // If the links we've replaced contains spaces (e.g. "brilliant " in "table"), assignment to "innerHTML" below gets confused and causes
        //   "Unterminated string constant" error. On the other hand, we can not just go ahead and use single quotes around "onMouseUp"
        //   event either, as there are also links that have them (e.g. "cat-o'-nine-tails" in "cat"), so let's also escape our links.
        function inPlaceLinkReplacer(str, p1, p2, p3, offset, s)
        {
        	// Expected p1: prefix, p3: suffix (both sent back as-is)
        	//  p2: the actual "link" material which may contain special characters
        	return p1 + escape(p2) + p3;
        }
        function inPlaceLinkReplacerDebug(str, p1, p2, p3, offset, s)
        {
        	alert(' str = ' + str + '\n\n p1 = ' + p1 + '\n\n p2 = ' + p2 + '\n\n p3 = ' + p3);
        	return p1 + escape(p2) + p3;
        }
        html = html.replace( /(onMouseUp=parent\.mwdGoToWord\(")(.+?)("\))/gi, inPlaceLinkReplacer );
        html = html.replace( /(audio\.pl\?.*?=)(.+?)("\);>)/gi, inPlaceLinkReplacer );
      }
      else
      {
        // MW site lists "Suggestions for" title for nonexistent words as well, so let's make sure there's at least one link underneath
        results = /(Suggestions for.+href="\/dictionary\/.+<\/PRE>)/ig.exec( sBody );
        if ( results != null )
        {
          var html = results[ 1 ].replace( /href="\/dictionary\/([^"]+)"/gi, 'href="" onMouseUp=\'parent.mwdx("$1");\' ' ).replace( />\s*([0-9]+)/g, '>\r\n$1' );
        }
        else
        {
          // In these cases returned HTML doesn't really offer much other than a subscription link, or the whole homepage: Ignored.
          windowW = 200;
          results = /(<div\sclass="entry\steaser">)/ig.exec( sBody );
          if ( results != null )
          {
            // Teaser entry
            var html = '<center><b>' + q + '</b> can be found at Merriam-WebsterUnabridged.com (Subscription required).</center><br/>';
          }
          else
          {
            var html = '<center><b>' + q + '</b> not found</center><br/>';
          }
        }
      }

      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=defTable style="font-size: 70%; border: inset 2px" height="100%" width="100%"><style type="text/css"> .variant { font-weight: bold; } .verb_class { display: block; } .unicode{font-family:"Lucida Sans Unicode";}</style><tr><td style="padding: 5px 5px">' + html + "</td></tr></table>";
      // writeFile('InnerHTML_Final_' + q + '.txt', dictPopupBodyInnerHTML);

      // This assignment will reformat the HTML extensively
      dictPopupBody.innerHTML = dictPopupBodyInnerHTML;
      // writeFile('InnerHTML_Assigned' + q + '.txt', dictPopupBody.innerHTML);

      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',mwdCopySelection);

      // 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.defTable.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 mwdCopySelection()
    {
      dictPopup.document.execCommand( "Copy" );
      dictPopup.document.selection.empty();
    }
    
    function mwdGoToWord(w)
    {
      if ( dictPopup.document.selection.type == "Text" )
      {
        mwdCopySelection();
      }
      else
      {
        mwdx(w);
      }
    }
  ]]></script>
  <copyright>
  Copyright (c) 2006 David Bau, Glenn Carr and Kim Gr&#228;sman
  Distributed under the terms of the
  GNU Public License, Version 2 (http://www.gnu.org/copyleft/gpl.txt)
  </copyright>
</search>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
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