Zero Click jQuery Search Widget

Why do I need this widget?

Authors generally write browser plugins for letting people define the meanings of certain words or perform easy and quick web searches of selected text. It is easy to see that the same features are not available to the user once he/she starts using a different browser or visits that web-page on a different browser/machine that does not have that particular extension/plugin/add-on installed. This is frustrating for the user who might have gotten used to the conveniences provided by that extension.

What I would like to propose is a widget that web-site authors can embed into their web-pages so that users:

  1. Need not externally install extentions for defining words or concepts or getting more information about something they want to know more about.
  2. Get a consistent experience across all browsers and machines that they use. So, if one user sees a page in a certain way, he/she can expect others to also see it in the same way notwithstanding the Browser or Operating System used.

What is the zero click widget?

The zero click search widget searches for a block of selected text using Duck Duck Go's public API and displays the results in an iframe. The result iframe is highly configurable via configuration parameters.

Demos

Select some text in the paragraphs below to see how the widget works and looks like.

  1. Transparent widget

    An operating system (OS) is software, consisting of programs and data, that runs on computers and manages the computer hardware[1] and provides common services for efficient execution of various application software. For hardware functions such as input and output and memory allocation, the operating system acts as an intermediary between application programs and the computer hardware,[2][3] although the application code is usually executed directly by the hardware, but will frequently call the OS or be interrupted by it. Operating systems are found on almost any device that contains a computer—from cellular phones and video game consoles to supercomputers and web servers. Examples of popular modern operating systems for personal computers are Microsoft Windows, Mac OS X, and GNU/Linux.[4]

    Javascript Code:
    $("#p1").zero_clickable({
      id: "a1", 
      singleton: true, 
      clickout: true, 
      css: { color: "#666666", "font-family": "monospace" }
    });
          
  2. Widget with a white background

    Early computers were built to perform a series of single tasks, like a calculator. Operating systems did not exist in their modern and more complex forms until the early 1960s.[5] Some operating system features were developed in the 1950s, such as monitor programs that could automatically run different application programs in succession to speed up processing. Hardware features were added that enabled use of runtime libraries, interrupts, and parallel processing. When personal computers by companies such as Apple Inc., Atari, IBM and Amiga became popular in the 1980s, vendors added operating system features that had previously become widely used on mainframe and mini computers. Later, many features such as graphical user interface were developed specifically for personal computer operating systems.

    Javascript Code:
    $("#p2").zero_clickable({
      id: "a2", 
      singleton: true, 
      clickout: true, 
      proximity: false, 
      css: { color: "#666666" }, 
      onbeforeshow: function(a) { alert("About to show: " + a.attr("id")); }, 
      onbeforeclose: function(a) { alert("About to remove: " + a.attr("id")); }
    });
          
    CSS (stylesheet):
    #a2 {
      background-color: #FFFFFF;
    }
    
  3. Widget with a violet font and light violet background

    An operating system consists of many parts. One of the most important components is the kernel, which controls low-level processes that the average user usually cannot see: it controls how memory is read and written, the order in which processes are executed, how information is received and sent by devices like the monitor, keyboard and mouse, and decides how to interpret information received from networks. The user interface is a component that interacts with the computer user directly, allowing them to control and use programs. The user interface may be graphical with icons and a desktop, or textual, with a command line. Application programming interfaces provide services and code libraries that let applications developers write modular code reusing well defined programming sequences in user space libraries or in the operating system itself. Which features are considered part of the operating system is defined differently in various operating systems. For example, Microsoft Windows considers its user interface to be part of the operating system, while many versions of Linux do not.

    Javascript Code:
    $("#p3").zero_clickable({
      id: "a3", 
      singleton: true, 
      clickout: true, 
      css: { color: "purple", "font-family": "'Segoe UI',Arial,sans-serif" }
    });
          
    CSS (stylesheet):
    #a3 {
      background-color: #FFCEDE;
    }
        
  4. Widget Quick Intro.

    To make any block of text Zero Clickable, you need to do the following:

    1. Include jQuery core, jQuery UI and the zero clickable jQuery plugin in the <head> section of your HTML file.
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js"></script>
      <script src="http://dhruvbird.com/ddb/js/jquery.zero_clickable.min.js"></script>
    2. In a <script> tag, when the document is completely loaded, select the div (or element) containing the text you want to make zero clickable using jQuery's selector mechanism and then call zero_clickable(params) on it where, params should be a hash (object) containing one or more of the following configuration parameters.
      <script type="text/javascript">
      $().ready(function() {
        $("#p1").zero_clickable({
          id: "a1", 
          singleton: true, 
          clickout: true, 
          css: { color: "#666666", "font-family": "monospace" }
        });
      });
      </script>
      In the example above, a DOM element with an id of p1 is the element that contains the text we want to make zero clickable.
    3. In the <head> section of your HTML file, you will also need to include the following basic CSS for styling the widget. You may replace it with your own custom styling.
      <link rel="stylesheet" type="text/css" href="css/jquery.zero_clickable.css" />
      <style type="text/css">
        #a1 {
          background-color: #FFFFFF;
        }
      </style>
    Widget parameters

    The following configurables may be passed to the widget constructor (the zero_clickable() method) to customize the behaviour and look & feel of the wedget. All the fields below are optional.

    1. id: An id to assign to the div that will show the zero click info. This can be used for selecting the div for styling purposes.
      Default: (empty)
    2. unpunct: (true/false) Remove punctuations from the selected text if true. Default: false
    3. max-length: Ignore selected text if number of selected characters are greater than max-length.
      Default: 60
    4. singleton: (true/false) Will allow ONLY 1 instance of this widget on this page if set to true. The value of 'singleton' must be the SAME for ALL invocations of this widget on the same page. The behaviour of the widget is undefined if you use different paramaters when invoked on the same page.
      Default: false
    5. clickout: (true/false) Clicking outside the widget closes it if true. The value of clickout is meaningful ONLY if the 'singleton' flag is set to true.
      Default: false
    6. proximity: (true/false) If true, changes the opacity of the widget based on widget position and the position of the mouse pointer. The value of proximity holds true only if singleton is set to true. If 'proximity' is set to true and 'singleton' is set to false, then the behaviour of this widget can not be defined. Just like 'singleton', if you specify a value for 'proximity' once on a page, you MUST use the same value on all invocations on that page.
      Default: true
    7. cornered: (true/false). If true, the widget will try to start itself at one of the corners of the screen such that it is not under the mouse. sandesh247 suggested this since most selections would be to copy text and not to define a term. Thanks Sandy!! :-) :-)
      Default: true
    8. error-string: The error string to display in the iframe if no matches were found.
    9. css: Other css attributes. The attributes that are forwarded (if using iframe) are: color, font-faimly. By default, color and font-family are copied from the element that has been made zero_clickable.
      Default: (empty)
    Download
    1. Unminified (12kB)
    2. Minified (4kB)
     
    Background Color:
           
    Font Color:
           
    Font Family:
    AaBb AaBb AaBb AaBb
    Font Size:
    14px 16px 18px 20px
    Line Height:
    125% 150% 175% 200%