Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Version 0.3.0.

  • Loading branch information...
commit 1f608fe50caa13691110c36ee02696dd0a24316b 1 parent 073e20b
@samuelclay samuelclay authored
View
1  .gitignore
@@ -0,0 +1 @@
+.DS_Store
View
6 build-min/visualsearch.js
@@ -5,7 +5,7 @@
For all details and documentation:
http://documentcloud.github.com/visualsearch
*/
-(function(){var c=jQuery;window.VS||(window.VS={});VS.app||(VS.app={});VS.ui||(VS.ui={});VS.model||(VS.model={});VS.utils||(VS.utils={});VS.VERSION="0.3.0";VS.VisualSearch=function(a){var b={container:"",query:"",unquotable:[],remainder:"text",showFacets:!0,callbacks:{search:c.noop,focus:c.noop,blur:c.noop,facetMatches:c.noop,valueMatches:c.noop}};this.options=_.extend({},b,a);this.options.callbacks=_.extend({},b.callbacks,a.callbacks);VS.app.hotkeys.initialize();this.searchQuery=new VS.model.SearchQuery;
+(function(){var c=jQuery;window.VS||(window.VS={});VS.app||(VS.app={});VS.ui||(VS.ui={});VS.model||(VS.model={});VS.utils||(VS.utils={});VS.VERSION="0.3.0";VS.VisualSearch=function(a){var b={container:"",query:"",autosearch:!0,unquotable:[],remainder:"text",showFacets:!0,callbacks:{search:c.noop,focus:c.noop,blur:c.noop,facetMatches:c.noop,valueMatches:c.noop}};this.options=_.extend({},b,a);this.options.callbacks=_.extend({},b.callbacks,a.callbacks);VS.app.hotkeys.initialize();this.searchQuery=new VS.model.SearchQuery;
this.searchBox=new VS.ui.SearchBox({app:this,showFacets:this.options.showFacets});a.container&&(a=this.searchBox.render().el,c(this.options.container).html(a));this.searchBox.value(this.options.query||"");c(window).bind("unload",function(){});return this};VS.init=function(a){return new VS.VisualSearch(a)}})();
(function(){var c=jQuery;VS.ui.SearchBox=Backbone.View.extend({id:"search",events:{"click .VS-cancel-search-box":"clearSearch","mousedown .VS-search-box":"maybeFocusSearch","dblclick .VS-search-box":"highlightSearch","click .VS-search-box":"maybeTripleClick"},initialize:function(){this.app=this.options.app;this.flags={allSelected:!1};this.facetViews=[];this.inputViews=[];_.bindAll(this,"renderFacets","_maybeDisableFacets","disableFacets","deselectAllFacets","addedFacet","removedFacet","changedFacet");
this.app.searchQuery.bind("reset",this.renderFacets).bind("add",this.addedFacet).bind("remove",this.removedFacet).bind("change",this.changedFacet);c(document).bind("keydown",this._maybeDisableFacets)},render:function(){c(this.el).append(JST.search_box({}));c(document.body).setMode("no","search");return this},value:function(a){return null==a?this.serialize():this.setQuery(a)},serialize:function(){var a=[],b=this.inputViews.length;this.app.searchQuery.each(_.bind(function(b,c){a.push(this.inputViews[c].value());
@@ -22,8 +22,8 @@ function(a){return a.isFocused()})||this.$(".VS-search-box").removeClass("VS-foc
this,"access","")}];a=this.facetCategoryMenu||(this.facetCategoryMenu=new dc.ui.Menu({items:a,standalone:!0}));this.$(".VS-icon-search").after(a.render().open().content);return!1}})})();
(function(){var c=jQuery;VS.ui.SearchFacet=Backbone.View.extend({type:"facet",className:"search_facet",events:{"click .category":"selectFacet","keydown input":"keydown","mousedown input":"enableEdit","mouseover .VS-icon-cancel":"showDelete","mouseout .VS-icon-cancel":"hideDelete","click .VS-icon-cancel":"remove"},initialize:function(){this.flags={canClose:!1};_.bindAll(this,"set","keydown","deselectFacet","deferDisableEdit")},render:function(){c(this.el).html(JST.search_facet({model:this.model}));
this.setMode("not","editing");this.setMode("not","selected");this.box=this.$("input");this.box.val(this.model.get("value"));this.box.bind("blur",this.deferDisableEdit);this.box.bind("input propertychange",this.keydown);this.setupAutocomplete();return this},calculateSize:function(){this.box.autoGrowInput();this.box.unbind("updated.autogrow");this.box.bind("updated.autogrow",_.bind(this.moveAutocomplete,this))},resize:function(a){this.box.trigger("resize.autogrow",a)},setupAutocomplete:function(){this.box.autocomplete({source:_.bind(this.autocompleteValues,
-this),minLength:0,delay:0,autoFocus:!0,position:{offset:"0 5"},create:_.bind(function(){c(this.el).find(".ui-autocomplete-input").css("z-index","auto")},this),select:_.bind(function(a,b){a.preventDefault();var c=this.model.get("value");this.set(b.item.value);(c!=b.item.value||this.box.val()!=b.item.value)&&this.search(a);return!1},this),open:_.bind(function(){var a=this.box;this.box.autocomplete("widget").find(".ui-menu-item").each(function(){var b=c(this);b.data("item.autocomplete").value==a.val()&&
-a.data("autocomplete").menu.activate(new c.Event("mouseover"),b)})},this)});this.box.autocomplete("widget").addClass("VS-interface")},moveAutocomplete:function(){var a=this.box.data("autocomplete");a&&a.menu.element.position({my:"left top",at:"left bottom",of:this.box.data("autocomplete").element,collision:"flip",offset:"0 5"})},searchAutocomplete:function(){var a=this.box.data("autocomplete");if(a){var b=a.menu.element;a.search();b.outerWidth(Math.max(b.width("").outerWidth(),a.element.outerWidth()))}},
+this),minLength:0,delay:0,autoFocus:!0,position:{offset:"0 5"},create:_.bind(function(){c(this.el).find(".ui-autocomplete-input").css("z-index","auto")},this),select:_.bind(function(a,b){a.preventDefault();var c=this.model.get("value");this.set(b.item.value);(c!=b.item.value||this.box.val()!=b.item.value)&&this.options.app.options.autosearch&&this.search(a);return!1},this),open:_.bind(function(){var a=this.box;this.box.autocomplete("widget").find(".ui-menu-item").each(function(){var b=c(this);b.data("item.autocomplete").value==
+a.val()&&a.data("autocomplete").menu.activate(new c.Event("mouseover"),b)})},this)});this.box.autocomplete("widget").addClass("VS-interface")},moveAutocomplete:function(){var a=this.box.data("autocomplete");a&&a.menu.element.position({my:"left top",at:"left bottom",of:this.box.data("autocomplete").element,collision:"flip",offset:"0 5"})},searchAutocomplete:function(){var a=this.box.data("autocomplete");if(a){var b=a.menu.element;a.search();b.outerWidth(Math.max(b.width("").outerWidth(),a.element.outerWidth()))}},
closeAutocomplete:function(){var a=this.box.data("autocomplete");a&&a.close()},autocompleteValues:function(a,b){var g=this.model.get("category"),e=this.model.get("value"),d=a.term;this.options.app.options.callbacks.valueMatches(g,d,function(a,g){g=g||{};a=a||[];if(d&&e!=d){if(g.preserveMatches)return a;var h=VS.utils.inflector.escapeRegExp(d||""),i=RegExp("\\b"+h,"i"),a=c.grep(a,function(a){return i.test(a)||i.test(a.value)||i.test(a.label)})}g.preserveOrder?b(a):b(_.sortBy(a,function(a){return a==
e||a.value==e?"":a}))})},set:function(a){a&&this.model.set({value:a})},search:function(a,b){b||(b=1);this.closeAutocomplete();this.options.app.searchBox.searchEvent(a);_.defer(_.bind(function(){this.options.app.searchBox.focusNextFacet(this,b,{viewPosition:this.options.order})},this))},enableEdit:function(){"is"!=this.modes.editing&&(this.setMode("is","editing"),this.deselectFacet(),""==this.box.val()&&this.box.val(this.model.get("value")));this.flags.canClose=!1;this.options.app.searchBox.disableFacets(this);
this.options.app.searchBox.addFocus();_.defer(_.bind(function(){this.options.app.searchBox.addFocus()},this));this.resize();this.searchAutocomplete();this.box.focus()},deferDisableEdit:function(){this.flags.canClose=!0;_.delay(_.bind(function(){this.flags.canClose&&!this.box.is(":focus")&&"is"==this.modes.editing&&"is"!=this.modes.selected&&this.disableEdit()},this),250)},disableEdit:function(){var a=VS.utils.inflector.trim(this.box.val());a!=this.model.get("value")&&this.set(a);this.flags.canClose=
View
BIN  build-min/visualsearch.js.gz
Binary file not shown
View
4 docs/search_facet.html
@@ -62,7 +62,9 @@
<span class="kd">var</span> <span class="nx">originalValue</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">model</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;value&#39;</span><span class="p">);</span>
<span class="k">this</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">ui</span><span class="p">.</span><span class="nx">item</span><span class="p">.</span><span class="nx">value</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">originalValue</span> <span class="o">!=</span> <span class="nx">ui</span><span class="p">.</span><span class="nx">item</span><span class="p">.</span><span class="nx">value</span> <span class="o">||</span> <span class="k">this</span><span class="p">.</span><span class="nx">box</span><span class="p">.</span><span class="nx">val</span><span class="p">()</span> <span class="o">!=</span> <span class="nx">ui</span><span class="p">.</span><span class="nx">item</span><span class="p">.</span><span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">this</span><span class="p">.</span><span class="nx">search</span><span class="p">(</span><span class="nx">e</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">app</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">autosearch</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">search</span><span class="p">(</span><span class="nx">e</span><span class="p">);</span>
+ <span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">},</span> <span class="k">this</span><span class="p">),</span>
View
1  docs/visualsearch.html
@@ -22,6 +22,7 @@
<span class="kd">var</span> <span class="nx">defaults</span> <span class="o">=</span> <span class="p">{</span>
<span class="nx">container</span> <span class="o">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
<span class="nx">query</span> <span class="o">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
+ <span class="nx">autosearch</span> <span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
<span class="nx">unquotable</span> <span class="o">:</span> <span class="p">[],</span>
<span class="nx">remainder</span> <span class="o">:</span> <span class="s1">&#39;text&#39;</span><span class="p">,</span>
<span class="nx">showFacets</span> <span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
Please sign in to comment.
Something went wrong with that request. Please try again.