Skip to content
Browse files

first rough cut

  • Loading branch information...
1 parent 23eac4f commit 994a004e4a87477f892fcd8e49de4f08faa44889 Pinhook committed Sep 20, 2010
Showing with 977 additions and 0 deletions.
  1. +12 −0 .gitmodules
  2. +1 −0 documentjs
  3. +1 −0 funcunit
  4. +1 −0 jquery
  5. +15 −0 srchr/funcunit.html
  6. +39 −0 srchr/history/history.html
  7. +58 −0 srchr/history/history.js
  8. +5 −0 srchr/history/resources/example.coffee
  9. +13 −0 srchr/history/resources/example.js
  10. +9 −0 srchr/history/resources/example.less
  11. +6 −0 srchr/history/scripts/build.js
  12. +6 −0 srchr/history/scripts/clean.js
  13. +4 −0 srchr/history/search.js
  14. +10 −0 srchr/history/search_history.css
  15. +6 −0 srchr/history/views/add.ejs
  16. +20 −0 srchr/models/flickr.js
  17. +5 −0 srchr/models/search.js
  18. +28 −0 srchr/models/upcoming.js
  19. +20 −0 srchr/models/yahoo.js
  20. +66 −0 srchr/models/yql.js
  21. +20 −0 srchr/qunit.html
  22. +6 −0 srchr/scripts/build.js
  23. +6 −0 srchr/scripts/clean.js
  24. +4 −0 srchr/scripts/docs.js
  25. +6 −0 srchr/search/search.css
  26. +18 −0 srchr/search/search.html
  27. +73 −0 srchr/search/search.js
  28. +19 −0 srchr/search/views/init.ejs
  29. +15 −0 srchr/search_result/funcunit.html
  30. +40 −0 srchr/search_result/funcunit/funcunit.js
  31. +5 −0 srchr/search_result/resources/example.coffee
  32. +13 −0 srchr/search_result/resources/example.js
  33. +9 −0 srchr/search_result/resources/example.less
  34. +6 −0 srchr/search_result/scripts/build.js
  35. +6 −0 srchr/search_result/scripts/clean.js
  36. +10 −0 srchr/search_result/search_result.css
  37. +58 −0 srchr/search_result/search_result.html
  38. +57 −0 srchr/search_result/search_result.js
  39. +7 −0 srchr/search_result/views/results.ejs
  40. +10 −0 srchr/search_types/search_types.css
  41. +18 −0 srchr/search_types/search_types.html
  42. +15 −0 srchr/search_types/search_types.js
  43. +5 −0 srchr/search_types/views/init.ejs
  44. +4 −0 srchr/srchr.css
  45. +33 −0 srchr/srchr.html
  46. +46 −0 srchr/srchr.js
  47. +5 −0 srchr/tabs/resources/example.coffee
  48. +13 −0 srchr/tabs/resources/example.js
  49. +9 −0 srchr/tabs/resources/example.less
  50. +6 −0 srchr/tabs/scripts/build.js
  51. +6 −0 srchr/tabs/scripts/clean.js
  52. +14 −0 srchr/tabs/tabs.css
  53. +18 −0 srchr/tabs/tabs.html
  54. +40 −0 srchr/tabs/tabs.js
  55. +3 −0 srchr/test/funcunit/funcunit.js
  56. +9 −0 srchr/test/funcunit/srchr_test.js
  57. +3 −0 srchr/test/qunit/qunit.js
  58. +5 −0 srchr/test/qunit/srchr_test.js
  59. +4 −0 srchr/views/flickr.ejs
  60. +3 −0 srchr/views/upcoming.ejs
  61. +4 −0 srchr/views/yahoo.ejs
  62. +1 −0 steal
