From 9e7c4e1004d86ecf1f0ff96540dc2aa4924569fc Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 24 Oct 2016 10:25:28 +0200 Subject: [PATCH 1/7] My first push (snif...) --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ From 49a3c224d5730fb9b7c9a45efdc6827c371ffdc5 Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 24 Oct 2016 15:12:16 +0200 Subject: [PATCH 2/7] Substring vs. Substr --- src/types/substring.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/types/substring.js diff --git a/src/types/substring.js b/src/types/substring.js new file mode 100644 index 0000000..5919d29 --- /dev/null +++ b/src/types/substring.js @@ -0,0 +1,32 @@ +//Substring +var string = 'My name is Bond' + +var a = 3; +var b = 6; +console.log('a =',a,'et b =',b); + +//return the sub string between two positions a and b +var withSubstring = string.substring(a, b); +function verifySubstring(element){ + if(element.length == b-a){ + return true; + } + else + return false; +} +console.log('La fonction Substring renvoit "',withSubstring,'" qui est de taille', withSubstring.length); +console.log(withSubstring,'verifySubstring ? : ', verifySubstring(withSubstring)); + + +// return the sub string of a length b from the position a +var withSubstr = string.substr(a, b); +function verifySubstr(string, element){ + if(element.length == b && string.indexOf(element) == a){ + return true; + } + else + return false; +} + +console.log('La fonction Substr renvoit "',withSubstr,'" qui est de taille',withSubstr.length); +console.log('verifySubst ? : ', verifySubstr(string, withSubstr)); \ No newline at end of file From 49679a763a54a13d2c4b727bceb8dafdf0d60725 Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 24 Oct 2016 15:22:19 +0200 Subject: [PATCH 3/7] toLower vs. toUpper --- src/types/cases.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/types/cases.js diff --git a/src/types/cases.js b/src/types/cases.js new file mode 100644 index 0000000..dc91636 --- /dev/null +++ b/src/types/cases.js @@ -0,0 +1,11 @@ +// tolower vs toupper + +var string = 'My name is Bond' + +//to upper case : tous les caractères de la chaine deviennent des majuscules +var toUpper = string.toUpperCase(); +console.log('La phrase "',string, '" en majuscule, donne : "',toUpper,'".'); + +//to lower case : tous les caractères de la chaine deviennent des minuscules +var toLower = string.toLowerCase(); +console.log('La phrase "',string, '" en minuscule, donne : "',toLower,'".'); \ No newline at end of file From 9362e3a8fd168c5e6d5542197b3820948d4e2dcb Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 25 Oct 2016 16:16:50 +0200 Subject: [PATCH 4/7] YEAAAAAAAAAAAAAAAAAAAAAAAAAH !! --- src/fonctions/closure.js | 25 ++++++++++ src/fonctions/es5.js | 99 +++++++++++++++++++++++++++++++++++++ src/fonctions/foreach.js | 26 ++++++++++ src/fonctions/format.js | 12 +++++ src/fonctions/operations.js | 33 +++++++++++++ src/fonctions/sort.js | 29 +++++++++++ src/types/arrays.js | 77 +++++++++++++++++++++++++++++ src/types/boolean.js | 5 ++ src/types/objects.js | 35 +++++++++++++ src/types/typeof.js | 7 +++ 10 files changed, 348 insertions(+) create mode 100644 src/fonctions/closure.js create mode 100644 src/fonctions/es5.js create mode 100644 src/fonctions/foreach.js create mode 100644 src/fonctions/format.js create mode 100644 src/fonctions/operations.js create mode 100644 src/fonctions/sort.js create mode 100644 src/types/arrays.js create mode 100644 src/types/boolean.js create mode 100644 src/types/objects.js create mode 100644 src/types/typeof.js diff --git a/src/fonctions/closure.js b/src/fonctions/closure.js new file mode 100644 index 0000000..736f569 --- /dev/null +++ b/src/fonctions/closure.js @@ -0,0 +1,25 @@ +var denver = { + name: 'Denver', + age:12 +}; + +var petitPied ={ + name: 'Petit Pied', + age:-65000000 +}; + +function pure(a,b){ + //a.age = 15 ; NOT PURE because it changes a + return a.age + b.age; //PURE : for some input, will always return a value +} + +console.log('pure :', pure(denver, petitPied)) + +function unpure(){ + // "sonsole.log" or "screen()" will modify a stream + // capture the external petitPied object + // depens on external context and not only parameters + console.log('kick '+petitPied.name); +} + +unpure(); \ No newline at end of file diff --git a/src/fonctions/es5.js b/src/fonctions/es5.js new file mode 100644 index 0000000..0ff539f --- /dev/null +++ b/src/fonctions/es5.js @@ -0,0 +1,99 @@ +var topics = require('../data').topics; + +// ******* Filtered topics ******* +var result = topics.filter(function (topic) { + // returns true if we keep this topic + return topic.user.name === 'Leonard'; +}); +console.log('result :', result); + +console.log('########'); + +var resultFat = topics.filter(topic => topic.user.name === 'Leonard'); +console.log('resultFat :', resultFat); + +console.log('########'); + + +// ******* Mapped topics ******* +var titles = topics.map(function (topic) { + return topic.title; +}); +console.log('titles :', titles); + +console.log('########'); + +var fatTitles = topics.map(topic => topic.title); +console.log('titles :', fatTitles); + +// ******* Contain violence ******* + +var hasViolence = topics.some(function (topic) { + return topic.tags.includes('violence'); +}); +console.log('has violence : ', hasViolence); +console.log('########'); + + + +// ******* Sheldon's comments ******* +var filtered = topics.filter(function (topic) { + return topic.comments.some(function (comment) { + return comment.user.name === 'Sheldon'; + }); +}); +console.log('filtered : ', filtered); + +var title = filtered.map(function (topic) { + return topic.title; +}); +console.log('Sheldon Comments : ', title); + +//fat arrow style +var fatFiltered = topics.filter(topic => topic.comments.some(comment => comment.user.name === 'Sheldon')).map(topic => topic.title); +console.log('Fat Sheldon Comments : ', fatFiltered); + + +// ******* Penny's sorted ids comments ******** +var pennyComment = []; +var fatPennyComment = []; + +var sortFunction = function (a, b) { + if (a === b) { + return 0; + } + return a < b ? -1 : 1; +}; + +var filteredPenny = topics.filter(function (topic) { + return topic.comments.forEach(function (comment) { + if (comment.user.name === 'Penny') { + pennyComment.push(comment.id) + } + }); +}); +console.log('filtered : ', pennyComment.sort(sortFunction)); + +//fat arrow style +topics.filter(topic => topic.comments.forEach(comment => comment.user.name === 'Penny' ? fatPennyComment.push(comment.id) : 0)); +console.log('filtered : ', fatPennyComment.sort(sortFunction)); + + +// ******* "Fun" tags for non admin ******** +var tableTag =[]; + +topics.forEach(function (topic){ + topic.comments.forEach(function (comment) { + if(!comment.user.admin && comment.tags != undefined){ + comment.tags.forEach(function (tag) { + if(tag.includes('fun')){ + tableTag.push(comment.content); + } + + }) + } + + }) +}); + +console.log('tags : ', tableTag); \ No newline at end of file diff --git a/src/fonctions/foreach.js b/src/fonctions/foreach.js new file mode 100644 index 0000000..89ecbf7 --- /dev/null +++ b/src/fonctions/foreach.js @@ -0,0 +1,26 @@ +var users = require('../data').users; + +users.forEach(function (user) { + console.log('user name : ', user.name); +}); + +console.log('######'); +// no result sent by clog() +users.forEach(user => console.log('user name : ', user.name)); + + +//************** forEach - display admin users ************** +var admins = []; +var adminsFat = []; + +// function style +users.forEach( function (user){ + if(user.admin === true){ + admins.push(user.name); + } +}); +console.log('result : ',admins); + +//fat arrow style (not very pertinent) +users.forEach( (user) => user.admin ? adminsFat.push(user.name) : ''); +console.log('resultFat : ',adminsFat); \ No newline at end of file diff --git a/src/fonctions/format.js b/src/fonctions/format.js new file mode 100644 index 0000000..de6a97a --- /dev/null +++ b/src/fonctions/format.js @@ -0,0 +1,12 @@ +function add(a, b) { // more safe + return a + b; +} +console.log('2+3 = ', add(2, 3)); + +var mult = function (a, b) { // mult is a variable + return a * b; +}; +console.log('4*3 = ', mult(4,3)); + +var divide = (a,b) => a/b; // fat arrow style (ES2015) +console.log('10/2 =', divide(10,2)); \ No newline at end of file diff --git a/src/fonctions/operations.js b/src/fonctions/operations.js new file mode 100644 index 0000000..4543712 --- /dev/null +++ b/src/fonctions/operations.js @@ -0,0 +1,33 @@ +function add(a, b) { + return a + b; +} + +function divide(a, b) { + return a / b; +} + +function multiply(a, b) { + return a * b; +} + +var minus = function (a, b) { + return a - b; +}; + +console.log('a =', 2, 'b =', 6); +console.log('a*b =', multiply(2, 6)); +console.log('a*b =', divide(2, 6)); +console.log('a*b =', add(2, 6)); +console.log('a*b =', minus(2, 6)); + +function operation(op, x, y) { + return op(x,y); +} + +console.log('add ', operation(add, 56, 59)); +console.log('add ', operation(multiply, 56, 59)); + +var ops = [add, divide, multiply, minus]; + +var rand = ops[Math.floor(Math.random() * ops.length)]; +console.log('add random ', rand ,operation(rand, 56,59)); \ No newline at end of file diff --git a/src/fonctions/sort.js b/src/fonctions/sort.js new file mode 100644 index 0000000..0e8d20d --- /dev/null +++ b/src/fonctions/sort.js @@ -0,0 +1,29 @@ +// ********* classer des nombres dans un tableau ********* + +var x = [0, 3, 5, 6, 10, 12, -12, 45, 34]; +console.log('tableau de x :', x); + +var sortFunction = function (a, b) { + if (a === b) { + return 0; + } + return a < b ? -1 : 1; +}; + +x.sort(sortFunction); +console.log('tableau de x :', x); + + +// ********* classer des objets ********* +var users = require('../data').users; +// console.log('users', users); + +function sortUsers(user1, user2) { + if (user1.name < user2.name) return -1; + if (user1.name > user2.name) return 1; + return 0; + +} + +users.sort(sortUsers); +console.log('users', users.map(user => user.name)); \ No newline at end of file diff --git a/src/types/arrays.js b/src/types/arrays.js new file mode 100644 index 0000000..54056f1 --- /dev/null +++ b/src/types/arrays.js @@ -0,0 +1,77 @@ +var x = [0, 3, 5, 6, 10, 12, -12, 45, 34]; + +// console.log('first :', x[0]); + +// console.log('third :', x[2]); +x[2] = -42; // modification du 3eme élément +// console.log('third :', x[2]); + +// déviation (ne pas faire) +x[-2] = "what ????"; +// console.log('found :', x[-2]); + +// console.log('all table', x); +x[99] = 140; +// console.log('big table now :', x); + + +/* Let's start over and serious stuff */ +x = [0, 3, 5, 6, 10, 12, -12, 45, 34]; + + +// *********** Sorted Array *********** +x.sort(); +console.log('x sorted : ', x); + +x.sort(function (a, b) { + if (a < b) { + return -1; + } + else if (a > b) { + return 1; + } + return 0; + +}); +console.log('x correctly sorted : ', x); + +// Elvis operator +var sortFunction = (a, b) => a < b ? -1 : 1; +x.sort(sortFunction); +console.log('ES 2015 sorted', x); + + +// *********** Filtered Array *********** +var filtered = x.filter(function (number) { + return number >= 0; +}); +console.log('filtered x : ', filtered); + +// Fat Arrow +var filteredFunction = (number) => number >= 0; +filtered = x.filter(filteredFunction); +console.log('filteredFunction : ', filtered); + +// Equivalent direct +direct = x.filter(number => number >= 0); + +// *********** Ajout/Supression d'éléments dans le tableau *********** + +x = [0, 3, 5, 6, 10, 12, -12, 45, 34]; +console.log('tableau de x : ', x); + +// Remove last element +var lastElement = x.pop(); +console.log('tableau de x : ', x); + +// Add last element +x.push(50); +console.log('tableau de x : ', x); + +// Remove first element +var firstElement = x.shift(); +console.log('tableau de x : ', x); + +// Add first element +x.unshift(10); +console.log('tableau de x : ', x); \ No newline at end of file diff --git a/src/types/boolean.js b/src/types/boolean.js new file mode 100644 index 0000000..8cda64c --- /dev/null +++ b/src/types/boolean.js @@ -0,0 +1,5 @@ +console.log('this is bad', 2 == "2"); + +console.log('this is good', 2 === "2"); + +console.log('this is also true',2 !== "2"); \ No newline at end of file diff --git a/src/types/objects.js b/src/types/objects.js new file mode 100644 index 0000000..3fa40de --- /dev/null +++ b/src/types/objects.js @@ -0,0 +1,35 @@ +var x = {}; +console.log('x : ', x, typeof x); + +var john = { + name: 'John', + address: "London", + friend: { + name: 'Jim', + age: 12 + } + +}; + +console.log(john.name, 'lives in ', john.address); +console.log(john.friend.name,'is',john.friend.age); + + +var funkyCop = { + name : 'Robocop' +}; + +var enemy ={ + name : 'Dick' +}; + +funkyCop.foe = enemy; +console.log('funky :',funkyCop); +enemy.foe = funkyCop; +funkyCop.name = "Venere Robocop" +console.log('enemy :',enemy); + +enemy.dead = true; +delete funkyCop.foe; +console.log('funky now :', funkyCop); +console.log('enemy now :', enemy); \ No newline at end of file diff --git a/src/types/typeof.js b/src/types/typeof.js new file mode 100644 index 0000000..97db418 --- /dev/null +++ b/src/types/typeof.js @@ -0,0 +1,7 @@ +console.log(typeof "I am a string"); +console.log(typeof 2); +console.log(typeof {name: 'Jo'}); +console.log(typeof true); +console.log(typeof [2,4]); +var myArray = [2,4] +console.log('is Array ?', Array.isArray(myArray), Array.isArray({name : 'Jim'})); \ No newline at end of file From 2c788e4df083f14c166e8c9b4e242ef9b4bbc45c Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 25 Oct 2016 16:37:08 +0200 Subject: [PATCH 5/7] work on second list --- src/start.html | 31 +++++++++++++++ src/start.js | 2 + src/types/number.js | 14 +++++++ src/types/string.js | 93 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 src/start.js create mode 100644 src/types/number.js create mode 100644 src/types/string.js diff --git a/src/start.html b/src/start.html index f3e471e..0b544c8 100644 --- a/src/start.html +++ b/src/start.html @@ -3,8 +3,39 @@ Starting JS + +

