From a8e4b7150047a83a30f9ef259e5f08d620bacc75 Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Mon, 18 Jul 2016 21:00:18 +0200 Subject: [PATCH 01/10] Filtered tags - needs cleanup --- forum/qa-content/qa-ask.js | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/forum/qa-content/qa-ask.js b/forum/qa-content/qa-ask.js index 5697b828..2e6c9700 100644 --- a/forum/qa-content/qa-ask.js +++ b/forum/qa-content/qa-ask.js @@ -296,3 +296,49 @@ function set_category_description(idprefix) n.innerHTML=desc; } } + +/* + * Feature - Remove unnecessary # from tags, when creating new post (question) + */ + ;(function (document) + { + 'use strict'; + + window.addEventListener('DOMContentLoaded', function() + { + var tags = document.getElementById('tags'); + var askQuestionBtn = document.querySelector('input[value="Zadaj pytanie"]'); + + /*tags.addEventListener('blur', function() + { + + });*/ + + askQuestionBtn.addEventListener('click', function(ev) + { + //// + ev.preventDefault(); + //// + + var hashTags = tags.value.split(' '); + + var filteredTags = hashTags.filter(function(hash) + { + if (hash.indexOf('#') < 0 || hash.toLowerCase().indexOf('c#') > -1) + { + console.log('OK: ', hash); + + return hash; + } else console.log('REMOVED: ', hash); + + }); + + console.log('splitted: ', hashTags, ' >> ', filteredTags); + + tags.value = filteredTags.join(' '); + }); + }); + + + + }(document)); From 196cf09153e76ff6a9480210c084f12b049b4324 Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Mon, 18 Jul 2016 21:27:05 +0200 Subject: [PATCH 02/10] Filtered tags - cleaned code --- forum/qa-content/qa-ask.js | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/forum/qa-content/qa-ask.js b/forum/qa-content/qa-ask.js index 2e6c9700..11509f17 100644 --- a/forum/qa-content/qa-ask.js +++ b/forum/qa-content/qa-ask.js @@ -304,41 +304,28 @@ function set_category_description(idprefix) { 'use strict'; + // wait for DOM to load window.addEventListener('DOMContentLoaded', function() { + // get DOM elements: "tags" input and button "Zadaj pytanie" var tags = document.getElementById('tags'); var askQuestionBtn = document.querySelector('input[value="Zadaj pytanie"]'); - /*tags.addEventListener('blur', function() - { - - });*/ - + // when user clicks "Zadaj pytanie" askQuestionBtn.addEventListener('click', function(ev) - { - //// - ev.preventDefault(); - //// + { + // get written tags and split them + var allTags = tags.value.split(' '); - var hashTags = tags.value.split(' '); - - var filteredTags = hashTags.filter(function(hash) + // filter tags, accept only those without # and those like "C#" + var filteredTags = allTags.filter(function(hash) { if (hash.indexOf('#') < 0 || hash.toLowerCase().indexOf('c#') > -1) - { - console.log('OK: ', hash); - return hash; - } else console.log('REMOVED: ', hash); - }); - console.log('splitted: ', hashTags, ' >> ', filteredTags); - + // put filtered tags into "tags" input - separated by blank space (' ') tags.value = filteredTags.join(' '); }); - }); - - - + }); }(document)); From e4493f53bc9b2d5cbc5ac7bf9919632e208a22a1 Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Tue, 26 Jul 2016 18:38:02 +0200 Subject: [PATCH 03/10] Improvement - include languages with # on second position --- forum/qa-content/qa-ask.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/forum/qa-content/qa-ask.js b/forum/qa-content/qa-ask.js index 11509f17..d0ed81ab 100644 --- a/forum/qa-content/qa-ask.js +++ b/forum/qa-content/qa-ask.js @@ -301,7 +301,7 @@ function set_category_description(idprefix) * Feature - Remove unnecessary # from tags, when creating new post (question) */ ;(function (document) - { + { 'use strict'; // wait for DOM to load @@ -319,9 +319,8 @@ function set_category_description(idprefix) // filter tags, accept only those without # and those like "C#" var filteredTags = allTags.filter(function(hash) - { - if (hash.indexOf('#') < 0 || hash.toLowerCase().indexOf('c#') > -1) - return hash; + { + return hash.indexOf('#') < 0 || hash.indexOf('#') === 1; }); // put filtered tags into "tags" input - separated by blank space (' ') From 4f954a3cee61921c47716cde9bee6da8d0b38b5e Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Wed, 3 Aug 2016 20:24:39 +0200 Subject: [PATCH 04/10] Filtering only # on 0 position and recoded to ES6 syntax --- forum/qa-content/qa-ask.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/forum/qa-content/qa-ask.js b/forum/qa-content/qa-ask.js index d0ed81ab..736ac51c 100644 --- a/forum/qa-content/qa-ask.js +++ b/forum/qa-content/qa-ask.js @@ -300,31 +300,30 @@ function set_category_description(idprefix) /* * Feature - Remove unnecessary # from tags, when creating new post (question) */ - ;(function (document) - { + ;( function ( document ) + { 'use strict'; // wait for DOM to load - window.addEventListener('DOMContentLoaded', function() - { + window.addEventListener( 'DOMContentLoaded', ( ) => { // get DOM elements: "tags" input and button "Zadaj pytanie" - var tags = document.getElementById('tags'); - var askQuestionBtn = document.querySelector('input[value="Zadaj pytanie"]'); + const tags = document.getElementById( 'tags' ); + const askQuestionBtn = document.querySelector( 'input[value="Zadaj pytanie"]' ); // when user clicks "Zadaj pytanie" - askQuestionBtn.addEventListener('click', function(ev) - { + askQuestionBtn.addEventListener( 'click', ( ev ) => { // get written tags and split them - var allTags = tags.value.split(' '); + const allTags = tags.value.split( ' ' ); // filter tags, accept only those without # and those like "C#" - var filteredTags = allTags.filter(function(hash) - { - return hash.indexOf('#') < 0 || hash.indexOf('#') === 1; - }); + let filteredTags = []; + + allTags.forEach( ( hash ) => { + hash.indexOf( '#' ) === 0 ? filteredTags.push( hash.slice( 1 ) ) : filteredTags.push( hash ); + } ); // put filtered tags into "tags" input - separated by blank space (' ') - tags.value = filteredTags.join(' '); - }); - }); - }(document)); + tags.value = filteredTags.join( ' ' ); + } ); + } ); + } ( document ) ); From b128465348378126ae7bdeae52d495507b1c3920 Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Wed, 3 Aug 2016 22:10:22 +0200 Subject: [PATCH 05/10] [fix] IIFE in ES6 --- forum/qa-content/qa-ask.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/forum/qa-content/qa-ask.js b/forum/qa-content/qa-ask.js index 736ac51c..b02d4e37 100644 --- a/forum/qa-content/qa-ask.js +++ b/forum/qa-content/qa-ask.js @@ -300,18 +300,17 @@ function set_category_description(idprefix) /* * Feature - Remove unnecessary # from tags, when creating new post (question) */ - ;( function ( document ) - { - 'use strict'; + ;( ( document ) => { + 'use strict'; - // wait for DOM to load - window.addEventListener( 'DOMContentLoaded', ( ) => { + // wait for DOM to load + window.addEventListener( 'DOMContentLoaded', ( ) => { // get DOM elements: "tags" input and button "Zadaj pytanie" const tags = document.getElementById( 'tags' ); const askQuestionBtn = document.querySelector( 'input[value="Zadaj pytanie"]' ); // when user clicks "Zadaj pytanie" - askQuestionBtn.addEventListener( 'click', ( ev ) => { + askQuestionBtn.addEventListener( 'click', ( ev ) => { // get written tags and split them const allTags = tags.value.split( ' ' ); @@ -324,6 +323,6 @@ function set_category_description(idprefix) // put filtered tags into "tags" input - separated by blank space (' ') tags.value = filteredTags.join( ' ' ); - } ); + } ); } ); - } ( document ) ); + } ) ( document ); \ No newline at end of file From 9fac8bdc6faeb2168955f1179b3fea5c4adbcbad Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Fri, 5 Aug 2016 21:46:44 +0200 Subject: [PATCH 06/10] Some code optimistation and ES6 simple code block instead of IIFE --- forum/qa-content/qa-ask.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/forum/qa-content/qa-ask.js b/forum/qa-content/qa-ask.js index b02d4e37..a8b1e2db 100644 --- a/forum/qa-content/qa-ask.js +++ b/forum/qa-content/qa-ask.js @@ -297,32 +297,38 @@ function set_category_description(idprefix) } } -/* +/** * Feature - Remove unnecessary # from tags, when creating new post (question) */ - ;( ( document ) => { +{ + 'use strict'; // wait for DOM to load window.addEventListener( 'DOMContentLoaded', ( ) => { + // get DOM elements: "tags" input and button "Zadaj pytanie" const tags = document.getElementById( 'tags' ); const askQuestionBtn = document.querySelector( 'input[value="Zadaj pytanie"]' ); // when user clicks "Zadaj pytanie" - askQuestionBtn.addEventListener( 'click', ( ev ) => { - // get written tags and split them - const allTags = tags.value.split( ' ' ); + askQuestionBtn.addEventListener( 'click', ( ) => { - // filter tags, accept only those without # and those like "C#" - let filteredTags = []; + let allTags = tags.value.split( ' ' ); - allTags.forEach( ( hash ) => { - hash.indexOf( '#' ) === 0 ? filteredTags.push( hash.slice( 1 ) ) : filteredTags.push( hash ); - } ); + /* + * Filter tags: when a single tag has # character on 0 position, remove it + * For example: "#problem" will be filtered to "problem" + */ + for ( let i = 0, len = allTags.length; i < len; i++ ) { + + if ( allTags[ i ].indexOf( '#' ) === 0 ) + allTags[ i ] = allTags[ i ].slice( 1 ); + + } - // put filtered tags into "tags" input - separated by blank space (' ') - tags.value = filteredTags.join( ' ' ); } ); + } ); - } ) ( document ); \ No newline at end of file + + }; \ No newline at end of file From 8fac3a91bf3d15365334f518f8f2e6221a91e0d0 Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Mon, 24 Oct 2016 21:22:40 +0200 Subject: [PATCH 07/10] Changed syntax from ES6 to ES5 --- forum/qa-content/qa-ask.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/forum/qa-content/qa-ask.js b/forum/qa-content/qa-ask.js index a8b1e2db..a93abd5b 100644 --- a/forum/qa-content/qa-ask.js +++ b/forum/qa-content/qa-ask.js @@ -300,35 +300,36 @@ function set_category_description(idprefix) /** * Feature - Remove unnecessary # from tags, when creating new post (question) */ -{ +( function(document) { 'use strict'; // wait for DOM to load - window.addEventListener( 'DOMContentLoaded', ( ) => { + window.addEventListener( 'DOMContentLoaded', function() { // get DOM elements: "tags" input and button "Zadaj pytanie" - const tags = document.getElementById( 'tags' ); - const askQuestionBtn = document.querySelector( 'input[value="Zadaj pytanie"]' ); + var tags = document.getElementById( 'tags' ); + var askQuestionBtn = document.querySelector( 'input[value="Zadaj pytanie"]' ); // when user clicks "Zadaj pytanie" - askQuestionBtn.addEventListener( 'click', ( ) => { + askQuestionBtn.addEventListener( 'click', function() { - let allTags = tags.value.split( ' ' ); + var allTags = tags.value.split( ' ' ); /* * Filter tags: when a single tag has # character on 0 position, remove it * For example: "#problem" will be filtered to "problem" */ - for ( let i = 0, len = allTags.length; i < len; i++ ) { + for ( var i = 0, len = allTags.length; i < len; i++ ) { - if ( allTags[ i ].indexOf( '#' ) === 0 ) + if ( allTags[ i ].indexOf( '#' ) === 0 ) { allTags[ i ] = allTags[ i ].slice( 1 ); - + } + } } ); } ); - }; \ No newline at end of file + } ( document ) ); \ No newline at end of file From 70529ce442a4f450cd0b5ca0e944c4c5bb01a80f Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Mon, 24 Oct 2016 21:33:54 +0200 Subject: [PATCH 08/10] Rebase with merge --- forum/qa-content/qa-ask.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/forum/qa-content/qa-ask.js b/forum/qa-content/qa-ask.js index a93abd5b..bb529531 100644 --- a/forum/qa-content/qa-ask.js +++ b/forum/qa-content/qa-ask.js @@ -304,9 +304,9 @@ function set_category_description(idprefix) 'use strict'; - // wait for DOM to load - window.addEventListener( 'DOMContentLoaded', function() { - + // wait for DOM to load + window.addEventListener('DOMContentLoaded', function() + { // get DOM elements: "tags" input and button "Zadaj pytanie" var tags = document.getElementById( 'tags' ); var askQuestionBtn = document.querySelector( 'input[value="Zadaj pytanie"]' ); From 45f10ae827401436543d04188c49ce1f4b4ef3b7 Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Mon, 24 Oct 2016 21:36:48 +0200 Subject: [PATCH 09/10] Format --- forum/qa-content/qa-ask.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/forum/qa-content/qa-ask.js b/forum/qa-content/qa-ask.js index bb529531..9af344bc 100644 --- a/forum/qa-content/qa-ask.js +++ b/forum/qa-content/qa-ask.js @@ -300,13 +300,12 @@ function set_category_description(idprefix) /** * Feature - Remove unnecessary # from tags, when creating new post (question) */ -( function(document) { +( function( document ) { 'use strict'; // wait for DOM to load - window.addEventListener('DOMContentLoaded', function() - { + window.addEventListener('DOMContentLoaded', function() { // get DOM elements: "tags" input and button "Zadaj pytanie" var tags = document.getElementById( 'tags' ); var askQuestionBtn = document.querySelector( 'input[value="Zadaj pytanie"]' ); From 985cca26f09b5ae7ab066b895e3cb77a33f3684e Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Mon, 24 Oct 2016 21:43:08 +0200 Subject: [PATCH 10/10] ...... --- forum/qa-content/qa-ask.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/forum/qa-content/qa-ask.js b/forum/qa-content/qa-ask.js index 9af344bc..8fedd420 100644 --- a/forum/qa-content/qa-ask.js +++ b/forum/qa-content/qa-ask.js @@ -300,12 +300,13 @@ function set_category_description(idprefix) /** * Feature - Remove unnecessary # from tags, when creating new post (question) */ -( function( document ) { +;( function( document ) { 'use strict'; // wait for DOM to load window.addEventListener('DOMContentLoaded', function() { + // get DOM elements: "tags" input and button "Zadaj pytanie" var tags = document.getElementById( 'tags' ); var askQuestionBtn = document.querySelector( 'input[value="Zadaj pytanie"]' );