Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Tuesday, October 16, 2018

Javascript JSON to string

Javascript JSON to string


Into this post we are going to discuss how to convert Javascript JSON ( Javascript Object Notation ) to string or javascript json to string.

Into this kind real IT world we can say Javascript is everywhere like front end and BackEnd both so we can say Javascript is going to rule everywhere.

Javascript JSON to String by visionfortech , Javascript blog

So in today's article we are going to discuss JSON which generally uses to pass data from one end to another end.

Let start understanding of that using below simple examples.

So into Javascript we can do that easily using JSON.stringify().

First let's take and example of Object

let json_to_string = JSON.stringify({ javascript_json: 5, json_to_string: 6 })

console.log(json_to_string);

//output: "{"javascript_json":5,"json_to_string":6}"
Now let's take an example of run time creation of Array of Object

let json_to_string = JSON.stringify([new String('visiofortech'),new Boolean(false),new Number(7)])

console.log(json_to_string);

//output: "["visiofortech",false,7}"
Now let's take an example of Date object

let json_to_string = JSON.stringify(new Date(2018, 10, 16, 15, 4, 5))

console.log(json_to_string);

//output: ""2018-11-16T09:34:05.000Z""

Hope you enjoyed the article and it got added something new to your knowledge.
To add something new every-time into your mind stay tuned to visionfortech.

To Learn more about Javascript Javascript Treasure.

Please comment below if you have something doubts or some questions.

Enjoy...!!!
Happy Learning....!!!

Thursday, September 13, 2018

Javascript Global and Local Variables

Javascript Global and Local Variables


Into this post we are going to discuss difference between how to declare javascript global variable and javascript local variable and its scope

we are going to discuss how can we declare global variable and local varible into Javascript with example.

Javascript global variable vs local variable by visionfortech
Javascript global variable vs local variable by visionfortech


Javascript Global Variable:

If we define var and let variable same globally then let variable will not get added into global window object while var variable will get added to global window object.

So let's declare two variables at the time of window loaded
let Visionfortech_global = "Visionfortech is defined as Global variable"

var Visionfortech_local = "Visionfortech is defined as Local variable"

console.log(Visionfortech_global);
o/p : undefined

console.log(Visionfortech_local);
o/p : Visionfortech is defined as Local variable
  

Javascript Local Variable : 
let js_local_variable = 1;

if (js_local_variable === 1) {
  let js_local_variable = 2;

  console.log(js_local_variable);
  // output: 2
}

console.log(js_local_variable);
// output: 1
  

Now let see the scope example of Javascript global and Local variable.

var global_variable = 1;
var javascript_global_variable = 2;
if (a === 1) {
var global_variable = 11; // the scope is global
let javascript_global_variable = 22; // the scope is inside the if-block
console.log(global_variable); // 11
console.log(javascript_global_variable); // 22
}
console.log(global_variable); // 11
console.log(javascript_global_variable); // 2

Enjoy....!!!!

Feel free to comment below your experience with above approach and If you still find any problem  with above steps Let me know I would love to help you to resolve your  problem.

 If you want to take your Technological Knowledge to the Next Level and For More Technological information Stay tuned to Visionfortech

Friday, August 10, 2018

Javascript let vs var


Javascript Let vs Var


Into this post we are going to discuss difference between Javascript var and Let.

we are going to discuss about Javascipt variable declaration method like where user can declare variable with var and where user can declare variable with let.



Global Variable Declaration:

If we define var and let variable same globally then let variable will not get added into global window object while var variable will get added to global window object.

So let's declare two variables at the time of window loaded
let Visionfortech_let = "Visionfortech is defined as let variable"

var Visionfortech_var = "Visionfortech is defined as var variable"

console.log(Visionfortech_let);
o/p : undefined

console.log(Visionfortech_var);
o/p : Visionfortech is defined as var variable
  

Redeclare Variable:


So Here let's discuss about one more example of let vs var into Javascript.You can not declare let variable but you can redeclare var variable


'use strict';
var let_vs_var = "Javascript let vs var";
var let_vs_var = "Difference Between let and var Javascript"; //replaced easily
'use strict';
let let_vs_var = "Javascript let vs var";
let let_vs_var = "Difference Between let and var Javascript"; // Error: let_vs_var is already declared