Hello Javascript

+ +

You are so nice !

+ + + + + + \ No newline at end of file diff --git a/src/start.js b/src/start.js new file mode 100644 index 0000000..e3375bf --- /dev/null +++ b/src/start.js @@ -0,0 +1,2 @@ +var x = 2+2; +console.log(x); diff --git a/src/types/number.js b/src/types/number.js new file mode 100644 index 0000000..186a259 --- /dev/null +++ b/src/types/number.js @@ -0,0 +1,14 @@ +var x =2; +console.log(typeof x); + +x = x+0.2; +console.log('x :', x, typeof x); + +x = parseInt('4'); +console.log('x :', x, typeof x); + +var y = parseFloat('2.345'); +console.log('y :', y, typeof y); + +var z = parseFloat('ha ha ha ha'); +console.log('z :', z, typeof z); \ No newline at end of file diff --git a/src/types/string.js b/src/types/string.js new file mode 100644 index 0000000..4c92092 --- /dev/null +++ b/src/types/string.js @@ -0,0 +1,93 @@ +var string = "Hello world"; + +string += " !"; +console.log('string :', string); + +var index1 = string.indexOf('lo'); +console.log('index of lo : ', index1); + +var index2 = string.indexOf('jo'); +console.log('index of lo : ', index2); + +function contains(haystack, needle) { + return haystack.indexOf(needle) >= 0; +} + +var isTrue = contains('Jack', 'ack'); +console.log('Est-ce que "ack" est contenu dans "Jack" ?', isTrue); +var isFalse = contains('Mac Donalds', 'ack'); +console.log('Est-ce que "ack" est contenu dans "Mac Donalds" ?', isFalse); +var isAlsoTrue = contains('Jim', 'Jim'); +console.log('Est-ce que "Jim" est contenu dans "Jim" ?', isAlsoTrue); + +//Equivalent +console.log('Jack is back'.includes('ack')); /*Exist since ES 2015*/ + +/* + * Regular Expression (/.../) + */ + +var hello = "Hello World !"; +var found = hello.search(/orl/); +var alsoFound = hello.search(/world/i); +console.log('found :', found, 'also :', alsoFound); + +// /i for case insensitive +var x = /(.)*(world)/i.test('Hello World !'); +console.log('x :', x); + +// it is conform +var strangelyTrue = /(.)*(world)/i.test('Hello World here'); +console.log('strangelyTrue :', strangelyTrue); + +// not conform : we MUST finish with "world" +var moreStrict = /(.)*(world)$/i.test('Hello World here'); +console.log('moreStrict :', moreStrict); + + + + +//Substring +var string = 'My name is Bond' + +var a = 3; +var b = 6; + +//return the sub string between two positions a and b +var withSubstring = string.substring(a, b); +function verifySubstring(element){ + if(element.length == b-a){ + return true; + } + else + return false; +} +console.log(withSubstring.length); +console.log(withSubstring,'verifySubstring ? : ', verifySubstring(withSubstring)); + + +// return the sub string of a length b from the position a +var withSubstr = string.substr(a, b); +function verifySubstr(string, element){ + if(element.length == b && string.indexOf(element) == a){ + return true; + } + else + return false; +} + +console.log(withSubstr.length); +console.log('verifySubst ? : ', verifySubstr(string, withSubstr)); + + +// tolower vs toupper + +var string = 'My name is Bond' + +//to upper case +var toUpper = string.toUpperCase(); +console.log('La phrase "',string, '" en majuscule, donne : "',toUpper,'".'); + +//to lower case +var toLower = string.toLowerCase(); +console.log('La phrase "',string, '" en minuscule, donne : "',toLower,'".'); \ No newline at end of file From 428949bb549effd057c6308f94c9cc20a9093b24 Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 27 Oct 2016 16:12:29 +0200 Subject: [PATCH 6/7] jquery, before ajax --- src/fonctions/es5.js | 2 +- src/prorotypes/bind.js | 27 ++++++++++++++++++++++ src/prorotypes/priority.js | 18 +++++++++++++++ src/prorotypes/prototype.js | 46 +++++++++++++++++++++++++++++++++++++ src/prorotypes/this.js | 25 ++++++++++++++++++++ src/work/jquery-event.js | 27 ++++++++++++++++++++++ src/work/work.html | 30 ++++++++++++++++++++++-- 7 files changed, 172 insertions(+), 3 deletions(-) diff --git a/src/fonctions/es5.js b/src/fonctions/es5.js index 0ff539f..a14e79f 100644 --- a/src/fonctions/es5.js +++ b/src/fonctions/es5.js @@ -65,7 +65,7 @@ var sortFunction = function (a, b) { return a < b ? -1 : 1; }; -var filteredPenny = topics.filter(function (topic) { +topics.forEach(function (topic) { return topic.comments.forEach(function (comment) { if (comment.user.name === 'Penny') { pennyComment.push(comment.id) diff --git a/src/prorotypes/bind.js b/src/prorotypes/bind.js index e69de29..9088b53 100644 --- a/src/prorotypes/bind.js +++ b/src/prorotypes/bind.js @@ -0,0 +1,27 @@ +function Dinosaurus(name){ + this.size = 12; + this.name = name; +} +Dinosaurus.prototype.age = -65000000; + +const denver = new Dinosaurus('Denver'); + +function Carnivore(){ +} +Carnivore.prototype.eat = function (obj){ + console.log(this.name + ' eats ' + obj.name); +} + +const tRex = new Carnivore(); +tRex.name = 'T Rex'; + +//modification : +const eating = tRex.eat; +eating(tRex); + +//use bind to apply function to an object +boundToDenver = eating.bind(denver); +console.log('bound eating to denver'); +boundToDenver(tRex); + +eating.bind(denver)(tRex); \ No newline at end of file diff --git a/src/prorotypes/priority.js b/src/prorotypes/priority.js index e69de29..19bea6c 100644 --- a/src/prorotypes/priority.js +++ b/src/prorotypes/priority.js @@ -0,0 +1,18 @@ +function Dinosaurus(name){ + this.size = 12; + this.name = name; +} +Dinosaurus.prototype.age = -65000000; +Dinosaurus.prototype.size = 20; + +const denver = new Dinosaurus('Denver'); + +const petitPied = new Dinosaurus('Petit Pied'); + +console.log('denver size : ', denver.size); + +//Denver object is built from a prototype +//But denver has no prototype :( +//console.log('denver prototype size : ', denver.prototype.size); +denver.size = 150; +console.log('new denver size : ', denver.size); \ No newline at end of file diff --git a/src/prorotypes/prototype.js b/src/prorotypes/prototype.js index e69de29..a42b0f8 100644 --- a/src/prorotypes/prototype.js +++ b/src/prorotypes/prototype.js @@ -0,0 +1,46 @@ +/** + * Note that : we have a Uppercase + * It's just a convention + */ + +function Dinosaurus(name){ + this.size = 12; + this.name = name; +} +Dinosaurus.prototype.age = -65000000; + +const denver = new Dinosaurus('Denver'); +// new gives access to a prototype + +const petitPied = new Dinosaurus('Petit Pied'); +petitPied.size = 3; + +console.log('name : ', denver.name); +console.log('size : ', denver.size); +console.log('name : ', petitPied.name); +console.log('size :', petitPied.size); + +console.log('denver age : ',denver.age); +console.log('denver age : ',petitPied.age); + +function TRex(){ + this.name = 'Rex'; +} +function Carnivore(){ +} +Carnivore.prototype.eat = function (obj){ + console.log(this.name + ' eats ' + obj.name); +} + + +// TRex.prototype = Dinosaurus.prototype; +// TRex.prototype = Carnivore.prototype; + +Object.assign(TRex.prototype, Dinosaurus.prototype); +Object.assign(TRex.prototype, Carnivore.prototype); + +const rex = new TRex(); + +console.log('rex age : ', rex.age); +console.log('rex size : ', rex.size); +rex.eat(petitPied); \ No newline at end of file diff --git a/src/prorotypes/this.js b/src/prorotypes/this.js index e69de29..23b1d95 100644 --- a/src/prorotypes/this.js +++ b/src/prorotypes/this.js @@ -0,0 +1,25 @@ +function Dinosaurus(name){ + this.size = 12; + this.name = name; +} +Dinosaurus.prototype.age = -65000000; + +const denver = new Dinosaurus('Denver'); + +function Carnivore(){ +} +Carnivore.prototype.eat = function (obj){ + console.log(this.name + ' eats ' + obj.name); +} + +const tRex = new Carnivore(); +tRex.eat(denver); + +tRex.name = 'T Rex'; +tRex.eat(denver); + +denver.eat = tRex.eat; +denver.eat(tRex); // Object this : denver + +const eating = tRex.eat; +eating(denver); // Object this : {} \ No newline at end of file diff --git a/src/work/jquery-event.js b/src/work/jquery-event.js index e69de29..2505b78 100644 --- a/src/work/jquery-event.js +++ b/src/work/jquery-event.js @@ -0,0 +1,27 @@ +function displaySearch(term) { + clean('section.search'); + var contents = search(term); + contents.forEach(function (content) { + const pElement = $('

