Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Monday, November 4, 2013

Published 1:18 AM by with 0 comment

google translator


Language is the human capacity for acquiring and using complex systems of communication, and a language is any specific example of such a system. The scientific study of language is called linguistics. Estimates of the number of languages in the world vary between 6,000 and 7,000. However, any precise estimate depends on a partly arbitrary distinction between languages and dialects. Natural languages are spoken or signed, but any language can be encoded into secondary media using auditory, visual, or tactile stimuli, for example, in graphic writing, braille, or whistling. This is because human language is modality-independent. When used as a general concept, "language" may refer to the cognitive ability to learn and use systems of complex communication, or to describe the set of rules that makes up these systems, or the set of utterances that can be produced from those rules. All languages rely on the process of semiosis to relate signs with particular meanings. Oral and sign languages contain a phonological system that governs how symbols are used to form sequences known as words or morphemes, and a syntactic system that governs how words and morphemes are combined to form phrases and utterances.
Read More
    email this       edit

Friday, December 28, 2012

Published 8:37 AM by with 0 comment

JavaScript Try Catch

Try Catch (Exception)

try
{
}
 catch(err)
{
}
 finally
{
} 
QRCode









Try Catch (Exception)



Javascript Error Handling
Try Catch

Example

try
{
    //lines of codes
}
catch(err)
{
    //err.description
    //err.message
    //err.name
    //err.number
    //err.stack
}
finally
{
    //success or failure , code executes here
}

Throw


Example

function ThrowHelper()
{
    var err = new Error(123,"Error in helper");
    throw err;
}

//elsewhere in code
try
{
    ThrowHelper();
}
catch(ex)
{
    var msg = ex.number +" :"+ex.message;
    //log msg
}

-
Read More
    email this       edit
Published 7:02 AM by with 1 comment

JavaScript Array Functions

Javascript Array Functions (Array)


var fruit = ["apple","orange","banana"];
log(fruit.sort());//apple,banana,orange
fruit.push("pear");
log(fruit.sort());//apple,banana,orange,pear

var vegitables = ["carrot","broccoli","cauliflovd"];
var all = fruit.concat(vegitables);
log(all);//apple,orange,banana,carrot,broccoli,cauliflovd
 
QRCode

Javascript Array Functions (Array)


Javascript Array functions
push,pop,concat,map,filter,some,every,forEach,reduce,sort,splice,slice,join,reverse
Array is a Stack data sructure (first in first out)

Example

var fruit = ["apple","orange","banana"];
log(fruit.sort());//apple,banana,orange

fruit.push("pear");
log(fruit.sort());//apple,banana,orange,pear

var vegitables = ["carrot","broccoli","cauliflovd"];
var all = fruit.concat(vegitables);
log(all);//apple,orange,banana,carrot,broccoli,cauliflovd

var firt = fruit.slice(0,1);
log(first);//apple

var result = fruit.splice(1,2,"melon","grape");
log(result);//start in 1 no of 2 remove and add "melon","grape"
//out put is orange,banana
//splice is immutable function in javascript

fruit.splice(1,2,"melon","grape");
log(fruit);
//apple,melon,grape

fruit = fruit.map(function(i){return i.toUpperCase()});
log(fruit);
//APPLE,MELON,GRAPE

fruit = fruit.map(function(i){return {fruitname:i}});
log(fruit);
//[object Object],[object Object],[object Object]

fruit = fruit.filter(function(){
    return i[0]==="a";
});
log(fruit);
//apple

fruit = fruit.every(function(){
    return i[0]==="a";
});
log(fruit);
//false //if every items start with "a"


fruit = fruit.every(function(){
    return i.length>0;
});
log(fruit);
//true //if every items has more than 0 length

fruit = fruit.some(function(){
    return i.length>0;
});
log(fruit);
//true //if some items has more than 0 length

fruit.forEach(function(){
    log(i);
});
Read More
    email this       edit
Published 4:46 AM by with 0 comment

Javascript Function

Javascript Function

Javascript function definitions,
There are few different methods to define a function in javascript

Example
function Samsple1()
{
 log('Hello Aruna');
}...
 
QRCode




Javascript Function

 
Javascript function definitions
There are few different methods to define a function in javascript

Example

function Samsple1()
{
    log('Hello Aruna');
}


Example