Javascript Let Example : 
let vision = 1;

if (vision === 1) {
  let vision = 2;

  console.log(vision);
  // output: 2
}

console.log(vision);
// output: 1
  

Now let see the scope example of Javascript let vs var.

var let_vs_var = 1;
var javascript_var = 2;
if (a === 1) {
var let_vs_var = 11; // the scope is global
let javascript_var = 22; // the scope is inside the if-block
console.log(let_vs_var); // 11
console.log(javascript_var); // 22
}
console.log(let_vs_var); // 11
console.log(javascript_var); // 2

Enjoy....!!!!

Feel free to comment below your experience with above approach and If you still find any problem  with above steps Let me know I would love to help you to resolve your  problem.

 If you want to take your Technological Knowledge to the Next Level and For More Technological information Stay tuned to Visionfortech

Tuesday, July 25, 2017

[Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive

[Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive


In this post i am going to discuss about how to remove a jQuery violation "[Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive" from chrome console.

Basically user can remove all the basic violations from just changing the type of log from "Verbose" to "Info".

visionfortech,javascript,Pratik Soni













But what if  user want to remove above violation from "Verbose" log Type ?
So Here is the solution.

Problem : 









The above violation is occur because e.preventDefault() will take much time and it will not passively load the component or we can say DOM.

So to remove that please include below code on top of your javascript.

Solution :

{passive:true}

// To remove the violation jquery-1.11.1.min.js:3 [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive.

jQuery.event.special.touchstart = {
setup: function( _, ns, handle ){
if ( ns.includes("noPreventDefault") ) {
 this.addEventListener("touchstart", handle, { passive: false });
} else {
this.addEventListener("touchstart", handle, { passive: true });
}
}
};

//Remove violation code End

So now run your application and above violation will not appear into console.

Cheers...!!!Enjoy...!!!

Feel free to comment below your experience with above approach and If you still find any problem with above steps Let me know I would love to help you to resolve your  problem.

I hope this article will provided you solution which you are expecting. If you want to know more about Javascript check out Javascript World

If you want to take your Technological Knowledge to the Next Level and For More Technological information Stay tuned to Visionfortech

Tuesday, June 13, 2017

Bootstrap search drop down list or list with [X] sign to delete element

Bootstrap search drop down list or list with [X] sign to delete element

This post is all about a bootstrap drop down list or we can say list with search facility and delete functionality as well.

In this post we are going to discuss about a component through which user can show the drop down list with search option facility and user also can delete the option by just clicking [X] sign besides every option.So let's see how we can achieve that.

Bootstrap search drop down list or list with [X] sign to delete element,visionfortech,visionfortech latest blog,visionfortech latest post


You can see the live demo at live Demo
Jsfiddle URL : JSfiddle URL


The HTML file : 

<div class="dropdown" id="option_dropdown" style="margin-left:20px;margin-top:20px">
<button class="btn btn-default btn-filter" type="button" id="savedSearch"
data-toggle="dropdown" data-submenu="" aria-expanded="true" style="word-wrap: break-word;">
<span id="filter_name">Select Language</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu" id="saveLanguageUl"  style="max-height: 315px;overflow-y: scroll;"></ul>
</div>

JavaScript code :

var pra="";
$(document).ready(function(){
$("#saveLanguageUl").empty();
   $("#saveLanguageUl").append('<li><input type="text" id="searchFilterInput" placeholder="Search for Language.." title="Type in to searcg language option">');
   var language = ["angular.js","backbone.js","d3.js","amcharts.js","jquery.js","bootstrap.js","bootstrap.css","mabbox.js","python","php","ajax","json"];
 
    for(var i = 0; i < language.length; i++) {
 $("#saveLanguageUl").append('<li style="height:35px" class=""><a href="#" id='+language[i]+' name='+language[i]+'>'+language[i]  +'   <span style="float:right;" class="deleteOptionBtn glyphicon glyphicon-remove-sign" title="Delete '+language[i]+' Filter" id='+language[i]+'><br></span></a></li>');
}
       
          $("#searchFilterInput").keyup(function(){
    var input, filter, ul, li, a, i;
    input = document.getElementById("searchFilterInput");
    filter = input.value.toUpperCase();
    ul = document.getElementById("saveLanguageUl");
    li = ul.getElementsByTagName("li");
    for (i = 1; i < li.length; i++) {
                  a = li[i].getElementsByTagName("a")[0];
                  if(a.name.toUpperCase().includes(filter)){
                      li[i].style.display = "";
                  } else {
                      li[i].style.display = "none";

                  }
              }
          })
$('#saveLanguageUl').on('click', 'a', function(event) {
var filterId = $(this).attr('id');
if(pra == ""){
$("#filter_name").text(filterId);
}
else{
pra = "";
}
$("#searchFilterInput").val("");
});

$('#saveLanguageUl').on('click', 'span.deleteOptionBtn', function(event) {

var filterId = $(this).attr('id');
pra = filterId;
$(this).closest("li").remove();
$("#filter_name").text($(this).attr('Select Saved Filter'));
});
});


CSS Code:

#searchFilterInput {
  background-position: 10px 12px;
  background-repeat: no-repeat;
  width: 100%;
  font-size: 16px;
  padding: 12px 20px 12px 15px;
  border: 1px solid #ddd;
  margin-bottom: 12px;
}

You can see the live demo at live Demo
Jsfiddle URL : JSfiddle URL

Enjoy...!!!

Feel free to comment below your experience with above approach and If you still find any problem with above steps Let me know I would love to help you to resolve your  problem.

If you want to take your Technological Knowledge to the Next Level and For More Technological information Stay tuned to Visionfortech

Wednesday, May 10, 2017

Create E commerce website for free in 5 minutes | (with images)

Create E commerce website for free in 5 minutes | (with images)


Into this post i am going to discuss some points which are:
How to create  E commerce website in 5 minutes.
How user can create a E commerce website in which he/she can do whatever he/she want.
How easy to create a website in few minutes.

By using opencart you can create your create your own website and most important thing that it is open-source.

visionfortech,best technical blog


So by following below steps you can create a E Commerce website in few minutes.
1) Install any server(apache,tomcat) and Mysql database.
     You can install both of this by just installing one software which is XAMPP.
     You can download XAMPP from Here.

2) Download the opencart from Here.or you can download that from opencart website as well.

Visionfortech,Latest technological blog,Create E commerce website in few minutes


3) Put that downloaded files into the root directory of your server here i user XAMPP so iam going to put all the files into htdocs directory which is root directory for apache in xampp.

4) Rename config-dist.php to config.php and admin/config-dist.php to admin/config.php.

5) Open xampp control pannel and start the apache as well as mysql server.

Visionfortech,Latest technological blog,Create E commerce website in few minutes


6) Then open you browser and type http://localhost:opencart and you can see the below screen

Visionfortech,Latest technological blog,Create E commerce website in few minutes


7) Press Continue.



8) Press Continue.

Visionfortech,Latest technological blog,Create E commerce website in few minutes
Enter username and password for your admin pannel using which you can manage your shopping website and do everything what you want.

9) After that delete the install folder from your root directory of server.

Visionfortech,Latest technological blog,Create E commerce website in few minutes

Enjoy....!!!!

Feel free to comment below your experience with above approach and If you still find any problem  with above steps Let me know I would love to help you to resolve your  problem.

 If you want to take your Technological Knowledge to the Next Level and For More Technological information Stay tuned to Visionfortech

Monday, January 9, 2017

[Solution] Draw Flowchart with drag and drop facility using HTML and JavaScript(Flowchart Builder)

Draw Flowchart with drag and drop facility using HTML and JavaScript(Flowchart Builder)


         In this post we are going to provide a solution how a developer can embed his/her own flowchart builder into their application.

         This post contains the source code for that.You can download that code from Download code from GitHub

         At some point of time all developers want to Embed flowchart builder into their application.But they may not know how can they do that so here is the solution how they can embed flowchart into their own application.By using this code End user can draw their own flowchart with just simple drag and drop and simply connect those nodes to make it better understandable.

          Every Developer,programmer or student  knows what the flowchart is so we are not going to discuss here what flowchart is.

          So for Brief Flowchart is a diagram which shows user that what is the flow of the program or an application 

So for that you just need to write a small HTML code for that and below is the code.

HTML File

You just need to include the flowchart.js library into your HTML application and you can download that from flowhchart.js

<script type='text/javascript' src="js/flowchart.js">

Output : 

Latest Technological Blog,draw flowchart using html and javascript with drag and drop






















You can also get your drawn chart data into json format.

Get chart into JSON Format : 

console.log(myDiagram.model.toJson());

Enjoy....!!!!

Feel free to comment below your experience with above approach and If you still find any problem  with above steps Let me know I would love to help you to resolve your  problem.

I hope this article will help to understand the Javascript Concept. If you want to know more about Javascript check out Javascript World

 If you want to take your Technological Knowledge to the Next Level and For More Technological information Stay tuned to Visionfortech

Tuesday, December 20, 2016

[Solution] Embed Map(openstreetmap) of Leaflet.js into HTML

[Solution] Embed Map(openstreetmap) of Leaflet.js into HTML

This post contains how can we use leafleat.js javascript to embed openstreetmap into HTML file and how to create markercluster(group of marker).

In this post we will discuss.

1) What is leaflet.js
2) What is open street map and how we can embed openstreetmap into HTML file 
3) What is MarkerCluster and what is fitbound of leaflet.js ?
4) Code to Embed openstreetmap into HTML(you can download the code).

visionfortech,include_openstreetmap_into_htrml,openstreetmap,Latest Technologocal Blog

So let's start.

You can download the code of this small project from https://github.com/visionfortech/embed-openstreetmap-in-html

What is leaflet.js ?

Leaflet.js is the trending open-source javascript library for mobile as well as tablet as well as web interactive maps.Its file size is just of 33 KB and most importantly it  has mapping features what we developers always needs.

What is open street map and how we can embed openstreetmap into HTML file  ?

OpenStreetMap is a collaborative project to create a free editable map of the world. The creation and growth of OSM has been motivated by restrictions on use or availability of map information across much of the world, and the advent of inexpensive portable satellite navigation devices. OSM is considered a prominent example of volunteered geographic information.

Created by Steve Coast in the UK in 2004, it was inspired by the success of Wikipedia and the predominance of proprietary map data in the UK and elsewhere.Since then, it has grown to over 2 million registered users, who can collect data using manual survey, GPS devices, aerial photography, and other free sources. These crowdsourced data are then made available under the Open Database Licence. The site is supported by the OpenStreetMap Foundation, a non-profit organisation registered in England and Wales.

For Embeding map into HTML

You need to import below JavaScript file into your HTML file.

<script type='text/javascript' src="js/leaflet-src.js">

What is leaflet.js ?

Leaflet.js is the trending open-source javascript library for mobile as well as tablet as well as web interactive maps.Its file size is just of 33 KB and most importantly it  has mapping features what we developers always needs.

Embed into HTML

1) At first you need to include leaflet.js library into your HTML page.

<script type='text/javascript' src="js/leaflet-src.js">
2) Then you need add below thing into your JavaScript.

var mymap = L.map('mapid').setView([10.1, 20.2], 13);

 L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
     attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
 }).addTo(mymap);

 var myIcon = L.icon({
    iconUrl:'images/map-marker-pratik.png',
    iconRetinaUrl:'map-marker-pratik.png',
    iconSize: [25, 40]
  });2) Then you need add below thing into your JavaScript.


3) Then add marker on your Map by doing below

L.marker([51.5, -0.09]).addTo(map)
    .bindPopup('Visionfortech.')
    .openPopup();3) Then add marker on your Map by doing below

What is MarkerCluster and what is fitbound of leaflet.js ?

Suppose you have multiple market at same position then what you can do ?

         At that time you need MarkerCluster Library of leaflet.js which can group the marker into once and it will show you the group(or we can say total count of marker at that particular position).

<link rel="stylesheet" type="text/css" href="css/MarkerCluster.css" /> <!-- Use to group Marker -->
<link rel="stylesheet" type="text/css" href="css/MarkerCluster.Default.css" /><!-- Use to group Marker -->
<script type='text/javascript' src='js/leaflet.markercluster.js'></script><!-- Use to group Marker -->
<script src="js/leaflet.markercluster-src.js"></script>

To use markerCluster you have to include above libraries into your HTML File.
After that you have to include below into your JavaScript

var marker_cluster = L.markerClusterGroup();
 
