text: (function() {
    var bind, emit, expand;
  
    expand = function(text) {
      return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\*(.+?)\*/g, '<i>$1</i>');
    };
  
    emit = function($item, item) {
      var flag, handle, keystroke, parse, report, search, status, success, twins;
      $item.append("<div style=\"width:93%; background:#eee; padding:.8em; margin-bottom:5px; text-align: center;\">\n  <span>" + (expand(item.text)) + "<br></span>\n  <p class=\"caption\">ready</p>\n</div>\n<div class=report></div>");
      flag = function(slug, site) {
        return "<img class=\"remote\"\n  title=\"" + site + "\"\n  src=\"http://" + site + "/favicon.png\"\n  data-site=\"" + site + "\"\n  data-slug=\"" + slug + "\">";
      };
      twins = function(slug, sites) {
        var site;
        return (slug.replace(/-/g, ' ')) + "<br>" + (((function() {
          var i, len, results;
          results = [];
          for (i = 0, len = sites.length; i < len; i++) {
            site = sites[i];
            results.push(flag(slug, site));
          }
          return results;
        })()).join(' '));
      };
      report = function(result) {
        var sites, slug;
        return ((function() {
          var results;
          results = [];
          for (slug in result) {
            sites = result[slug];
            results.push(twins(slug, sites));
          }
          return results;
        })()).join('<br>');
      };
      status = function(text) {
        return $item.find('p.caption').text(text);
      };
      success = function(data) {
        status((Object.keys(data.result).length) + " titles");
        return $item.find('.report').append(report(data.result));
      };
      search = function(request) {
        var url;
        url = "http://" + (item.site || 'search.fed.wiki.org:3030') + "/match";
        console.log('search', request);
        $.post(url, request, success, 'json').fail(function(e) {
          return $item.find('.caption').text("search failed " + e.responseText);
        });
        $item.find('.report').empty();
        return status("searching");
      };
      keystroke = function(e) {
        var input, request;
        if (e.keyCode === 13) {
          input = $item.find('input').val();
          if (input.match(/\w/)) {
            request = $.extend({}, $item.request);
            request.query += " " + input;
            return search(request);
          }
        }
      };
      handle = function(request) {
        if (request.input) {
          $item.request = request;
          return $item.find('span').append('<input type=text style="width: 95%;"></input>').keyup(keystroke);
        } else if (request.search) {
          $item.request = request;
          return $item.find('span').append('<button>search</button>').click(function() {
            return search(request);
          });
        } else {
          return search(request);
        }
      };
      parse = function(text) {
        var request;
        request = {};
        text = text.replace(/\b(AND|OR)\b/g, function(op) {
          request.match = op.toLowerCase();
          return '';
        });
        text = text.replace(/\b(ALL)\b/, function(op) {
          request.match = 'and';
          return '';
        });
        text = text.replace(/\b(ANY)\b/, function(op) {
          request.match = 'or';
          return '';
        });
        text = text.replace(/\b(WORDS|LINKS|SITES|ITEMS|PLUGINS)\b/g, function(op) {
          request.find = op.toLowerCase();
          return '';
        });
        text = text.replace(/\b(INPUT)\b/, function(op) {
          request.input = true;
          return '';
        });
        text = text.replace(/\b(SEARCH)\b/, function(op) {
          request.search = true;
          return '';
        });
        request.query = text;
        return request;
      };
      return handle(parse(item.text));
    };
  
    bind = function($item, item) {
      $item.dblclick(function() {
        return wiki.textEditor($item, item);
      });
      return $item.find('input').dblclick(function() {
        return false;
      });
    };
  
    if (typeof window !== "undefined" && window !== null) {
      window.plugins.search = {
        emit: emit,
        bind: bind
      };
    }
  
    if (typeof module !== "undefined" && module !== null) {
      module.exports = {
        expand: expand
      };
    }
  
  }).call(this);
  
  //# sourceMappingURL=search.js.map
  