var fun = function Samsple2()
{
    log('Hello Aruna');
};


Example

var ops = {
    Add:function AddNumbers(n1,n2)
    {
        return n1+n2;
    }
};

var x = ops.Add(3,5); //x =8
var y = ops.AddNumbers(3,5); //
not valid

Encapsulation-in-JavaScript

 

Example

var x = 2000;
var fun = function Encas()
{
    var y = 12;
    return y;
};

var total = x+y; //
Invalid use of y

var total = x+Encas()//total is 2012

Functions in Functions


Example

function OuterFunction(n)
{
    function InnerFunction()
    {
        return n*n;
    }
    return InnerFunction();
}
var x = OuterFunction(10);// x = 100
//InnerFunction can not call direcly

Immediate Functions


Example

(
function() {...}()
)
;

or

(
function() {...}
)
();

Module Pattern

  Extended immediate function

Example

var fun = (function(){
    var m=2000,c=0,d=10,y=2;
    return {
        GetHiddenYear:function()
        {
            return m+c+d+y;
        }
    }
}());

var x = fun.GetHiddenYear(); //x==2012;

Passing function as a parameter


Example

function Add(n1,n2)
{
    return n1+n2;
}

function calc(n1,n2,processForCalc)
{
    return processForCalc(n1,n2);
}

function executeMath()
{
    log(calc(4,4,Add));//output 8
}


 
Read More
    email this       edit
Published 12:22 AM by with 0 comment

HTML5 Web Storage

HTML5 Web Storage

HTML5 web storage, a better local storage than cookies.

What is HTML5 Web Storage?

With HTML5, web pages can store data locally within the user's browser.
Earlier, this was done with cookies. However, Web Storage is more secure and faster. The data is not included with every server request, but used ONLY when asked for. It is also possible to store large amounts of data, without affecting the website's performance.
The data is stored in key/value pairs, and a web page can only access data stored by itself.

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari
Web storage is supported in Internet Explorer 8+, Firefox, Opera, Chrome, and Safari.
Note: Internet Explorer 7 and earlier versions, do not support web storage.

localStorage and sessionStorage 

There are two new objects for storing data on the client:
  • localStorage - stores data with no expiration date
  • sessionStorage - stores data for one session
Before using web storage, check browser support for localStorage and sessionStorage:
if(typeof(Storage)!=="undefined")
  {
  // Yes! localStorage and sessionStorage support!
  // Some code.....
  }
else
  {
  // Sorry! No web storage support..
  }


The local Storage Object

The local Storage object stores the data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year.

Example

localStorage.lastname="Smith";
document.getElementById("result").innerHTML="Last name: "
+ localStorage.lastname;

Try it yourself »
Example explained:
  • Create a localStorage key/value pair with key="lastname" and value="Smith"
  • Retrieve the value of the "lastname" key and insert it into the element with id="result"
Tip: Key/value pairs are always stored as strings. Remember to convert them to another format when needed.
The following example counts the number of times a user has clicked a button. In this code the value string is converted to a number to be able to increase the counter:

Example

if (localStorage.clickcount)
  {
  localStorage.clickcount=Number(localStorage.clickcount)+1;
  }
else
  {
  localStorage.clickcount=1;
  }
document.getElementById("result").innerHTML="You have clicked the button " + localStorage.clickcount + " time(s).";

Try it yourself »


The sessionStorage Object

The sessionStorage object is equal to the localStorage object, except that it stores the data for only one session. The data is deleted when the user closes the browser window.
The following example counts the number of times a user has clicked a button, in the current session:

Example

if (sessionStorage.clickcount)
  {
  sessionStorage.clickcount=Number(sessionStorage.clickcount)+1;
  }
else
  {
  sessionStorage.clickcount=1;
  }
document.getElementById("result").innerHTML="You have clicked the button " + sessionStorage.clickcount + " time(s) in this session.";

Try it yourself » Refferenced from W3school »




Read More
    email this       edit

Wednesday, December 26, 2012

Published 10:14 PM by with 0 comment

HTML5 Server-Sent Events

What is the Web workers
 
A server-sent event is when a web page automatically gets updates from a server.
This was also possible before, but the web page would have to ask if any updates were available. With server-sent events, the updates come automatically.
Examples: Facebook/Twitter updates, stock price updates, news feeds, sport results, etc.


