From 534da8770a7d2f0047c193b19f7a728a7a234108 Mon Sep 17 00:00:00 2001 From: Zuriel Yahav Date: Sun, 15 Jan 2017 05:15:05 +0200 Subject: [PATCH 1/6] html, js, css --- ex10/index.html | 16 ++++++++++++++++ ex10/js.js | 10 ++++++++++ ex10/style.css | 27 +++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 ex10/index.html create mode 100644 ex10/js.js create mode 100644 ex10/style.css diff --git a/ex10/index.html b/ex10/index.html new file mode 100644 index 0000000..5829100 --- /dev/null +++ b/ex10/index.html @@ -0,0 +1,16 @@ + + + + + + +
+ +
    +
  1. java
  2. +
  3. java 22
  4. +
  5. java 333
  6. +
+
+ + diff --git a/ex10/js.js b/ex10/js.js new file mode 100644 index 0000000..86b5dd1 --- /dev/null +++ b/ex10/js.js @@ -0,0 +1,10 @@ +var fff = _.debounce(function() { + if ($( '.input' ).val() === '') { + $( "ol" ).addClass( "hide" ); + } else { + $( "ol" ).removeClass( "hide" ); + } + }, 500) + +$( '.input' ).on('input', function() { fff(); }); + diff --git a/ex10/style.css b/ex10/style.css new file mode 100644 index 0000000..99645c7 --- /dev/null +++ b/ex10/style.css @@ -0,0 +1,27 @@ +div { + margin: 10px; +} + +.input { + width: 250px; + border: 0 solid black; + border-width: 2px; +} + +.hide { + display: none; +} + +ol { + width: 250px; + border: 0 solid black; + border-width: 2px; +} + +li { + border-bottom: 1px dashed black; +} + +.last { + border-bottom: none; +} From 202cde2f1f6e00b085c6f1bc644f7b89935fe065 Mon Sep 17 00:00:00 2001 From: Zuriel Yahav Date: Mon, 16 Jan 2017 06:37:38 +0200 Subject: [PATCH 2/6] add require, ajax --- ex10/getSuggestions.js | 12 ++++++++++++ ex10/index.html | 10 ++++++---- ex10/js.js | 23 ++++++++++++++++------- ex10/render.js | 16 ++++++++++++++++ ex10/style.css | 4 +++- 5 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 ex10/getSuggestions.js create mode 100644 ex10/render.js diff --git a/ex10/getSuggestions.js b/ex10/getSuggestions.js new file mode 100644 index 0000000..42c725f --- /dev/null +++ b/ex10/getSuggestions.js @@ -0,0 +1,12 @@ +define(function() { + return function (url, callback) { + $.ajax({ + url: url, + method: 'GET', + error: function(error) { alert('an error' + error); }, + success: function(data) { + callback(JSON.parse(data)); + } + }); + } +}); diff --git a/ex10/index.html b/ex10/index.html index 5829100..eb8da00 100644 --- a/ex10/index.html +++ b/ex10/index.html @@ -1,15 +1,17 @@ - + Suggestions + + + + +
    -
  1. java
  2. -
  3. java 22
  4. -
  5. java 333
