Skip to content

Instantly share code, notes, and snippets.

@lzsucceed
Last active August 29, 2015 14:02
Show Gist options
  • Save lzsucceed/fabcb4d14de661c34b2d to your computer and use it in GitHub Desktop.
Save lzsucceed/fabcb4d14de661c34b2d to your computer and use it in GitHub Desktop.
// Generated by CoffeeScript 1.7.1
(function() {
var SearchView, searchView,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
SearchView = (function(_super) {
__extends(SearchView, _super);
function SearchView() {
return SearchView.__super__.constructor.apply(this, arguments);
}
SearchView.prototype.el = $('#submitbtn');
SearchView.prototype.initialize = function() {
_.bindAll(this, "searchStart", "makeSelectedTextHighLight");
this.collection = new Dichelp.Collections.SelectedWords;
this.sources = Dichelp.Collections.WebAPIs;
return void 0;
};
SearchView.prototype.events = {
'click': 'searchStart'
};
SearchView.prototype.makeSelectedTextHighLight = function(targetText) {
var resultHtml, textArray;
console.log("set HighLight on text");
textArray = $('#selectionArea').text().split(" ");
resultHtml = "";
_.map(textArray, function(content) {
content = content.trim();
if (content === targetText) {
console.log("==");
return resultHtml = resultHtml + " <span class='text-high-light'> " + content + "</span>";
} else {
return resultHtml = resultHtml + " " + content;
}
});
$('#selectionArea').html(resultHtml);
};
SearchView.prototype.searchStart = function() {
var collectionView, newWord, text;
console.log("search start!");
text = $('#searchtext').val();
if (text === "") {
console.log("empty");
return;
}
text = text.trim();
if (this.collection.where({
word: text
}).length === 0) {
newWord = new Dichelp.Models.SelectedWordModel({
word: text,
urls: this.sources
});
this.collection.add(newWord);
this.makeSelectedTextHighLight(text);
collectionView = new Dichelp.Views.ResultCollections({
model: newWord
});
collectionView.runTask();
} else {
console.log($('#searchtext').val() + "already exists");
}
return void 0;
};
return SearchView;
})(Backbone.View);
searchView = new SearchView;
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment