coursegen 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/Gemfile.lock +3 -3
  4. data/coursegen.gemspec +7 -2
  5. data/lib/coursegen.rb +12 -9
  6. data/lib/coursegen/cli.rb +2 -1
  7. data/lib/coursegen/course/{lib → data}/citem.rb +4 -2
  8. data/lib/coursegen/course/data/data_adaptor.rb +37 -0
  9. data/lib/coursegen/course/{lib → data}/lectures.rb +0 -0
  10. data/lib/coursegen/course/{lib → data}/section.rb +0 -0
  11. data/lib/coursegen/course/{lib → data}/section_def.rb +0 -0
  12. data/lib/coursegen/course/data/toc.rb +160 -0
  13. data/lib/coursegen/course/helpers/bootstrap_markup.rb +64 -0
  14. data/lib/coursegen/course/helpers/content_helpers.rb +10 -5
  15. data/lib/coursegen/course/helpers/list_of.rb +89 -0
  16. data/lib/coursegen/course/helpers/list_of_helpers.rb +19 -0
  17. data/lib/coursegen/course/helpers/navigation_helpers.rb +0 -1
  18. data/lib/coursegen/course/lib/helpers_.rb +1 -1
  19. data/lib/coursegen/course/lib/search_data_generator.rb +9 -3
  20. data/lib/coursegen/course/{lib → schedule}/schedule_def.rb +0 -0
  21. data/lib/coursegen/course/{lib → schedule}/scheduler.rb +0 -0
  22. data/lib/coursegen/templates.rb +10 -0
  23. data/lib/coursegen/version.rb +1 -1
  24. data/templates/Rules +18 -10
  25. data/templates/cg_config.rb +2 -1
  26. data/templates/content/bootstrap/css/custom.css +6 -0
  27. data/templates/content/chalkmark/chalkmark.js +30 -0
  28. data/templates/content/tipuesearch/img/loader.gif +0 -0
  29. data/templates/content/tipuesearch/img/search.png +0 -0
  30. data/templates/content/tipuesearch/tipuesearch_set.js +22 -0
  31. data/templates/content/tipuesearch/tipuesearchmin.js +14 -0
  32. data/templates/content/tipuesearch/tipuesearchnomin.js +444 -0
  33. data/templates/content/tipuesearch_logic/search.md.erb +8 -0
  34. data/templates/content/tipuesearch_logic/tipuesearch_content.js.erb +6 -0
  35. data/templates/layouts/course.html +15 -16
  36. data/templates/layouts/helpful_box.html +3 -0
  37. data/templates/layouts/main_navbar.html.erb +5 -5
  38. metadata +94 -26
  39. data/pkg/coursegen-0.0.1.gem +0 -0
  40. data/pkg/coursegen-0.0.2.gem +0 -0
  41. data/pkg/coursegen-0.0.3.gem +0 -0
@@ -0,0 +1,19 @@
1
+ module ListOfHelpers
2
+
3
+ # source: name of a section as a string
4
+ # rows: array with one or more of:
5
+ # "page"
6
+ # "subsection"
7
+ # cols: array with one or more of:
8
+ # :date
9
+ # :number
10
+ # :title
11
+ # :homeworks
12
+
13
+ def list_of(source:, rows:, cols:)
14
+ markup_adaptor = BootstrapMarkup.new
15
+ data_adaptor = DataAdaptor.new(source)
16
+ lecture_table_builder = ListOf.new(markup_adaptor, data_adaptor, rows, cols)
17
+ lecture_table_builder.render
18
+ end
19
+ end
@@ -32,7 +32,6 @@ module NavigationHelpers
32
32
  link_to_section :pa, item_symbol
33
33
  end
34
34
 
35
-
36
35
  def link_to_section section_symbol, item_symbol
37
36
  the_item = lookup_nitem(section_symbol.to_s, item_symbol.to_s)
38
37
  link_to_unless_current(the_item[:title], the_item.identifier)
@@ -3,7 +3,7 @@ include ContentHelpers
3
3
  include NavigationHelpers
4
4
  include LectureHelpers
5
5
  include SidebarHelpers
6
+ include ListOfHelpers
6
7
  include Nanoc::Helpers::Rendering
7
8
  include Nanoc::Helpers::LinkTo
8
- include Nanoc::Toolbox::Helpers::Navigation
9
9
  include Nanoc::Helpers::Tagging
@@ -2,10 +2,8 @@ class SearchIndex
2
2
  attr_reader :index
3
3
  def initialize all_items
4
4
  all_citems = all_items.map { |itm| Toc.instance.n2c(itm) }