diff --git a/ex10/js.js b/ex10/js.js index 86b5dd1..f5c69b2 100644 --- a/ex10/js.js +++ b/ex10/js.js @@ -1,10 +1,19 @@ -var fff = _.debounce(function() { +requirejs(['render','getSuggestions'], function(render,getSuggestions) { + + var toggleSuggestions = _.debounce(function() { if ($( '.input' ).val() === '') { - $( "ol" ).addClass( "hide" ); - } else { - $( "ol" ).removeClass( "hide" ); + // User deleted all input so we hide suggestions + render.hideSuggestions(); + } else { + // User need same suggestions so lets get same and show it + var q = $( '.input' ).val(); + getSuggestions('http://localhost:8000/?q=' + q, render.showSuggestions); } - }, 500) - -$( '.input' ).on('input', function() { fff(); }); + }, 500); + $(function() { + $( '.input' ).on('input', function() { + toggleSuggestions(); + }); + }); +}); diff --git a/ex10/render.js b/ex10/render.js new file mode 100644 index 0000000..34d5037 --- /dev/null +++ b/ex10/render.js @@ -0,0 +1,16 @@ +define(function() { + // Call me with no data to hide suggestion box + // otherwise i will render "data", (show suggestions) + return { + showSuggestions: function(data) { + $( 'li' ).remove(); + for (var i = 0; i < data.length; ++i) { + $( 'ol' ).append( '
  • ' + data[i] + '
  • '); + } + $( 'ol' ).removeClass( "hide" ); + }, + hideSuggestions: function() { + $( 'ol' ).addClass( "hide" ); + } + } +}); diff --git a/ex10/style.css b/ex10/style.css index 99645c7..5c3b11d 100644 --- a/ex10/style.css +++ b/ex10/style.css @@ -22,6 +22,8 @@ li { border-bottom: 1px dashed black; } -.last { +li:nth-last-child(-n+1) { border-bottom: none; } + + From fe4c902ee5a1fe00b176cb885b24961c5b4d1ae9 Mon Sep 17 00:00:00 2001 From: Zuriel Yahav Date: Mon, 16 Jan 2017 07:48:35 +0200 Subject: [PATCH 3/6] style render --- ex10/render.js | 14 +++++++++----- ex10/style.css | 10 +++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ex10/render.js b/ex10/render.js index 34d5037..7b52c4a 100644 --- a/ex10/render.js +++ b/ex10/render.js @@ -3,11 +3,15 @@ define(function() { // otherwise i will render "data", (show suggestions) return { showSuggestions: function(data) { - $( 'li' ).remove(); - for (var i = 0; i < data.length; ++i) { - $( 'ol' ).append( '
  • ' + data[i] + '
  • '); - } - $( 'ol' ).removeClass( "hide" ); + if (data.length >= 1) { + $( 'li' ).remove(); + for (var i = 0; i < data.length; ++i) { + $( 'ol' ).append( '
  • ' + data[i] + '
  • '); + } + $( 'ol' ).removeClass( "hide" ); + } else { + $( 'ol' ).addClass( "hide" ); + } }, hideSuggestions: function() { $( 'ol' ).addClass( "hide" ); diff --git a/ex10/style.css b/ex10/style.css index 5c3b11d..aa13dea 100644 --- a/ex10/style.css +++ b/ex10/style.css @@ -5,17 +5,21 @@ div { .input { width: 250px; border: 0 solid black; - border-width: 2px; + border-width: 1px; } .hide { display: none; } +* { + box-sizing: border-box; +} + ol { width: 250px; - border: 0 solid black; - border-width: 2px; + border: 1px solid black; + border-width: 1px; } li { From 861d9f6c19f7bd34ea8a7cdc02241c4a44cd9c0f Mon Sep 17 00:00:00 2001 From: Zuriel Yahav Date: Mon, 16 Jan 2017 08:50:05 +0200 Subject: [PATCH 4/6] index seach --- ex10/index.html | 2 +- ex10/search.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 ex10/search.js diff --git a/ex10/index.html b/ex10/index.html index eb8da00..6bf376c 100644 --- a/ex10/index.html +++ b/ex10/index.html @@ -6,7 +6,7 @@ - +
    diff --git a/ex10/search.js b/ex10/search.js new file mode 100644 index 0000000..025c070 --- /dev/null +++ b/ex10/search.js @@ -0,0 +1,50 @@ + +var search = { + toggleSuggestions: { + _.debounce(function() { + if ($( '.input' ).val() === '') { + // User deleted all input so we hide suggestions + render.hideSuggestions(); + } else { + + console.log('typingwwww'); + // User need same suggestions so lets get same and show it + var query = $( '.input' ).val(); + getSuggestions(query , showSuggestions); + } + }, 500); + }, + showSuggestions: function(data) { + // Call me with no data to hide suggestion box + // otherwise i will render "data", (show suggestions) + if (data.length >= 1) { + $( 'li' ).remove(); + for (var i = 0; i < data.length; ++i) { + $( 'ol' ).append( '
  • ' + data[i] + '
  • '); + } + $( 'ol' ).removeClass( "hide" ); + } else { + hideSuggestions(); + } + }, + hideSuggestions: function() { + $( 'ol' ).addClass( "hide" ); + }, + getSuggestions: function(query, callback) { + $.ajax({ + url: 'http://localhost:8000/?q=' + query, + method: 'GET', + error: function(error) { alert('an error' + error); }, + success: function(data) { + callback(JSON.parse(data)); + } + }); + } +}; + +$(function() { + $( '.input' ).on('input', function() { + console.log('typing'); + search.toggleSuggestions(); + }); +}); From ad4e9e66f464a3bc3aed7e64d44d23c8924f017d Mon Sep 17 00:00:00 2001 From: Zuriel Yahav Date: Mon, 16 Jan 2017 09:15:24 +0200 Subject: [PATCH 5/6] add search. :) --- ex10/search.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/ex10/search.js b/ex10/search.js index 025c070..0642cd4 100644 --- a/ex10/search.js +++ b/ex10/search.js @@ -1,19 +1,14 @@ - var search = { - toggleSuggestions: { - _.debounce(function() { + toggleSuggestions: _.debounce(function() { if ($( '.input' ).val() === '') { // User deleted all input so we hide suggestions - render.hideSuggestions(); + search.hideSuggestions(); } else { - - console.log('typingwwww'); // User need same suggestions so lets get same and show it var query = $( '.input' ).val(); - getSuggestions(query , showSuggestions); + search.getSuggestions(query , search.showSuggestions); } - }, 500); - }, + }, 500), showSuggestions: function(data) { // Call me with no data to hide suggestion box // otherwise i will render "data", (show suggestions) @@ -24,7 +19,7 @@ var search = { } $( 'ol' ).removeClass( "hide" ); } else { - hideSuggestions(); + search.hideSuggestions(); } }, hideSuggestions: function() { @@ -44,7 +39,6 @@ var search = { $(function() { $( '.input' ).on('input', function() { - console.log('typing'); search.toggleSuggestions(); }); }); From bd4ef01edec240cb71f705f2297fc2669590a60e Mon Sep 17 00:00:00 2001 From: Zuriel Yahav Date: Mon, 16 Jan 2017 09:29:12 +0200 Subject: [PATCH 6/6] call hideSggestions from getSuggestion --- ex10/search.js | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/ex10/search.js b/ex10/search.js index 0642cd4..1abc5d8 100644 --- a/ex10/search.js +++ b/ex10/search.js @@ -1,26 +1,20 @@ var search = { toggleSuggestions: _.debounce(function() { - if ($( '.input' ).val() === '') { - // User deleted all input so we hide suggestions - search.hideSuggestions(); - } else { - // User need same suggestions so lets get same and show it - var query = $( '.input' ).val(); - search.getSuggestions(query , search.showSuggestions); - } - }, 500), - showSuggestions: function(data) { - // Call me with no data to hide suggestion box - // otherwise i will render "data", (show suggestions) - if (data.length >= 1) { - $( 'li' ).remove(); - for (var i = 0; i < data.length; ++i) { - $( 'ol' ).append( '
  • ' + data[i] + '
  • '); - } - $( 'ol' ).removeClass( "hide" ); - } else { + if ($( '.input' ).val() === '') { + // User deleted all input so we hide suggestions search.hideSuggestions(); + } else { + // User need same suggestions so lets get same and show it + var query = $( '.input' ).val(); + search.getSuggestions(query , search.showSuggestions); + } + }, 500) , + showSuggestions: function(data) { + $( 'li' ).remove(); + for (var i = 0; i < data.length; ++i) { + $( 'ol' ).append( '
  • ' + data[i] + '
  • '); } + $( 'ol' ).removeClass( "hide" ); }, hideSuggestions: function() { $( 'ol' ).addClass( "hide" ); @@ -31,7 +25,11 @@ var search = { method: 'GET', error: function(error) { alert('an error' + error); }, success: function(data) { - callback(JSON.parse(data)); + if (data.length >= 1) { + callback(JSON.parse(data)); + } else { + search.hideSuggestions(); + } } }); }