Internet ExplorerFirefoxOperaSafariGoogle Chrome ΙΕ not Support.
var source=new EventSource("sample.php");
source.onmessage=function(event)
  {
  document.getElementById("result").innerHTML+=event.data + "
"; };
Read More
    email this       edit
Published 9:38 PM by with 0 comment

HTML5 Web Workers

What is the Web workers
  A web worker is a JavaScript that runs in the background, independently of other scripts, without affecting the performance of the page. You can continue to do whatever you want: clicking, selecting things, etc., while the web worker runs in the background.


Internet ExplorerFirefoxOperaSafariGoogle Chrome ΙΕ not Support.

<button onclick="startWorker()">Start Worker</button>
<button onclick="stopWorker()">Stop Worker</button>


<script>
var w;

function startWorker()
{
if(typeof(Worker)!=="undefined")
  {
  if(typeof(w)=="undefined")
  {
  w=new Worker("demo_workers.js");
  }
  w.onmessage = function (event) {
    document.getElementById("result").innerHTML=event.data;
    };
  }
else
  {
  document.getElementById("result").innerHTML="Sorry, your browser does not support Web Workers...";
  }
}

function stopWorker()
{
w.terminate();
}
</script>
Read More
    email this       edit

Thursday, December 20, 2012

Published 8:28 PM by with 0 comment

JQuery Message Box


This message box is designed for asp.net pages using JQuery


collect all files in one folder and test the sample page

Message box with animation

//#--Scrolling with Animation-----------------
//$("#ContentDivMessage").animate( { left:left1}, 500 )
//.animate( { top:top1 }, 500);
//#-------------------------------------------
Message box with out animation

//#--With out Animation-----------------------
document.getElementById('ContentDivMessage').style.left = left1;
document.getElementById('ContentDivMessage').style.top = top1;
//#-------------------------------------------
Read More
    email this       edit

Monday, December 17, 2012

Published 4:36 AM by with 1 comment

Random Images - Photo Album



DOWNLOAD SOURCE
.pic {
    -moz-border-bottom-colors: none;
    -moz-border-left-colors: none;
    -moz-border-right-colors: none;
    -moz-border-top-colors: none;
    border-color: #EEEEEE;
    border-image: none;
    border-style: solid;
    border-width: 5px 5px 18px;
    box-shadow: 2px 2px 3px #333333;
    position: absolute;
   background-color: #EEEEEE;
}
#imagecontainer{
    width:100%;
    height:400px;
}
</style>
<script>
    function randomFromInterval(from,to)
    {
        return Math.floor(Math.random()*(to-from+1)+from);
    }
function jsonFlickrApi(rsp) {
      var s = "";
      // http://farm{id}.static.flickr.com/{server-id}/{id}_{secret}_[mstb].jpg
      // http://www.flickr.com/photos/{user-id}/{photo-id}
      //s = "total number is: " + rsp.photos.photo.length + "<br/>";

      for (var i=0; i < rsp.photos.photo.length; i++) {
        //var rand = randomFromInterval(1,10);
        var stage_width=800;
        var stage_height=400;
        var left = randomFromInterval(0,stage_width);
 var top = randomFromInterval(0,400);
 var rot = randomFromInterval(-40,40);
 
  if(top>(stage_height-130) && left > (stage_width-230))
  {
   top-=120+130;
   left-=230;
  }
       
        photo = rsp.photos.photo[i];
      var _url = "http://farm" + photo.farm + ".static.flickr.com/" + photo.server + "/" + photo.id + "_" + photo.secret + "_" + "m.jpg";
        p_url = "http://www.flickr.com/photos/" + photo.owner + "/" + photo.id;
        s +=  '<div class="pic" style="top:'+top+'px;left:'+left+'px; -moz-transform:rotate('+rot+'deg); -webkit-transform:rotate('+rot+'deg);">'+
'<img src="' + _url + '"/></div>';
      }
      $('#imagecontainer').append(s);
  }
$(document).ready(function() {

 });

</script>

<div id="imagecontainer">
</div>


<script src="http://api.flickr.com/services/rest/?method=flickr.photos.search&amp;api_key=f3c5222d18401ab6991a5532da0208b1&amp;tags=nature&amp;per_page=50&amp;format=json"></script>

Read More
    email this       edit