5
- skiplist = Regexp.union([/\/search_index\/.*/, /\/bootstrap\/.*/, /\/config\/.*/, /\/tipuesearch\/.*/])
6
- @index = all_citems.select { |citem| citem.type == "page" && !citem.nitem.binary? && !citem.identifier.match(skiplist)}.map do
5
+ @index = all_citems.select { |citem| include_in_index? (citem)}.map do
7
6
  |item|
8
- # puts "indexing: #{item.title}, match: #{item.identifier.match(skiplist) ? "true" : "false"}"
9
7
  nok_parse = Nokogiri::HTML(item.nitem.compiled_content).at('body')
10
8
  nok_parse_inner_text = nok_parse.nil? ? "" : nok_parse.inner_text
11
9
  { title: clean_string(item.title),
@@ -18,4 +16,12 @@ class SearchIndex
18
16
  def clean_string str
19
17
  str.nil? ? "" : str.gsub(/(\s+|\"|\“|\”)/, " ")
20
18
  end
19
+
20
+ def include_in_index?(citem)
21
+ skiplist = Regexp.union([/\/tipuesearch_logic\/.*/, /\/bootstrap\/.*/, /\/config\/.*/, /\/tipuesearch\/.*/])
22
+ citem.type == "page" &&
23
+ !citem.nitem.binary? &&
24
+ !citem.identifier.match(skiplist)
25
+ end
26
+
21
27
  end
File without changes
@@ -8,6 +8,7 @@ module CourseGen
8
8
  copy_template_dir("layouts", "layouts")
9
9
  copy_template_dir("content/bootstrap", "content/bootstrap")
10
10
  copy_template_dir("content/content", "content/content")
11
+ copy_template_dir("content/chalkmark", "content/chalkmark")
11
12
  delete_target_file("lib/default.rb")
12
13
  copy_template_dir("lib", "lib")
13
14
  delete_target_file("Rules")
@@ -16,6 +17,10 @@ module CourseGen
16
17
  copy_template_file("cg_config.rb_sample", "cg_config.rb_sample")
17
18
  delete_target_file("content/stylesheet.css")
18
19
  delete_target_file("content/index.html")
20
+ delete_target_file("layouts/default.html")
21
+ create_empty_dir("content/images")
22
+ copy_template_dir("content/tipuesearch", "content/tipuesearch")
23
+ copy_template_dir("content/tipuesearch_logic", "content/tipuesearch_logic")
19
24
  end
20
25
 
21
26
  def valid_cg_directory?
@@ -34,11 +39,16 @@ module CourseGen
34
39
  Pathname.new(File.dirname(__FILE__)).parent.parent.to_s
35
40
  end
36
41
 
42
+ # invoke methods from Thor::Actions
37
43
  def initialize
38
44
  super
39
45
  destination_root = Dir.getwd
40
46
  end
41
47
 
48
+ def create_empty_dir to
49
+ empty_directory(to)
50
+ end
51
+
42
52
  def copy_template_dir from, to
43
53
  directory("templates/#{from}", "#{to}")
44
54
  end
@@ -1,3 +1,3 @@
1
1
  module Coursegen
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.6"
3
3
  end
data/templates/Rules CHANGED
@@ -13,7 +13,6 @@
13
13
  # item, use the pattern “/about/*/”; “/about/*” will also select the parent,
14
14
  # because “*” matches zero or more characters.
15
15
 
16
- require 'pry'
17
16
  require './cg_config.rb'
18
17
 
19
18
  preprocess do
@@ -24,15 +23,19 @@ compile '/bootstrap/*' do
24
23
  nil
25
24
  end
26
25
 
27
- compile '/tipuesearch/*' do
26
+ compile '/content/scripts/*' do
28
27
  nil
29
28
  end
30
29
 
31
- compile '/content/scripts/*' do
30
+ compile '/chalkmark/*' do
31
+ nil
32
+ end
33
+
34
+ compile '/tipuesearch/*' do
32
35
  nil
33
36
  end
34
37
 
35
- compile "/search_index/tipuesearch_content/" do
38
+ compile "/tipuesearch_logic/tipuesearch_content" do
36
39
  filter :erb
37
40
  end
38
41
 
@@ -66,23 +69,28 @@ end
66
69
 
67
70
  route '/tipuesearch/*' do
68
71
  @item.identifier.chop + '.' + @item[:extension]
69
- end
72
+ end
73
+
74
+ route "/tipuesearch_logic/tipuesearch_content/" do
75
+ '/tipuesearch/tipuesearch_content.js'
76
+ end
77
+
78
+
79
+ route '/chalkmark/*' do
80
+ @item.identifier.chop + '.' + @item[:extension]
81
+ end
70
82
 
71
83
  route '/content/' do
72
84
  '/index.html'
73
85
  end
74
86
 
75
- route "/search_index/tipuesearch_content/" do
76
- '/tipuesearch/js/tipuesearch_content.js'
77
- end
78
-
79
87
  route '*' do
80
88
  if item[:extension].nil?
81
89
  raise RuntimeError, "Missing required extension: \".#{item.identifier}\""
82
90
  elsif item.binary?
83
91
  # Write item with identifier /foo/ to /foo.ext
84
92
  item.identifier.chop + '.' + item[:extension] rescue binding.pry
85
- elsif item.identifier == "/search_index/tipuesearch_content/"
93
+ elsif item.identifier == "/search_logic/tipuesearch_content/"
86
94
  item.identifier.chop + '.' + item[:extension] rescue binding.pry
87
95
  elsif item[:status] == "hidden"
88
96
  nil
@@ -9,6 +9,7 @@ COURSE_LONG_NAME = "Not a course"
9
9
 
10
10
  # Sections in the right hand margin of the page
11
11
  SECTION_CONFIG = [
12
- SectionDef.new("Background", "background", type: :section)
12
+ SectionDef.new("Background", "background", type: :section),
13
+ SectionDef.new("Hidden", "hidden", hidden: true, type: :section)
13
14
  ]
14
15
 
@@ -102,6 +102,12 @@ footer {
102
102
  }
103
103
 
104
104
  /* Search Page */
105
+
106
+ .h01 {
107
+ color: red;
108
+ font-weight: bold;
109
+ }
110
+
105
111
  #tipue_search_results_count {
106
112
  font-size: 14px;
107
113
  color: red;
@@ -0,0 +1,30 @@
1
+ function handle_helpful_link(yesno) {
2
+ $.ajax({
3
+ url: "http://chalkmark.herokuapp.com/api/helpful/vote/",
4
+ data: {url: document.title, value: yesno},
5
+ dataType: "jsonp",
6
+ success: function(data) { display_visit_stats(data); }}
7
+ )};
8
+
9
+ function display_visit_stats(response) {
10
+ yes_votes = response.true;
11
+ no_votes = response.false;
12
+ if (yes_votes > 0 || no_votes > 0) {
13
+ $("#helpful").addClass("text-center").html("<small>votes so far: Yes: " + response.true + " No: " + response.false + "</small>");
14
+ }
15
+ }
16
+
17
+ $("#yes-link").click( function() { handle_helpful_link("yes");});
18
+ $("#no-link").click( function() { handle_helpful_link("no");});
19
+
20
+ function record_visit() {
21
+ $.ajax({
22
+ url: "http://chalkmark.herokuapp.com/api/helpful/visiting/",
23
+ data: {url: document.title},
24
+ dataType: "jsonp",
25
+ success: function(data) { display_visit_stats(data) }}
26
+ )};
27
+
28
+ $(function() {
29
+ record_visit();
30
+ });
@@ -0,0 +1,22 @@
1
+
2
+ /*
3
+ Tipue Search 4.0
4
+ Copyright (c) 2014 Tipue
5
+ Tipue Search is released under the MIT License
6
+ http://www.tipue.com/search
7
+ */
8
+
9
+
10
+ var tipuesearch_stop_words = ["and", "be", "by", "do", "for", "he", "how", "if", "is", "it", "my", "not", "of", "or", "the", "to", "up", "what", "when"];
11
+
12
+ var tipuesearch_replace = {"words": [
13
+ {"word": "tipua", "replace_with": "tipue"},
14
+ {"word": "javscript", "replace_with": "javascript"}
15
+ ]};
16
+
17
+ var tipuesearch_stem = {"words": [
18
+ {"word": "e-mail", "stem": "email"},
19
+ {"word": "javascript", "stem": "script"},
20
+ {"word": "javascript", "stem": "js"}
21
+ ]};
22
+
@@ -0,0 +1,14 @@
1
+ (function($){$.fn.tipuesearch=function(options){var set=$.extend({"show":7,"newWindow":false,"showURL":true,"minimumLength":3,"descriptiveWords":25,"highlightTerms":true,"highlightEveryTerm":false,"mode":"static","liveDescription":"*","liveContent":"*","contentLocation":"tipuesearch/tipuesearch_content.json"},options);return this.each(function(){var tipuesearch_in={pages:[]};$.ajaxSetup({async:false});if(set.mode=="live")for(var i=0;i<tipuesearch_pages.length;i++)$.get(tipuesearch_pages[i],"",function(html){var cont=
2
+ $(set.liveContent,html).text();cont=cont.replace(/\s+/g," ");var desc=$(set.liveDescription,html).text();desc=desc.replace(/\s+/g," ");var t_1=html.toLowerCase().indexOf("<title>");var t_2=html.toLowerCase().indexOf("</title>",t_1+7);if(t_1!=-1&&t_2!=-1)var tit=html.slice(t_1+7,t_2);else var tit="No title";tipuesearch_in.pages.push({"title":tit,"text":desc,"tags":cont,"loc":tipuesearch_pages[i]})});if(set.mode=="json")$.getJSON(set.contentLocation,function(json){tipuesearch_in=$.extend({},json)});
3
+ if(set.mode=="static")tipuesearch_in=$.extend({},tipuesearch);var tipue_search_w="";if(set.newWindow)tipue_search_w=' target="_blank"';function getURLP(name){return decodeURIComponent(((new RegExp("[?|&]"+name+"="+"([^&;]+?)(&|#|;|$)")).exec(location.search)||[,""])[1].replace(/\+/g,"%20"))||null}if(getURLP("q")){$("#tipue_search_input").val(getURLP("q"));getTipueSearch(0,true)}$(this).keyup(function(event){if(event.keyCode=="13")getTipueSearch(0,true)});function getTipueSearch(start,replace){$("#tipue_search_content").hide();
4
+ var out="";var results="";var show_replace=false;var show_stop=false;var standard=true;var c=0;found=new Array;var d=$("#tipue_search_input").val().toLowerCase();d=$.trim(d);if(d.match('^"')&&d.match('"$')||d.match("^'")&&d.match("'$"))standard=false;if(standard){var d_w=d.split(" ");d="";for(var i=0;i<d_w.length;i++){var a_w=true;for(var f=0;f<tipuesearch_stop_words.length;f++)if(d_w[i]==tipuesearch_stop_words[f]){a_w=false;show_stop=true}if(a_w)d=d+" "+d_w[i]}d=$.trim(d);d_w=d.split(" ")}else d=
5
+ d.substring(1,d.length-1);if(d.length>=set.minimumLength){if(standard){if(replace){var d_r=d;for(var i=0;i<d_w.length;i++)for(var f=0;f<tipuesearch_replace.words.length;f++)if(d_w[i]==tipuesearch_replace.words[f].word){d=d.replace(d_w[i],tipuesearch_replace.words[f].replace_with);show_replace=true}d_w=d.split(" ")}var d_t=d;for(var i=0;i<d_w.length;i++)for(var f=0;f<tipuesearch_stem.words.length;f++)if(d_w[i]==tipuesearch_stem.words[f].word)d_t=d_t+" "+tipuesearch_stem.words[f].stem;d_w=d_t.split(" ");
6
+ for(var i=0;i<tipuesearch_in.pages.length;i++){var score=1E9;var s_t=tipuesearch_in.pages[i].text;for(var f=0;f<d_w.length;f++){var pat=new RegExp(d_w[f],"i");if(tipuesearch_in.pages[i].title.search(pat)!=-1)score-=2E5-i;if(tipuesearch_in.pages[i].text.search(pat)!=-1)score-=15E4-i;if(set.highlightTerms){if(set.highlightEveryTerm)var patr=new RegExp("("+d_w[f]+")","gi");else var patr=new RegExp("("+d_w[f]+")","i");s_t=s_t.replace(patr,'<span class="h01">$1</span>')}if(tipuesearch_in.pages[i].tags.search(pat)!=
7
+ -1)score-=1E5-i;if(d_w[f].match("^-")){pat=new RegExp(d_w[f].substring(1),"i");if(tipuesearch_in.pages[i].title.search(pat)!=-1||tipuesearch_in.pages[i].text.search(pat)!=-1||tipuesearch_in.pages[i].tags.search(pat)!=-1)score=1E9}}if(score<1E9)found[c++]=score+"^"+tipuesearch_in.pages[i].title+"^"+s_t+"^"+tipuesearch_in.pages[i].loc}}else for(var i=0;i<tipuesearch_in.pages.length;i++){var score=1E9;var s_t=tipuesearch_in.pages[i].text;var pat=new RegExp(d,"i");if(tipuesearch_in.pages[i].title.search(pat)!=
8
+ -1)score-=2E5-i;if(tipuesearch_in.pages[i].text.search(pat)!=-1)score-=15E4-i;if(set.highlightTerms){if(set.highlightEveryTerm)var patr=new RegExp("("+d+")","gi");else var patr=new RegExp("("+d+")","i");s_t=s_t.replace(patr,'<span class="h01">$1</span>')}if(tipuesearch_in.pages[i].tags.search(pat)!=-1)score-=1E5-i;if(score<1E9)found[c++]=score+"^"+tipuesearch_in.pages[i].title+"^"+s_t+"^"+tipuesearch_in.pages[i].loc}if(c!=0){if(show_replace==1){out+='<div id="tipue_search_warning_head">Showing results for '+
9
+ d+"</div>";out+='<div id="tipue_search_warning">Search instead for <a href="javascript:void(0)" id="tipue_search_replaced">'+d_r+"</a></div>"}if(c==1)out+='<div id="tipue_search_results_count">1 result</div>';else{c_c=c.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");out+='<div id="tipue_search_results_count">'+c_c+" results</div>"}found.sort();var l_o=0;for(var i=0;i<found.length;i++){var fo=found[i].split("^");if(l_o>=start&&l_o<set.show+start){out+='<div class="tipue_search_content_title"><a href="'+
10
+ fo[3]+'"'+tipue_search_w+">"+fo[1]+"</a></div>";if(set.showURL)out+='<div class="tipue_search_content_url"><a href="'+fo[3]+'"'+tipue_search_w+">"+fo[3]+"</a></div>";var t=fo[2];var t_d="";var t_w=t.split(" ");if(t_w.length<set.descriptiveWords)t_d=t;else for(var f=0;f<set.descriptiveWords;f++)t_d+=t_w[f]+" ";t_d=$.trim(t_d);if(t_d.charAt(t_d.length-1)!=".")t_d+=" ...";out+='<div class="tipue_search_content_text">'+t_d+"</div>"}l_o++}if(c>set.show){var pages=Math.ceil(c/set.show);var page=start/set.show;
11
+ out+='<div id="tipue_search_foot"><ul id="tipue_search_foot_boxes">';if(start>0)out+='<li><a href="javascript:void(0)" class="tipue_search_foot_box" id="'+(start-set.show)+"_"+replace+'">Prev</a></li>';if(page<=2){var p_b=pages;if(pages>3)p_b=3;for(var f=0;f<p_b;f++)if(f==page)out+='<li class="current">'+(f+1)+"</li>";else out+='<li><a href="javascript:void(0)" class="tipue_search_foot_box" id="'+f*set.show+"_"+replace+'">'+(f+1)+"</a></li>"}else{var p_b=page+2;if(p_b>pages)p_b=pages;for(var f=page-
12
+ 1;f<p_b;f++)if(f==page)out+='<li class="current">'+(f+1)+"</li>";else out+='<li><a href="javascript:void(0)" class="tipue_search_foot_box" id="'+f*set.show+"_"+replace+'">'+(f+1)+"</a></li>"}if(page+1!=pages)out+='<li><a href="javascript:void(0)" class="tipue_search_foot_box" id="'+(start+set.show)+"_"+replace+'">Next</a></li>';out+="</ul></div>"}}else out+='<div id="tipue_search_warning_head">Nothing found</div>'}else if(show_stop)out+='<div id="tipue_search_warning_head">Nothing found</div><div id="tipue_search_warning">Common words are largely ignored</div>';
13
+ else{out+='<div id="tipue_search_warning_head">Search too short</div>';if(set.minimumLength==1)out+='<div id="tipue_search_warning">Should be one character or more</div>';else out+='<div id="tipue_search_warning">Should be '+set.minimumLength+" characters or more</div>"}$("#tipue_search_content").html(out);$("#tipue_search_content").slideDown(200);$("#tipue_search_replaced").click(function(){getTipueSearch(0,false)});$(".tipue_search_foot_box").click(function(){var id_v=$(this).attr("id");var id_a=
14
+ id_v.split("_");getTipueSearch(parseInt(id_a[0]),id_a[1])})}})}})(jQuery);
@@ -0,0 +1,444 @@
1
+
2
+ /*
3
+ Tipue Search 4.0
4
+ Copyright (c) 2014 Tipue
5
+ Tipue Search is released under the MIT License
6
+ http://www.tipue.com/search
7
+ */
8
+
9
+
10
+ (function($) {
11
+
12
+ $.fn.tipuesearch = function(options) {
13
+
14
+ var set = $.extend( {
15
+
16
+ 'show' : 7,
17
+ 'newWindow' : false,
18
+ 'showURL' : true,
19
+ 'minimumLength' : 3,
20
+ 'descriptiveWords' : 25,
21
+ 'highlightTerms' : true,
22
+ 'highlightEveryTerm' : false,
23
+ 'mode' : 'static',
24
+ 'liveDescription' : '*',
25
+ 'liveContent' : '*',
26
+ 'contentLocation' : 'tipuesearch/tipuesearch_content.json'
27
+
28
+ }, options);
29
+
30
+ return this.each(function() {
31
+
32
+ var tipuesearch_in = {
33
+ pages: []
34
+ };
35
+ $.ajaxSetup({
36
+ async: false
37
+ });
38
+
39
+ if (set.mode == 'live')
40
+ {
41
+ for (var i = 0; i < tipuesearch_pages.length; i++)
42
+ {
43
+ $.get(tipuesearch_pages[i], '',
44
+ function (html)
45
+ {
46
+ var cont = $(set.liveContent, html).text();
47
+ cont = cont.replace(/\s+/g, ' ');
48
+ var desc = $(set.liveDescription, html).text();
49
+ desc = desc.replace(/\s+/g, ' ');
50
+
51
+ var t_1 = html.toLowerCase().indexOf('<title>');
52
+ var t_2 = html.toLowerCase().indexOf('</title>', t_1 + 7);
53
+ if (t_1 != -1 && t_2 != -1)
54
+ {
55
+ var tit = html.slice(t_1 + 7, t_2);
56
+ }
57
+ else
58
+ {
59
+ var tit = 'No title';
60
+ }
61
+
62
+ tipuesearch_in.pages.push({
63
+ "title": tit,
64
+ "text": desc,
65
+ "tags": cont,
66
+ "loc": tipuesearch_pages[i]
67
+ });
68
+ }
69
+ );
70
+ }
71
+ }
72
+
73
+ if (set.mode == 'json')
74
+ {
75
+ $.getJSON(set.contentLocation,
76
+ function(json)
77
+ {
78
+ tipuesearch_in = $.extend({}, json);
79
+ }
80
+ );
81
+ }
82
+
83
+ if (set.mode == 'static')
84
+ {
85
+ tipuesearch_in = $.extend({}, tipuesearch);
86
+ }
87
+
88
+ var tipue_search_w = '';
89
+ if (set.newWindow)
90
+ {
91
+ tipue_search_w = ' target="_blank"';
92
+ }
93
+
94
+ function getURLP(name)
95
+ {
96
+ return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20')) || null;
97
+ }
98
+ if (getURLP('q'))
99
+ {
100
+ $('#tipue_search_input').val(getURLP('q'));
101
+ getTipueSearch(0, true);
102
+ }
103
+
104
+ $(this).keyup(function(event)
105
+ {
106
+ if(event.keyCode == '13')
107
+ {
108
+ getTipueSearch(0, true);
109
+ }
110
+ });
111
+
112
+ function getTipueSearch(start, replace)
113
+ {
114
+ $('#tipue_search_content').hide();
115
+ var out = '';
116
+ var results = '';
117
+ var show_replace = false;
118
+ var show_stop = false;
119
+ var standard = true;
120
+ var c = 0;
121
+ found = new Array();
122
+
123
+ var d = $('#tipue_search_input').val().toLowerCase();
124
+ d = $.trim(d);
125
+
126
+ if ((d.match("^\"") && d.match("\"$")) || (d.match("^'") && d.match("'$")))
127
+ {
128
+ standard = false;
129
+ }
130
+
131
+ if (standard)
132
+ {
133
+ var d_w = d.split(' ');
134
+ d = '';
135
+ for (var i = 0; i < d_w.length; i++)
136
+ {
137
+ var a_w = true;
138
+ for (var f = 0; f < tipuesearch_stop_words.length; f++)
139
+ {
140
+ if (d_w[i] == tipuesearch_stop_words[f])
141
+ {
142
+ a_w = false;
143
+ show_stop = true;
144
+ }
145
+ }
146
+ if (a_w)
147
+ {
148
+ d = d + ' ' + d_w[i];
149
+ }
150
+ }
151
+ d = $.trim(d);
152
+ d_w = d.split(' ');
153
+ }
154
+ else
155
+ {
156
+ d = d.substring(1, d.length - 1);
157
+ }
158
+
159
+ if (d.length >= set.minimumLength)
160
+ {
161
+ if (standard)
162
+ {
163
+ if (replace)
164
+ {
165
+ var d_r = d;
166
+ for (var i = 0; i < d_w.length; i++)
167
+ {
168
+ for (var f = 0; f < tipuesearch_replace.words.length; f++)
169
+ {
170
+ if (d_w[i] == tipuesearch_replace.words[f].word)
171
+ {
172
+ d = d.replace(d_w[i], tipuesearch_replace.words[f].replace_with);
173
+ show_replace = true;
174
+ }
175
+ }
176
+ }
177
+ d_w = d.split(' ');
178
+ }
179
+
180
+ var d_t = d;
181
+ for (var i = 0; i < d_w.length; i++)
182
+ {
183
+ for (var f = 0; f < tipuesearch_stem.words.length; f++)
184
+ {
185
+ if (d_w[i] == tipuesearch_stem.words[f].word)
186
+ {
187
+ d_t = d_t + ' ' + tipuesearch_stem.words[f].stem;
188
+ }
189
+ }
190
+ }
191
+ d_w = d_t.split(' ');
192
+
193
+ for (var i = 0; i < tipuesearch_in.pages.length; i++)
194
+ {
195
+ var score = 1000000000;
196
+ var s_t = tipuesearch_in.pages[i].text;
197
+ for (var f = 0; f < d_w.length; f++)
198
+ {
199
+ var pat = new RegExp(d_w[f], 'i');
200
+ if (tipuesearch_in.pages[i].title.search(pat) != -1)
201
+ {
202
+ score -= (200000 - i);
203
+ }
204
+ if (tipuesearch_in.pages[i].text.search(pat) != -1)
205
+ {
206
+ score -= (150000 - i);
207
+ }
208
+
209
+ if (set.highlightTerms)
210
+ {
211
+ if (set.highlightEveryTerm)
212
+ {
213
+ var patr = new RegExp('(' + d_w[f] + ')', 'gi');
214
+ }
215
+ else
216
+ {
217
+ var patr = new RegExp('(' + d_w[f] + ')', 'i');
218
+ }
219
+ s_t = s_t.replace(patr, "<span class=\"h01\">$1</span>");
220
+ }
221
+ if (tipuesearch_in.pages[i].tags.search(pat) != -1)
222
+ {
223
+ score -= (100000 - i);
224
+ }
225
+
226
+ if (d_w[f].match("^-"))
227
+ {
228
+ pat = new RegExp(d_w[f].substring(1), 'i');
229
+ if (tipuesearch_in.pages[i].title.search(pat) != -1 || tipuesearch_in.pages[i].text.search(pat) != -1 || tipuesearch_in.pages[i].tags.search(pat) != -1)
230
+ {
231
+ score = 1000000000;
232
+ }
233
+ }
234
+ }
235
+
236
+ if (score < 1000000000)
237
+ {
238
+ found[c++] = score + '^' + tipuesearch_in.pages[i].title + '^' + s_t + '^' + tipuesearch_in.pages[i].loc;
239
+ }
240
+ }
241
+ }
242
+ else
243
+ {
244
+ for (var i = 0; i < tipuesearch_in.pages.length; i++)
245
+ {
246
+ var score = 1000000000;
247
+ var s_t = tipuesearch_in.pages[i].text;
248
+ var pat = new RegExp(d, 'i');
249
+ if (tipuesearch_in.pages[i].title.search(pat) != -1)
250
+ {
251
+ score -= (200000 - i);
252
+ }
253
+ if (tipuesearch_in.pages[i].text.search(pat) != -1)
254
+ {
255
+ score -= (150000 - i);
256
+ }
257
+
258
+ if (set.highlightTerms)
259
+ {
260
+ if (set.highlightEveryTerm)
261
+ {
262
+ var patr = new RegExp('(' + d + ')', 'gi');
263
+ }
264
+ else
265
+ {
266
+ var patr = new RegExp('(' + d + ')', 'i');
267
+ }
268
+ s_t = s_t.replace(patr, "<span class=\"h01\">$1</span>");
269
+ }
270
+ if (tipuesearch_in.pages[i].tags.search(pat) != -1)
271
+ {
272
+ score -= (100000 - i);
273
+ }
274
+
275
+ if (score < 1000000000)
276
+ {
277
+ found[c++] = score + '^' + tipuesearch_in.pages[i].title + '^' + s_t + '^' + tipuesearch_in.pages[i].loc;
278
+ }
279
+ }
280
+ }
281
+
282
+ if (c != 0)
283
+ {
284
+ if (show_replace == 1)
285
+ {
286
+ out += '<div id="tipue_search_warning_head">Showing results for ' + d + '</div>';
287
+ out += '<div id="tipue_search_warning">Search instead for <a href="javascript:void(0)" id="tipue_search_replaced">' + d_r + '</a></div>';
288
+ }
289
+ if (c == 1)
290
+ {
291
+ out += '<div id="tipue_search_results_count">1 result</div>';
292
+ }
293
+ else
294
+ {
295
+ c_c = c.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
296
+ out += '<div id="tipue_search_results_count">' + c_c + ' results</div>';
297
+ }
298
+
299
+ found.sort();
300
+ var l_o = 0;
301
+ for (var i = 0; i < found.length; i++)
302
+ {
303
+ var fo = found[i].split('^');
304
+ if (l_o >= start && l_o < set.show + start)
305
+ {
306
+ out += '<div class="tipue_search_content_title"><a href="' + fo[3] + '"' + tipue_search_w + '>' + fo[1] + '</a></div>';
307
+
308
+ if (set.showURL)
309
+ {
310
+ out += '<div class="tipue_search_content_url"><a href="' + fo[3] + '"' + tipue_search_w + '>' + fo[3] + '</a></div>';
311
+ }
312
+
313
+ var t = fo[2];
314
+ var t_d = '';
315
+ var t_w = t.split(' ');
316
+ if (t_w.length < set.descriptiveWords)
317
+ {
318
+ t_d = t;
319
+ }
320
+ else
321
+ {
322
+ for (var f = 0; f < set.descriptiveWords; f++)
323
+ {
324
+ t_d += t_w[f] + ' ';
325
+ }
326
+ }
327
+ t_d = $.trim(t_d);
328
+ if (t_d.charAt(t_d.length - 1) != '.')
329
+ {
330
+ t_d += ' ...';
331
+ }
332
+ out += '<div class="tipue_search_content_text">' + t_d + '</div>';
333
+ }
334
+ l_o++;
335
+ }
336
+
337
+ if (c > set.show)
338
+ {
339
+ var pages = Math.ceil(c / set.show);
340
+ var page = (start / set.show);
341
+ out += '<div id="tipue_search_foot"><ul id="tipue_search_foot_boxes">';
342
+
343
+ if (start > 0)
344
+ {
345
+ out += '<li><a href="javascript:void(0)" class="tipue_search_foot_box" id="' + (start - set.show) + '_' + replace + '">Prev</a></li>';
346
+ }
347
+
348
+ if (page <= 2)
349
+ {
350
+ var p_b = pages;
351
+ if (pages > 3)
352
+ {
353
+ p_b = 3;
354
+ }
355
+ for (var f = 0; f < p_b; f++)
356
+ {
357
+ if (f == page)
358
+ {
359
+ out += '<li class="current">' + (f + 1) + '</li>';
360
+ }
361
+ else
362
+ {
363
+ out += '<li><a href="javascript:void(0)" class="tipue_search_foot_box" id="' + (f * set.show) + '_' + replace + '">' + (f + 1) + '</a></li>';
364
+ }
365
+ }
366
+ }
367
+ else
368
+ {
369
+ var p_b = page + 2;
370
+ if (p_b > pages)
371
+ {
372
+ p_b = pages;
373
+ }
374
+ for (var f = page - 1; f < p_b; f++)
375
+ {
376
+ if (f == page)
377
+ {
378
+ out += '<li class="current">' + (f + 1) + '</li>';
379
+ }
380
+ else
381
+ {
382
+ out += '<li><a href="javascript:void(0)" class="tipue_search_foot_box" id="' + (f * set.show) + '_' + replace + '">' + (f + 1) + '</a></li>';
383
+ }
384
+ }
385
+ }
386
+
387
+ if (page + 1 != pages)
388
+ {
389
+ out += '<li><a href="javascript:void(0)" class="tipue_search_foot_box" id="' + (start + set.show) + '_' + replace + '">Next</a></li>';
390
+ }
391
+
392
+ out += '</ul></div>';
393
+ }
394
+ }
395
+ else
396
+ {
397
+ out += '<div id="tipue_search_warning_head">Nothing found</div>';
398
+ }
399
+ }
400
+ else
401
+ {
402
+ if (show_stop)
403
+ {
404
+ out += '<div id="tipue_search_warning_head">Nothing found</div><div id="tipue_search_warning">Common words are largely ignored</div>';
405
+ }
406
+ else
407
+ {
408
+ out += '<div id="tipue_search_warning_head">Search too short</div>';
409
+ if (set.minimumLength == 1)
410
+ {
411
+ out += '<div id="tipue_search_warning">Should be one character or more</div>';
412
+ }
413
+ else
414
+ {
415
+ out += '<div id="tipue_search_warning">Should be ' + set.minimumLength + ' characters or more</div>';
416
+ }
417
+ }
418
+ }
419
+
420
+ $('#tipue_search_content').html(out);
421
+ $('#tipue_search_content').slideDown(200);
422
+
423
+ $('#tipue_search_replaced').click(function()
424
+ {
425
+ getTipueSearch(0, false);
426
+ });
427
+
428
+ $('.tipue_search_foot_box').click(function()
429
+ {
430
+ var id_v = $(this).attr('id');
431
+ var id_a = id_v.split('_');
432
+
433
+ getTipueSearch(parseInt(id_a[0]), id_a[1]);
434
+ });
435
+ }
436
+
437
+ });
438
+ };
439
+
440
+ })(jQuery);
441
+
442
+
443
+
444
+