View
12 .gitmodules
@@ -0,0 +1,12 @@
+[submodule "jquery"]
+ path = jquery
+ url = git@github.com:jupiterjs/javascriptmvc.git
+[submodule "steal"]
+ path = steal
+ url = git@github.com:jupiterjs/steal.git
+[submodule "funcunit"]
+ path = funcunit
+ url = git@github.com:jupiterjs/funcunit.git
+[submodule "documentjs"]
+ path = documentjs
+ url = git@github.com:jupiterjs/documentjs.git
1 documentjs
@@ -0,0 +1 @@
+Subproject commit 2796274862526040197e4352011f95fbce3e3013
1 funcunit
@@ -0,0 +1 @@
+Subproject commit 8075484a21cec353abe363c4709affcc62554c8a
1 jquery
@@ -0,0 +1 @@
+Subproject commit 592e38a49015988ae03dea1a9fed1557b02c696a
View
15 srchr/funcunit.html
@@ -0,0 +1,15 @@
+<html>
+ <head>
+ <link rel="stylesheet" type="text/css" href="../funcunit/qunit/qunit.css" />
+ <title>srchr FuncUnit Test</title>
+ <script type='text/javascript' src='../steal/steal.js?srchr/test/funcunit'></script>
+ </head>
+ <body>
+
+ <h1 id="qunit-header">srchr Test Suite</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ </body>
+</html>
View
39 srchr/history/history.html
@@ -0,0 +1,39 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+ <head>
+ <title>search_history</title>
+ </head>
+ <body>
+ <div id='content'></div>
+
+ <form id='searchForm' action=''>
+ <input type='text' id='searchText'>
+ </form>
+ <script type='text/javascript'
+ src='../../steal/steal.js?srchr/history'>
+ </script>
+ <script type='text/javascript' >
+ $.Model.extend("Search",{
+ id: "search"
+ },{});
+
+ $("#content").srchr_history({
+ titleHelper : function(search){
+ return search.search;
+ }
+ });
+
+
+
+ $("#searchForm").submit(function(ev){
+ ev.preventDefault();
+
+ $(this).trigger("search.created",new Search({
+ search : $("#searchText").val()
+ }));
+ $("#searchText").val("")
+ })
+ </script>
+ </body>
+</html>
View
58 srchr/history/history.js
@@ -0,0 +1,58 @@
+steal.plugins('jquery/controller',
+ 'jquery/model/list/cookie',
+ 'jquery/view/ejs').then(function($){
+
+
+
+/**
+ * An abstract list widget that listens for items being created,
+ * shows them in a list, and then saves them in cookies for later retrieval.
+ */
+$.Controller.extend("Srchr.History",
+{
+ defaults : {
+ listenTo : document.documentElement,
+ storeName : "searchHistory",
+ //returns html to be displayed for each item on the list
+ titleHelper : function(instance){
+ return "Item"+instance[instance.Class.id]
+ }
+ }
+},
+{
+ init : function(){
+ this.instances = new $.Model.List.Cookie([]).retrieve(this.options.storeName)
+ this.addInstances(this.instances)
+
+ this.bind(this.options.listenTo, "search.created", "created");
+ },
+ created : function(el, ev, instance){
+ if(!this.instances.get(instance).length){
+ this.instances.push(instance);
+ this.addInstances([instance])
+ }
+
+ },
+ addInstances : function(instances){
+ this.element.append(this.view('add',{
+ data: instances,
+ titleHelper : this.options.titleHelper
+ }));
+ this.instances.store(this.options.storeName);
+ },
+ ".remove click" : function(el, ev){
+ var li = el.closest('li'),
+ toBeRemoved = li.model();
+ this.instances.remove(toBeRemoved);
+ this.instances.store(this.options.storeName);
+ li.fadeOut(function(){
+ el.remove();
+ });
+ ev.stopImmediatePropagation()
+ },
+ "li click" : function(el, ev){
+ $(this.options.listenTo).trigger("search.selected", el.model())
+ }
+})
+
+});
View
5 srchr/history/resources/example.coffee
@@ -0,0 +1,5 @@
+AddToContent "<ul>"
+AddToContent "<li>Include plugins and files in srchr/search_history/search_history.</li>"
+AddToContent "<li>Change to production mode by changing steal.js"
+AddToContent " to steal.production.js in this file.</li>"
+AddToContent "</ul>"
View
13 srchr/history/resources/example.js
@@ -0,0 +1,13 @@
+(function(){
+ var content = [];
+
+ AddToContent = function(newContent){
+ content.push( newContent);
+ };
+ window.onload = function(){
+ document.getElementById('content').innerHTML
+ = content.join("");
+ };
+
+})();
+
View
9 srchr/history/resources/example.less
@@ -0,0 +1,9 @@
+@brand_color: #4D926F;
+@box: 10px;
+h1 {
+ color: @brand_color;
+}
+ul {
+ margin: @box (2*@box);
+ width: (50*@box);
+}
View
6 srchr/history/scripts/build.js
@@ -0,0 +1,6 @@
+//steal/js srchr/search_history/scripts/compress.js
+
+load("steal/rhino/steal.js");
+steal.plugins('steal/build','steal/build/scripts','steal/build/styles',function(){
+ steal.build('srchr/search_history/search_history.html',{to: 'srchr/search_history'});
+});
View
6 srchr/history/scripts/clean.js
@@ -0,0 +1,6 @@
+//steal/js srchr/search_history/scripts/compress.js
+
+load("steal/rhino/steal.js");
+steal.plugins('steal/clean',function(){
+ steal.clean('srchr/search_history/search_history.html',{indent_size: 1, indent_char: '\t'});
+});
View
4 srchr/history/search.js
@@ -0,0 +1,4 @@
+steal.plugins('jquery/model/list').then(function(){
+ $.Model.extend("Srchr.SearchHistory.Search",{},{});
+ $.Model.List.Cookie.extend("Srchr.SearchHistory.SearchList",{},{})
+})
View
10 srchr/history/search_history.css
@@ -0,0 +1,10 @@
+body {font-family: verdana;
+ font-size: 1.4em;
+}
+h1 {
+ padding: 10px;
+}
+p {
+ padding: 10px;
+ margin: 10px;
+}
View
6 srchr/history/views/add.ejs
@@ -0,0 +1,6 @@
+<%for(var i=0; i < data.length; i++){%>
+ <li <%=data[i]%>>
+ <span class='text'><%= titleHelper(data[i])%></span>
+ <a href='javascript://' class='remove'>X</a>
+ </li>
+<%}%>
View
20 srchr/models/flickr.js
@@ -0,0 +1,20 @@
+steal.plugins("jquery/model").then("yql", function(){
+
+$.Model.extend("Srchr.Models.Flickr",{
+ findAll : function(params, success, error){
+ var self= this;
+ $.yql(
+ "SELECT * from flickr.photos.search where has_geo='true' AND text='#{query}'",
+ params,
+ function (data) {
+ success(self.wrapMany(data.query.results.photo))
+ }
+ );
+
+ }
+},{
+
+})
+
+
+});
View
5 srchr/models/search.js
@@ -0,0 +1,5 @@
+steal.plugins('jquery/model').then(function(){
+ $.Model.extend("Srchr.Models.Search",{
+ id: "search"
+ },{});
+})
View
28 srchr/models/upcoming.js
@@ -0,0 +1,28 @@
+
+
+steal.plugins("jquery/model").then("yql", function(){
+
+$.Model.extend("Srchr.Models.Upcoming",{
+ findAll : function(params, success, error){
+ var self= this;
+ $.yql(
+ "SELECT * FROM upcoming.events WHERE description LIKE '%#{query}%' OR name LIKE '%#{query}%' or tags='#{query}'",
+
+ params,
+ function (data) {
+
+ success(self.wrapMany(
+ data.query.count == "1" ? [data.query.results.event]
+ :
+ data.query.results.event
+ ))
+ }
+ );
+
+ }
+},{
+
+})
+
+
+});
View
20 srchr/models/yahoo.js
@@ -0,0 +1,20 @@
+steal.plugins("jquery/model").then("yql", function(){
+
+$.Model.extend("Srchr.Models.Yahoo",{
+ findAll : function(params, success, error){
+ var self= this;
+ $.yql(
+ "SELECT * from search.images where query='#{query}'",
+ params,
+ function (data) {
+ success(self.wrapMany(data.query.results.result))
+ }
+ );
+
+ }
+},{
+
+})
+
+
+});
View
66 srchr/models/yql.js
@@ -0,0 +1,66 @@
+/*
+ * jQuery YQL plugin
+ *
+ * Copyright (c) 2010 Gabriel Falcão
+ * Copyright (c) 2010 Lincoln de Sousa
+ * licensed under MIT license.
+ *
+ * http://github.com/gabrielfalcao/jquery-yql/raw/master/license.txt
+ *
+ * Version: 0.2.2
+ */
+
+(function($){
+ $.extend(
+ {
+ _prepareYQLQuery: function (query, params) {
+ $.each(
+ params, function (key) {
+ var name = new RegExp( "#\{" + key + "\}","g" );
+ var value = $.trim(this);
+ //if (!value.match(/^[0-9]+$/)) {
+ // value = '"' + value + '"';
+ //}
+ query = query.replace(name, value);
+ }
+ );
+ return query;
+ },
+ yql: function (query) {
+ var $self = this;
+ var successCallback = null;
+ var errorCallback = null;
+
+ if (typeof arguments[1] == 'object') {
+ query = $self._prepareYQLQuery(query, arguments[1]);
+ successCallback = arguments[2];
+ errorCallback = arguments[3];
+ } else if (typeof arguments[1] == 'function') {
+ successCallback = arguments[1];
+ errorCallback = arguments[2];
+ }
+
+ var doAsynchronously = successCallback != null;
+ var yqlJson = {
+ url: "http://query.yahooapis.com/v1/public/yql",
+ dataType: "jsonp",
+ success: successCallback,
+ async: doAsynchronously,
+ data: {
+ q: query,
+ format: "json",
+ env: 'store://datatables.org/alltableswithkeys',
+ callback: "?"
+ }
+ }
+
+ if (errorCallback) {
+ yqlJson.error = errorCallback;
+ }
+
+ $.ajax(yqlJson);
+ return $self.toReturn;
+ }
+ }
+ );
+ })(jQuery);
View
20 srchr/qunit.html
@@ -0,0 +1,20 @@
+<html>
+ <head>
+ <link rel="stylesheet" type="text/css" href="../funcunit/qunit/qunit.css" />
+ <title>srchr QUnit Test</title>
+ <script type='text/javascript'>
+ steal = {ignoreControllers: true}
+ </script>
+ <script type='text/javascript' src='../steal/steal.js?srchr/test/qunit'></script>
+ </head>
+ <body>
+
+ <h1 id="qunit-header">srchr Test Suite</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <div id="test-content"></div>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-test-area"></div>
+ </body>
+</html>
View
6 srchr/scripts/build.js
@@ -0,0 +1,6 @@
+//steal/js srchr/scripts/compress.js
+
+load("steal/rhino/steal.js");
+steal.plugins('steal/build','steal/build/scripts','steal/build/styles',function(){
+ steal.build('srchr/srchr.html',{to: 'srchr'});
+});
View
6 srchr/scripts/clean.js
@@ -0,0 +1,6 @@
+//steal/js srchr/scripts/compress.js
+
+load("steal/rhino/steal.js");
+steal.plugins('steal/clean',function(){
+ steal.clean('srchr/srchr.html',{indent_size: 1, indent_char: '\t'});
+});
View
4 srchr/scripts/docs.js
@@ -0,0 +1,4 @@
+//js srchr/scripts/doc.js
+
+_args = ['srchr/srchr.html']
+load("documentjs/document");
View
6 srchr/search/search.css
@@ -0,0 +1,6 @@
+.blurred {
+ color :gray;
+}
+.highlight {
+ background-color: yellow;
+}
View
18 srchr/search/search.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+ <head>
+ <title>search</title>
+ </head>
+ <body>
+
+ <div id='content'></div>
+
+ <script type='text/javascript'
+ src='../../steal/steal.js?srchr/search'>
+ </script>
+ <script type='text/javascript'>
+ $('#content').srchr_search();
+ </script>
+ </body>
+</html>
View
73 srchr/search/search.js
@@ -0,0 +1,73 @@
+steal.plugins('jquery/controller',
+ 'jquery/dom/form_params',
+ 'jquery/view/ejs')
+ .css('search')
+.then(
+ "//srchr/models/search",
+ function($){
+
+/**
+ * Creates a form to search with, searches with it
+ */
+$.Controller.extend("Srchr.Search",
+{
+ defaults : {
+ defaultText : "search for things here"
+ }
+},
+{
+ init : function(){
+ this.element.html(this.view(this.options));
+ this.bind(document.documentElement, "search.selected","searchSelected")
+ },
+ flash : function(el){
+ el.addClass('highlight')
+ setTimeout(function(){
+ el.removeClass('highlight')
+ }, 1000);
+ },
+ "form submit" : function(el, ev){
+ ev.preventDefault();
+ var search = new Srchr.Models.Search(el.formParams()),
+ ok = true;
+ if(!search.types.length){
+ this.flash(this.find('.options'));
+ ok = false;
+ }
+ if(search.query == this.options.defaultText){
+ this.flash(this.find('input[type=text]'));
+ ok = false;
+ }
+
+ if(ok){
+ el.trigger("search.created",search);
+ }
+
+
+ },
+ "input[type=text] focusin" : function(el, ev){
+ if(el.val() == this.options.defaultText){
+ el.val("")
+ }
+ el.removeClass('blurred')
+ },
+ "input[type=text] focusout" : function(el, ev){
+ if(el.val() == ""){
+ el.val(this.options.defaultText).addClass('blurred')
+ }
+ },
+ load : function(){
+ //if we are attached when the page loads, focus on our element
+ this.find("input[name=query]")[0].focus()
+ },
+ searchSelected : function(el, ev, data){
+ this.find("input[name=query]").val(data.query)[0].focus();
+ var checks = this.find("input[type=checkbox]").attr("checked",false);
+ for(var i =0; i < data.types.length; i++){
+ checks.filter("[value="+data.types[i]+"]").attr("checked",true);
+ }
+ }
+});
+
+});
+
View
19 srchr/search/views/init.ejs
@@ -0,0 +1,19 @@
+<form action=''>
+ <input type='text' value='<%=defaultText%>' name='query' class='blurred'/>
+ <input type='submit' value='search' />
+
+ <ul class='options'>
+ <li>
+ Flickr
+ <input type='checkbox' name='types' value='Srchr.Models.Flickr'/>
+ </li>
+ <li>
+ Yahoo
+ <input type='checkbox' name='types' value='Srchr.Models.Yahoo'/>
+ </li>
+ <li>
+ Upcoming
+ <input type='checkbox' name='types' value='Srchr.Models.Upcoming'/>
+ </li>
+ </ul>
+</form>
View
15 srchr/search_result/funcunit.html
@@ -0,0 +1,15 @@
+<html>
+ <head>
+ <link rel="stylesheet" type="text/css" href="../../funcunit/qunit/qunit.css" />
+ <title>srchr FuncUnit Test</title>
+ <script type='text/javascript' src='../../steal/steal.js?srchr/search_result/funcunit'></script>
+ </head>
+ <body>
+
+ <h1 id="qunit-header">srchr Test Suite</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ </body>
+</html>
View
40 srchr/search_result/funcunit/funcunit.js
@@ -0,0 +1,40 @@
+steal
+ .plugins("funcunit").then(function(){
+
+ module("srchr/search_result",{
+ setup : function(){
+ S.open('//srchr/search_result/search_result.html')
+ }
+ })
+
+ test("results shown", function(){
+ S("#searchVal").type("search\r");
+ S("li").exists(function(){
+ ok(true, "results have been shown")
+ })
+ })
+
+ test("results not shown when hidden", function(){
+ S("#toggle").click();
+ S("#searchVal").type("search\r");
+ S.wait(20, function(){
+ equals(S('li').size(), 0, "there are no li's")
+ });
+ });
+
+ test("don't query when hidden", function(){
+ S("#searchVal").type("search\r");
+ S("li").exists(function(){
+ ok(true, "results have been shown")
+ })
+ S("#toggle").click();
+ S("#searchVal").type("\r");
+ S.wait(20, function(){
+ equals(S('#searchNum').text(), "1", "only 1 query")
+
+ })
+
+ })
+
+
+ })
View
5 srchr/search_result/resources/example.coffee
@@ -0,0 +1,5 @@
+AddToContent "<ul>"
+AddToContent "<li>Include plugins and files in srchr/search_result/search_result.</li>"
+AddToContent "<li>Change to production mode by changing steal.js"
+AddToContent " to steal.production.js in this file.</li>"
+AddToContent "</ul>"
View
13 srchr/search_result/resources/example.js
@@ -0,0 +1,13 @@
+(function(){
+ var content = [];
+
+ AddToContent = function(newContent){
+ content.push( newContent);
+ };
+ window.onload = function(){
+ document.getElementById('content').innerHTML
+ = content.join("");
+ };
+
+})();
+
View
9 srchr/search_result/resources/example.less
@@ -0,0 +1,9 @@
+@brand_color: #4D926F;
+@box: 10px;
+h1 {
+ color: @brand_color;
+}
+ul {
+ margin: @box (2*@box);
+ width: (50*@box);
+}
View
6 srchr/search_result/scripts/build.js
@@ -0,0 +1,6 @@
+//steal/js srchr/search_result/scripts/compress.js
+
+load("steal/rhino/steal.js");
+steal.plugins('steal/build','steal/build/scripts','steal/build/styles',function(){
+ steal.build('srchr/search_result/search_result.html',{to: 'srchr/search_result'});
+});
View
6 srchr/search_result/scripts/clean.js
@@ -0,0 +1,6 @@
+//steal/js srchr/search_result/scripts/compress.js
+
+load("steal/rhino/steal.js");
+steal.plugins('steal/clean',function(){
+ steal.clean('srchr/search_result/search_result.html',{indent_size: 1, indent_char: '\t'});
+});
View
10 srchr/search_result/search_result.css
@@ -0,0 +1,10 @@
+body {font-family: verdana;
+ font-size: 1.4em;
+}
+h1 {
+ padding: 10px;
+}
+p {
+ padding: 10px;
+ margin: 10px;
+}
View
58 srchr/search_result/search_result.html
@@ -0,0 +1,58 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+ <head>
+ <title>search_result</title>
+ </head>
+ <body>
+ <form action='' id='searchForm'>
+ <input type='text' id='searchVal'/>
+ </form>
+ <a href="javascript://" id='toggle'>Toggle</a>
+ <div id='searchNum'></div>
+ <div id='content'></div>
+
+
+ <script type='text/javascript'
+ src='../../steal/steal.js?srchr/search_result'>
+ </script>
+ <script type='text/javascript'>
+ SEARCHNUM = 0;
+ Google = {
+ findAll : function(q, success){
+ var results = [];
+ var length = parseInt( Math.random()*100 );
+ for(var i =0; i < length; i++){
+ results.push({
+ title : i+"th search result",
+ text : "foo bar baz",
+ href : "http://blah.com/"+i
+ })
+ }
+ SEARCHNUM++;
+ $("#searchNum").html(SEARCHNUM)
+ success(results)
+ }
+ }
+
+ $("#content").srchr_search_result({
+ modelType : Google
+ })
+ $("#searchForm").submit(function(ev){
+ ev.preventDefault();
+ $("#searchForm").trigger("search.created",{
+ search : $("#searchVal").val()
+ });
+ })
+ $("#toggle").click(function(){
+ var c = $("#content")
+ if(c.is(":visible")){
+ c.hide()
+ }else{
+ c.show();
+ c.trigger("show")
+ }
+ })
+ </script>
+ </body>
+</html>
View
57 srchr/search_result/search_result.js
@@ -0,0 +1,57 @@
+steal.plugins('jquery/controller','jquery/view/ejs').then(function($){
+
+$.Controller.extend("Srchr.SearchResult",{
+ defaults: {
+ listenTo : document.documentElement,
+ resultView : "//srchr/search_result/views/results.ejs"
+ },
+ listensTo : ["show"]
+},{
+ /**
+ * @codestart
+ * $(selector).srchr_search_result({
+ * modelType : Srchr.Models.Google,
+ * listenTo : $('#searchBox')
+ * })
+ * @codeend
+ */
+ init: function(element, options){
+ this.bind(this.options.listenTo, "search.created", "created");
+ },
+
+ "created": function(el, ev, searchInst){
+ this.currentSearch = searchInst.query;
+ if (this.element.is(':visible')){
+ this.getResults();
+ }
+ },
+
+ "show": function(){
+ this.getResults();
+ },
+
+ getResults: function(){
+ // if we have a search
+ if (this.currentSearch){
+
+ // and our search is new ...
+ if(this.searched != this.currentSearch){
+ this.element.html("Searching for "+this.currentSearch)
+ this.options.modelType.findAll({query: this.currentSearch}, this.callback('renderResults'));
+ this.searched = this.currentSearch
+ }
+
+ }else{
+ this.element.html("Enter a search term!")
+ }
+
+ },
+
+ renderResults: function(data){
+ console.log(data)
+ this.element.html(this.view('results',{data: data, options: this.options }));
+ }
+})
+
+});
+
View
7 srchr/search_result/views/results.ejs
@@ -0,0 +1,7 @@
+<ul>
+<%for(var i = 0 ; i < data.length; i++){%>
+ <li>
+ <%= $.View(options.resultView,data[i]) %>
+ </li>
+<%}%>
+</ul>
View
10 srchr/search_types/search_types.css
@@ -0,0 +1,10 @@
+body {font-family: verdana;
+ font-size: 1.4em;
+}
+h1 {
+ padding: 10px;
+}
+p {
+ padding: 10px;
+ margin: 10px;
+}
View
18 srchr/search_types/search_types.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+ <head>
+ <title>search_types</title>
+ </head>
+ <body>
+ <h1>Thanks for stealing StealJS!</h1>
+ <p>Don't worry, it's open source. It's only stealing if you don't do something
+ awesome with it.
+ </p>
+ <div id='content'></div>
+
+ <script type='text/javascript'
+ src='../../steal/steal.js?srchr/search_types'>
+ </script>
+ </body>
+</html>
View
15 srchr/search_types/search_types.js
@@ -0,0 +1,15 @@
+steal.plugins('jquery/controller').then(function($){
+ $.Controller.extend("Srchr.SearchTypes",
+ {
+ defaults : {
+ //name - model pairs
+ models : Srchr.Models
+ }
+ },
+ {
+ init : function(){
+ this.element.html()
+ }
+ })
+})
+
View
5 srchr/search_types/views/init.ejs
@@ -0,0 +1,5 @@
+<ul>
+<%for(var title in models){%>
+ <li><input type='checkbox' name="types" value="<%=models[title].fullName%>"/> <%= title %></li>
+<%}%>
+</ul>
View
4 srchr/srchr.css
@@ -0,0 +1,4 @@
+body {font-family: verdana}
+.error {border: solid 1px red;}
+.error_text { color: red; font-size: 10px;}
+td {padding: 3px;}
View
33 srchr/srchr.html
@@ -0,0 +1,33 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+ <head>
+ <title>srchr</title>
+ <style type='text/css'>
+ body {font-family: verdana}
+ .error {border: solid 1px red;}
+ .error_text { color: red; font-size: 10px;}
+ td {padding: 3px;}
+ </style>
+ </head>
+ <body>
+ <div id='searchArea'></div>
+ <h3>Search History</h3>
+ <ul id='history'></ul>
+
+ <h3>Results</h3>
+
+ <ul id='resultsTab'>
+ <li><a href='#flickr'>Flickr</a></li>
+ <li><a href='#yahoo'>Yahoo</a></li>
+ <li><a href='#upcoming'>Upcoming</a></li>
+ </ul>
+ <div id='flickr'></div>
+ <div id='yahoo'></div>
+ <div id='upcoming'></div>
+
+ <script type='text/javascript'
+ src='../steal/steal.js?srchr,development'>
+ </script>
+ </body>
+</html>
View
46 srchr/srchr.js
@@ -0,0 +1,46 @@
+steal.plugins('srchr/search',
+ 'srchr/history',
+ 'srchr/search_result',
+ 'srchr/tabs')
+ .models('flickr','yahoo','upcoming')
+
+.then(function($){
+
+ $("#searchArea").srchr_search();
+
+ var typePrettyNames = {
+ "Srchr.Models.Flickr" : "f",
+ "Srchr.Models.Yahoo" : "y"
+ }
+
+ $("#history").srchr_history({
+ titleHelper : function(search){
+ var text = search.query
+ types = [];
+ for(var i=0; i < search.types.length; i++){
+ types.push( typePrettyNames[search.types[i]] )
+ }
+ return text+" "+types.join();
+ }
+ });
+
+ $("#resultsTab").srchr_tabs();
+
+ $("#flickr").srchr_search_result({
+ modelType : Srchr.Models.Flickr,
+ resultView : "//srchr/views/flickr.ejs"
+ });
+
+ $("#yahoo").srchr_search_result({
+ modelType : Srchr.Models.Yahoo,
+ resultView : "//srchr/views/yahoo.ejs"
+ });
+
+ $("#upcoming").srchr_search_result({
+ modelType : Srchr.Models.Upcoming,
+ resultView : "//srchr/views/upcoming.ejs"
+ });
+})
+
+
+
View
5 srchr/tabs/resources/example.coffee
@@ -0,0 +1,5 @@
+AddToContent "<ul>"
+AddToContent "<li>Include plugins and files in srchr/tabs/tabs.</li>"
+AddToContent "<li>Change to production mode by changing steal.js"
+AddToContent " to steal.production.js in this file.</li>"
+AddToContent "</ul>"
View
13 srchr/tabs/resources/example.js
@@ -0,0 +1,13 @@
+(function(){
+ var content = [];
+
+ AddToContent = function(newContent){
+ content.push( newContent);
+ };
+ window.onload = function(){
+ document.getElementById('content').innerHTML
+ = content.join("");
+ };
+
+})();
+
View
9 srchr/tabs/resources/example.less
@@ -0,0 +1,9 @@
+@brand_color: #4D926F;
+@box: 10px;
+h1 {
+ color: @brand_color;
+}
+ul {
+ margin: @box (2*@box);
+ width: (50*@box);
+}
View
6 srchr/tabs/scripts/build.js
@@ -0,0 +1,6 @@
+//steal/js srchr/tabs/scripts/compress.js
+
+load("steal/rhino/steal.js");
+steal.plugins('steal/build','steal/build/scripts','steal/build/styles',function(){
+ steal.build('srchr/tabs/tabs.html',{to: 'srchr/tabs'});
+});
View
6 srchr/tabs/scripts/clean.js
@@ -0,0 +1,6 @@
+//steal/js srchr/tabs/scripts/compress.js
+
+load("steal/rhino/steal.js");
+steal.plugins('steal/clean',function(){
+ steal.clean('srchr/tabs/tabs.html',{indent_size: 1, indent_char: '\t'});
+});
View
14 srchr/tabs/tabs.css
@@ -0,0 +1,14 @@
+
+.srchr_tabs { padding: 0px; margin: 0px; }
+.srchr_tabs li { float: left; padding: 10px; background-color: #F6F6F6; list-style: none; margin-left: 10px; }
+.srchr_tabs li a { color: #1C94C4; font-weight: bold; text-decoration: none; }
+.srchr_tabs li.active a { color: #F6A828; cursor: default; }
+.srchr_search_result { border: solid 1px #F6A828; }
+/* clearfix from jQueryUI */
+.ui-helper-clearfix:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
+.ui-helper-clearfix { display: inline-block; }
+/* required comment for clearfix to work in Opera \*/
+* html .ui-helper-clearfix { height:1%; }
+.ui-helper-clearfix { display:block; }
+/* end clearfix */
+​
View
18 srchr/tabs/tabs.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+ <head>
+ <title>tabs</title>
+ </head>
+ <body>
+ <h1>Thanks for stealing StealJS!</h1>
+ <p>Don't worry, it's open source. It's only stealing if you don't do something
+ awesome with it.
+ </p>
+ <div id='content'></div>
+
+ <script type='text/javascript'
+ src='../../steal/steal.js?srchr/tabs'>
+ </script>
+ </body>
+</html>
View
40 srchr/tabs/tabs.js
@@ -0,0 +1,40 @@
+steal.plugins('jquery/controller')
+ .css('tabs')
+ .then(function(){
+
+
+$.Controller.extend("Srchr.Tabs",{
+
+ // initialize code
+ init : function(el){
+
+ // activate the first tab
+ this.activate( $(el).children("li:first") )
+
+ // hide other tabs
+ var tab = this.tab;
+ this.element.addClass('ui-helper-clearfix').children("li:gt(0)").each(function(){
+ tab($(this)).hide()
+ })
+ },
+
+ // helper function finds the tab for a given li
+ tab : function(li){
+ return $(li.find("a").attr("href"))
+ },
+
+ // on an li click, activates new tab
+ "li click" : function(el, ev){
+ ev.preventDefault();
+ this.activate(el)
+ },
+
+ //hides old activate tab, shows new one
+ activate : function(el){
+ this.tab(this.find('.active').removeClass('active')).hide()
+ this.tab(el.addClass('active')).show().trigger("show");
+ }
+})
+
+})
+
View
3 srchr/test/funcunit/funcunit.js
@@ -0,0 +1,3 @@
+steal
+ .plugins("funcunit")
+ .then("srchr_test")
View
9 srchr/test/funcunit/srchr_test.js
@@ -0,0 +1,9 @@
+module("srchr test", {
+ setup: function(){
+ S.open("//srchr/srchr.html");
+ }
+});
+
+test("Copy Test", function(){
+ equals(S("h1").text(), "Welcome to JavaScriptMVC 3.0!","welcome text");
+});
View
3 srchr/test/qunit/qunit.js
@@ -0,0 +1,3 @@
+steal
+ .plugins("funcunit/qunit", "srchr")
+ .then("srchr_test");
View
5 srchr/test/qunit/srchr_test.js
@@ -0,0 +1,5 @@
+module("srchr");
+
+test("srchr testing works", function(){
+ ok(true,"an assert is run");
+});
View
4 srchr/views/flickr.ejs
@@ -0,0 +1,4 @@
+<a href='http://www.flickr.com/photos/<%=owner%>/<%=id%>'>
+ <img src='http://farm<%=farm%>.static.flickr.com/<%=server%>/<%=id%>_<%=secret%>_t.jpg' />
+ <%=title%>
+</a>
View
3 srchr/views/upcoming.ejs
@@ -0,0 +1,3 @@
+
+ <h2><a href='<%= url %>'><%= name%></a></h2>
+ <p><img src='<%= photo_url %>' /><%=description%></p>
View
4 srchr/views/yahoo.ejs
@@ -0,0 +1,4 @@
+<a href='<%= url %>'>
+ <img src='<%= thumbnail_url %>' />
+ <%=title%>
+</a>
1 steal
@@ -0,0 +1 @@
+Subproject commit daa6ea603ae6381eab4662ca7ced9e02ceea84a5

0 comments on commit 994a004

Please sign in to comment.
Something went wrong with that request. Please try again.