for(var i = 0; i < latitude.length; i++)
{
     var marker =  L.marker([latitude[i], longitude[i]],{icon: myIcon});
     marker.bindPopup("Latitude = "+latitude[i]+"<br>"+"Longitude = "+longitude[i]+"<br>"+"Provider = "+provider[i]);
     marker_cluster.addLayer( marker );//will add each marker into markerCluster
}
mymap.addLayer( marker_cluster );

What is FitBound ?

Suppose you have thousands of marker and you want to display each and every marker on screen when page gets loaded.

mymap.fitBounds(marker_cluster.getBounds())

you can do that by adding a single line into your JavaScript Function.
visionfortech,markerClustergroup,openstreetmap,leaflet.js,latest technological blog

You can download whole code from  https://github.com/visionfortech/embed-openstreetmap-in-html

Enjoy....!!!!

Feel free to comment below your experience with above approach and If you still find any problem  with above steps Let me know I would love to help you to resolve your  problem.

 If you want to take your Technological Knowledge to the Next Level and For More Technological information Stay tuned to Visionfortech


Wednesday, September 7, 2016

What you can not do with javascript that you can do with NodeJs

What you can not do with javascript that you can do with NodeJs

Here we are going to discuss about what javascript can not do which nodejs can do.

visionfortech,pratik soni blog,javascript,nodejs,pratik soni nodejs blog,latest technical blog


All browsers have JavaScript engines that run the JavaScript of web pages. Firefox has an engine called Spidermonkey, Safari has JavaScriptCore, and Chrome has an engine called V8.

Node.js is simply the V8 engine bundled with some libraries to do I/O and networking, so that you can use JavaScript outside of the browser, to create shell scripts, backend services or run on hardware

JavaScript is an implementation of ECMAScript, a standard defining the programming language.

Browsers have a built-in interpreter for JavaScript, along with a bunch of libraries and a run-time environment for working with web pages.

Nodejs is an interpreter and environment for javascript which includes a bunch of libraries for using javascript as a general-purpose programming language, with an emphasis on asynchronicity and non-blocking operations. Node actually runs the same interpreter as Google Chrome (V8), but provides a different set of libraries and a different run-time environment. It also includes a package management system (NPM) and a few language extensions you won't find standard in browsers (for example modules).

The JS interpreter in Google Chrome and the JS interpreter in Nodejs are essentially the same. The difference is, in a browser your end goal is to modify stuff in a web page (text, graphics, stylesheets, etc), in Nodejs it's to run general purpose code that might do anything from running a web server to manipulating files.

JavaScript is a language that runs inside web browsers as part of documents loaded by the browser. It gives behaviour to your pages (HTML gives semantic structure, CSS gives form or look and feel). However nothing ought to restrict JavaScript to run solely inside the browser. Now being an interpreted language, it needs an interpreter to run. V8 is the Google Chrome JS engine and 'node' is a front-end to it that can be used to run JavaScript scripts outside the browser. Node.js or just Node usually refers to a collection of objects and methods available to your JavaScript code when run in V8 or through the node interpreter. It is a JavaScript libray cum runtime.

Javascript is normally used in client side scripting to validate forms, send ajax requests and manipulate html pages. Nodejs allows you to run javascript on server, which makes sense as you are already using it in front end and same code can be reused at server side for any reusable functionality. Also it reduces the need to have two different languages in client and server side of any web application.

Node.js let’s you run JavaScript from your computer’s terminal/command prompt. It allows you to install and use modules, other JavaScript programs, to do things with JavaScript that we wouldn’t be able to do. Some examples are:


  1. Manipulate files using the file system module
  2. Transpile TypeScript or CoffeeScript into JavaScript
  3. Write desktop applications using Github’s Electron framework
  4. Write web applications (from the backend to UI) entirely in JavaScript


There are a lot of other uses. Node.js takes JavaScript from a language that only browsers can use to a programming language for building apps or just running programs from your computer’s terminal/command prompt.

If you know Java then Java is to JRE is to JVM what JavaScript is to Node is to V8.

Feel free to comment below your experience with above approach and If you still find any problem  with above steps Let me know I would love to help you to resolve your  problem.

 If you want to take your Technological Knowledge to the Next Level and For More Technological information Stay tuned to  Visionfortech
Protected by Copyscape