Permalink
Browse files

click search

  • Loading branch information...
1 parent db48814 commit 55066f552383421a7ef1eeffd72055564f8b4070 @agrberg agrberg committed Nov 6, 2010
Showing with 23 additions and 2 deletions.
  1. +23 −2 public/javascripts/main.js
View
@@ -1,3 +1,14 @@
+function getSelectedText() {
+ if (window.getSelection) {
+ return window.getSelection();
+ }
+ else if (document.selection) {
+ return document.selection.createRange().text;
+ }
+ return null;
+}
+
+
$(function(){
window.Search = Backbone.Model.extend({
urlf: function() {
@@ -66,11 +77,21 @@ $(function(){
events : {
"change #search_term" : "render",
- "click a.search" : "doThing"
+ "click a.search" : "doThing",
+ "click": "narrowSearch"
},
initialize: function() {
- _.bindAll(this, 'render','doThing')
+ _.bindAll(this, 'render','doThing','narrowSearch')
+ },
+
+ narrowSearch: function(event) {
+ var text = getSelectedText()
+ if (text && text != '') {
+ var term = this.get_term() + " " + text
+ this.showTerm(term,true)
+ $("#search_term").val(term)
+ }
},
get_term: function() {

0 comments on commit 55066f5

Please sign in to comment.