astronomy_engine 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e73f373599f23325492d9a1e392fc11da2d1824d
4
- data.tar.gz: c069e0ff45f23febf748bdd5b82344c6c83d462e
3
+ metadata.gz: 27ca3428426f6bcf7b19cf5e6604e4c5880e141e
4
+ data.tar.gz: 1645978cf6220f609b81322f55a6c19a2ce4a067
5
5
  SHA512:
6
- metadata.gz: 09af144a4e60b5a6546d4119ab9c9323b05a8889dc4471df1e5c8eabecaf450a6ff61aa0b479ed65c094ddc339c43a8ac65de01b0498b1b6c1cffd6399d180e5
7
- data.tar.gz: 0ccb9090715c690d1d248d8b8bc68252e50756a303c5b1a8151d1172d60df1cea29e2072b25c9640a3d48fdfa394c6cc54f152c7e273c07c4799732c3410c8a7
6
+ metadata.gz: c9e9db69e110e330b3b11af9b82d52c1e2dcbcb339d94541c1e998e321a26529f1af2a77adcb9d0bb09046815beb3b20952c6bb0b5c4710e1ec5b223ea8a9b61
7
+ data.tar.gz: f98c3d3cafc8c7321e306d7104b400994fead82c54857bc00a9dde75ca08511daf2e3cba6de3a40f7311dfd44f07051297500bfa5f7f30f4ee10c63917acca3c
@@ -1,3 +1,3 @@
1
1
  module AstronomyEngine
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -5,6 +5,7 @@
5
5
  <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
6
6
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
7
7
  <script src="js/main.js"></script>
8
+ <script src="js/debounce.js"></script>
8
9
  <link rel="stylesheet" type="text/css" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
9
10
  <link rel="stylesheet" type="text/css" href="css/style.css">
10
11
  </head>
@@ -14,6 +15,10 @@
14
15
  <div class="container-fluid">
15
16
  <div class="col-md-3">
16
17
  <div id="categories" class="list-group"></div>
18
+ <div class="input-group">
19
+ <span class="input-group-addon">Search</span>
20
+ <input type="text" id="search-box" class="form-control" placeholder="Search" aria-describedby="basic-addon1">
21
+ </div>
17
22
  </div>
18
23
  <div class="col-md-3">
19
24
  <div id="topics" class="list-group initially-hidden"></div>
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Debounce and throttle function's decorator plugin 1.0.5
3
+ *
4
+ * Copyright (c) 2009 Filatov Dmitry (alpha@zforms.ru)
5
+ * Dual licensed under the MIT and GPL licenses:
6
+ * http://www.opensource.org/licenses/mit-license.php
7
+ * http://www.gnu.org/licenses/gpl.html
8
+ *
9
+ */
10
+
11
+ (function ($) {
12
+ $.extend({
13
+ debounce: function (fn, timeout, invokeAsap, ctx) {
14
+ if (arguments.length == 3 && typeof invokeAsap != 'boolean') {
15
+ ctx = invokeAsap;
16
+ invokeAsap = false;
17
+ }
18
+
19
+ var timer;
20
+ return function () {
21
+
22
+ var args = arguments;
23
+ ctx = ctx || this;
24
+
25
+ invokeAsap && !timer && fn.apply(ctx, args);
26
+
27
+ clearTimeout(timer);
28
+
29
+ timer = setTimeout(function () {
30
+ invokeAsap || fn.apply(ctx, args);
31
+ timer = null;
32
+ }, timeout);
33
+ };
34
+ },
35
+
36
+ throttle: function (fn, timeout, ctx) {
37
+ var timer, args, needInvoke;
38
+ return function () {
39
+ args = arguments;
40
+ needInvoke = true;
41
+ ctx = ctx || this;
42
+
43
+ timer || (function () {
44
+ if (needInvoke) {
45
+ fn.apply(ctx, args);
46
+ needInvoke = false;
47
+ timer = setTimeout(arguments.callee, timeout);
48
+ }
49
+ else {
50
+ timer = null;
51
+ }
52
+ })();
53
+ };
54
+ }
55
+ });
56
+ })(jQuery);
@@ -17,18 +17,7 @@ $(document).ready(function () {
17
17
  url: 'categories/' + category + '/topics',
18
18
  type: 'GET',
19
19
  success: function (data) {
20
- topics = $('#topics');
21
- topics.empty();
22
- for (var i in data) {
23
- //var elem = $('<div class="list-group-item">' + data[i].name + '</div>');
24
- //elem.data('foo', 'bar');
25
- var elem = $('<a href="#" class="list-group-item">' + data[i].name + '</a>');
26
- elem.data('name', data[i].name);
27
- elem.data('description', data[i].description);
28
- elem.data('images', data[i].images);
29
- topics.append(elem);
30
- }
31
- topics.fadeIn();
20
+ displayTopics(data);
32
21
  }
33
22
  });
34
23
  })
@@ -41,15 +30,46 @@ $(document).ready(function () {
41
30
  for(var i in target.data('images')) {
42
31
  var keyinfo = "key=AIzaSyAbwKdX2k3t5M6hpAwDpcDCWHTBxtfRvMg";
43
32
  var image = target.data('images')[i] + "?" + keyinfo;
44
- images += '<img src="' + image + '&maxwidth=200" class="image-padding">';
33
+ images += '<img src="' + image + '&maxheight=200" class="image-padding">';
45
34
  }
46
35
  images += '</div>';
47
36
  var description = addLineBreaks(target.data('description'));
48
37
  $('#topic-body').html(images + description);
49
38
  });
50
39
 
40
+ $('#search-box').on('keyup blur', $.debounce(function(event) {
41
+ var search_term = $(event.target).val();
42
+
43
+ var topics = $('#topics');
44
+ if(search_term == '') {
45
+ topics.empty();
46
+ topics.fadeOut();
47
+ return;
48
+ }
49
+
50
+ $.ajax({
51
+ url: 'topics?q=' + search_term,
52
+ type: 'GET',
53
+ success: function (data) {
54
+ displayTopics(data);
55
+ }
56
+ });
57
+ }, 300));
51
58
  });
52
59
 
60
+ function displayTopics(data) {
61
+ topics = $('#topics');
62
+ topics.empty();
63
+ for (var i in data) {
64
+ var elem = $('<a href="#" class="list-group-item">' + data[i].name + '</a>');
65
+ elem.data('name', data[i].name);
66
+ elem.data('description', data[i].description);
67
+ elem.data('images', data[i].images);
68
+ topics.append(elem);
69
+ }
70
+ topics.fadeIn();
71
+ }
72
+
53
73
  function addLineBreaks(text) {
54
74
  return text.replace(/(?:\r\n|\r|\n)/g, '<div class="space-above"></div>');
55
75
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: astronomy_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Aschenbach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-27 00:00:00.000000000 Z
11
+ date: 2015-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,6 +126,7 @@ files:
126
126
  - lib/astronomy_engine/version.rb
127
127
  - lib/public/css/style.css
128
128
  - lib/public/index.html
129
+ - lib/public/js/debounce.js
129
130
  - lib/public/js/main.js
130
131
  - screenshot/example.jpg
131
132
  - spec/astronomy_engine_spec.rb