').text(content); + $('section.search').append(pElement); + }); +} + +function displaySearchValue() { + displaySearch($('input.search').val()); +} + +/* $('button').on('click', function () { + //const term = $('input.search'); + //console.log('test',term, term.val()); + //displaySearch(term.val()); + displaySearchValue(); + });*/ + +$('button').on('click', displaySearchValue); + +function clean(localisation){ + $(localisation).empty(); +} + +// $('body').text(contents.join(' ')); diff --git a/src/work/work.html b/src/work/work.html index f7e5884..68e848a 100644 --- a/src/work/work.html +++ b/src/work/work.html @@ -2,9 +2,35 @@ - $Title$ + Displaying Amazing Work -$END$ +

Recherche des commentaires comportant le mot :

+ +

Résultats :

+ +
+ + +
+ + + +
Ceci est un footer
+ + + + + + + \ No newline at end of file From 3fc5e36c2e68a493a57bc9d829899fc1ea35b028 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 28 Oct 2016 11:23:41 +0200 Subject: [PATCH 7/7] jquery, after ajax --- src/work/ajax.js | 30 ++++++++++++++++++++++++++++++ src/work/work.html | 8 +++++++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/work/ajax.js diff --git a/src/work/ajax.js b/src/work/ajax.js new file mode 100644 index 0000000..c730a1e --- /dev/null +++ b/src/work/ajax.js @@ -0,0 +1,30 @@ +$.get('http://localhost:3000/api/users/', function(users){ + console.log(users.sort((user1, user2) => user1.name < user2.name ? -1 : 1)); + // console.log(users.sort((user1, user2) => (user1.name).localeCompare(user2.name))); + displayUsers(users); +}); + + +$.get('/api/users/admins/', function(admins){ + console.log('admins', admins.map(admin => admin.name)); +}); + + +function displayUsers(users) { + const block=$('
    '); + users.forEach(function (user){ + const pUser = $('
  • ').text(user.name); + block.append(pUser); + }); + $('section.users').append(block); +} + + +/* +function displayUsers(users){ + const block = $('
    '); + const pUser = users.map(user => $('

    ').text(user.name)); + block.append(pUser); + $('section.users').append(block); +} +*/ diff --git a/src/work/work.html b/src/work/work.html index 68e848a..fe088a7 100644 --- a/src/work/work.html +++ b/src/work/work.html @@ -5,6 +5,12 @@ Displaying Amazing Work + +

    Connected Users

    +
    + +
    +

    Recherche des commentaires comportant le mot :

    Résultats :

    @@ -23,7 +29,7 @@

    Recherche des commentaires comportant le mot :

    - +