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

Friday, July 3, 2015

Digital Watch Creation Through Javascript

Understand Regular Expression

CharacterDescription
\wMatches any word character (alphanumeric).
\WMatches any non-word character.
\sMatches any whitespace character (tab, newline, carriage return, form feed, vertical tab).
\SMatches any non-whitespace character.
\dMatches any numerical digit.
\DMatches any character that is not a number.
[\b]Matches a backspace.
.Matches any character except a newline.
[...]Matches any one character within the brackets.
[^...]Matches any one character not within the brackets.
[x-y]Matches any character in the range of x to y.
[^x-y]Matches any character not in the range of x to y.
{x,y}Matches the previous item at least x times but not to exceed y times.
{x,}Matches the previous item at least x times.
{x}Matches the previous item exactly x times.
?Matches the previous item once or not at all.
+Matches the previous item at least once.
*Matches the previous item any number of times or not at all.
|Matches the expression to the left or the right of the | character.
(...)Group everything inside parentheses into a subpattern.
\xMatches the same characters that resulted from the subpattern in group number x. Groups, which are designated with parentheses, are numbered from left to right.
^Matches the beginning of the string or beginning of a line, in multiline matches.
$Matches the end of the string or end of a line, in multiline matches.
\bMatches the position between a word character and a non-word character.
\BMatches the position that is not between a word character and a non-word character.
Know More in Regular Expression
CharacterDescription
\fForm feed
\nNewline
\rCarriage return
\tTab
\vVertical tab
\/Forward slash (/)
\\Backward slash (\)
\.Period (.)
\*Asterisk (*)
\+Plus (+)
\?Question Mark (?)
\|Horizontal bar (|)
\(Left parenthesis (
\)Right parenthesis )
\[Left bracket ([)
\]Right bracket (])
\{Left curly brace ({)
\}Right curly brace (})
\XXXASCII character represented by the octal number XXX
\xHHASCII character represented by the hexadecimal number HH
\cXThe control character represented by X

Window Object Functions: Learn Here

Methods/PropertiesDescription
alertLoads an alert dialog box with the text string passed.
backLoads the previous page in place of the window instance.
blurRemoves the focus from a window.
captureEventsSets the window to capture all events of a specified type.
clearIntervalClears the interval set with the setInterval method.
clearTimeoutClears the timeout set with the setTimeout method.
closeCloses the instance of the window.
confirmDisplays a confirmation dialog box.
disableExternalCaptureDisables external event capturing.
enableExternalCaptureEnables external event capturing for the pages loaded from other servers.
findDisplays a Find dialog box where the user can enter text to search the _current page.
focusAssigns the focus to the specified _window instance.
forwardLoads the next page in place of the window instance.
handleEventInvokes the handler for the event passed.
homeLoads the user's specified home page in place of the window instance.
moveByMoves the window by the amounts specified.
moveToMoves the window to the specified location.
openOpens a new instance of a window.
printInvokes the Print dialog box so the user can print the current window.
promptDisplays a prompt dialog box.
releaseEventsReleases the captured events of a specified type.
resizeByResizes the window by the specified amount.
resizeToResizes the window to the specified size.
routeEventPasses the events of a specified type to be handled natively.
scrollScrolls the document in the window to a specified location.
scrollByScrolls the document in the window by a specified amount.
scrollToScrolls the document, both width and height, in the window to a specified location.
setIntervalInvokes a function or evaluates an expression every time the number of milliseconds has passed.
setTimeoutInvokes a function or evaluates an expression when the number of milliseconds has passed.
stopStops the current window from loading other items within it.
closedSpecifies if the window instance has been closed.
defaultStatusIs the default message in the window's status bar.
documentReferences all the information about the document within this window. See the Document object for more information.
framesReferences all the information about the frames within this window. See the Frame object for more information.
historyReferences the URLs the user has _visited.
innerHeightContains the height of the display area of the current window in pixels.
innerWidthContains the width of the display area of the current window in pixels.
lengthRepresents the number of frames in the current window.
locationContains the current URL loaded into the window.
locationbarReference to the browser's location bar.
menubarReference to the browser's menu bar.
nameName of the window.
openerContains the name of the window from which a second window was opened.
outerHeightContains the height of the outer area of the current window in pixels.
outerWidthContains the width of the outer area of the current window in pixels.
pageXOffsetContains the x-coordinate of the current window.
pageYOffsetContains the y-coordinate of the current window.
parentReference to the upper most window that is displaying the current frame.
personalbarReference to the browser's personal bar.
scrollbarsReference to the browser's scroll bars.
selfReference for the current window.
statusReference to the message in the window's status bar.
statusbarReference to the browser's status bar.
toolbarReference to the browser's tool bar.
topReference to the upper most window that is displaying the current frame.
windowReference for the current window.

JavaScript String Functions: Learn Here

Method/PropertyDescription
anchor()Creates an instance of the tag with the NAME attribute set to the string passed to the method.
big()Converts the string into an instance of the tag.
blink()Converts the string into an instance of the tag.
bold()Converts the string into an instance of the tag.
charAt()Returns the character at the index passed to the method.
charCodeAt()Returns the ISO-Latin-1 number of the character at the index passed to the method.
concat()Concatenates the two strings passed to return a new string. This method was added in JavaScript 1.2.
fixed()Converts the string into an instance of the , fixed pitch font tag.
fontcolor()Sets the COLOR attribute of an instance of the tag.
fontsize()Sets the SIZE attribute of an instance of the tag.
fromCharCode()Returns the string value of the ISO-Latin-1 number passed to the method.
indexOf()Returns the index of the first occurrence of the string passed to the method within an instance of a String object.
italics()Converts the string into an instance of the tag.
lastIndexOf()Returns the index of the last occurrence of the string passed to the method within an instance of a String object.
link()Converts the string into an instance of the tag and sets the HREF attribute with the URL that is passed to the method.
match()Returns an array containing the matches found based on the regular expression passed to the method.
replace()Performs a search and replace, using the regular expression and replace string passed to the method, on the instance of a String that calls it.
search()Returns the index location of the match found in the string passed to the method. A -1 is returned if the string is not found.
slice()Returns the string between the beginning and ending index passed to the method. If a negative number is passed, the index is referenced from the end of the string passed.
small()Converts the string into an instance of the tag.
split()Returns the string split into segments defined by the string and instance limit passed to the method.
strike()Converts the string into an instance of the tag.
sub()Converts the string into an instance of the tag.
substr()Returns the string beginning with the indexed location and number of characters to return. If a negative number is passed, the index is referenced from the end of the string passed.
substring()Returns the string between the beginning and ending index passed to the method.
sup()Converts the string into an instance of the tag.
toLowerCase()Converts all the characters in the string to lowercase.
toSource()Returns the string representation of the String passed.
toString()Returns the characters passed as type string.
toUpperCase()Converts all the characters in the string to uppercase.
lengthReturns the length of the string.
prototypeProvides the ability for a programmer to add properties to instances of the String object.

Friday, December 26, 2014

Play With Cookies

<script type="text/javascript">
//----------------------------------------------------------
//      create cookie
//----------------------------------------------------------
function setCookie( name, value, expires, path, domain, secure ) {

var today = new Date();

    today.setTime( today.getTime() );
    if ( expires ) {
        expires = expires * 1000 * 60 * 60 * 24;
     }

     var expires_date = new Date( today.getTime() + (expires) );

     document.cookie = name+'='+escape( value ) +
                       ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) +
                       ( ( path ) ? ';path=' + path : '' ) +
                       ( ( domain ) ? ';domain=' + domain : '' ) +
                       ( ( secure ) ? ';secure' : '' );

}

//----------------------------------------------------------
//      check if cookie defined 
//----------------------------------------------------------
function getCookie(name) {

    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;

    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
       return null;
    }

    if ( start == -1 ) return null;
    var end = document.cookie.indexOf( ';', len );
    if ( end == -1 ) end = document.cookie.length;
    return unescape( document.cookie.substring( len, end ) );
}

//------------------------------------------------------------
//      Remove cookie
//------------------------------------------------------------
function removeCookie(  name, path, domain) {
    if ( getCookie( name ) )
{
        document.cookie = name + '=' + ( ( path ) ? ';path=' + path : '') + ( ( domain ) ? ';domain=' + domain : '' ) + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
}
//------------------------------------------------------------
//      Get the domain name
//------------------------------------------------------------
function getDomainname () {
    var hostname = window.location.hostname.split('.');
    if ( hostname.length >= 2 ) {
        var len = hostname.length;
        var domainname = '.' +  hostname[len - 2] + '.' + hostname[len - 1];
    } else {
        var domainname = '.' + window.location.hostname;
    }
    return domainname;
}
</script>

JavaScript Libraries

Prototype JS
====================
Prototype enhances JavaScript by providing classes and inheritance.
http://prototypejs.org/learn/
http://api.prototypejs.org/dom/dollar/

MooTools
=================
MooTools also includes some lightweight effects and animation functions.

Script.aculo.us
====================
Open-source JavaScript framework for visual effects and interface behaviors.

UIZE 
========================
Widgets, AJAX, DOM, templates, and more.

Ext Core
==============

jsPHP
==============
Pseudo-implementation of JavaScript for PHP 5
Following Attributes Available in Language

  1.     prototype inheritence, chaining and other object oriented features
  2.     JSBoolean, JSNumber, JSString, JSObject, JSArray, JSFunction, JSRegExp, JSDate, JSError and JSMath, as well as the global helper functions, such as parseInt or isNaN.

Tutorial
http://www.jsphp.org/tutorial
Download
https://github.com/SOLFENIX/jsphp
How to
http://www.dyn-web.com/javascript/
Important
http://www.dyn-web.com/sitemap.php

JSDoc
==========
Doc generators

JS Charts
==========
JS Charts is a JavaScript based chart generator that requires little or no coding
Just include our scripts, prepare your chart data in XML, JSON or JavaScript Array and your chart is ready!
http://www.jscharts.com/how-to-use
http://www.jscharts.com/

highlight.js
==================
Syntax highlighting for the Web
https://highlightjs.org/static/demo/
How to Use
https://highlightjs.org/usage/
Download
https://highlightjs.org/download/

Crayon Syntax Highlighter
===========================
For Wordpress
https://github.com/aramk/crayon-syntax-highlighter/blob/master/crayon_formatter.class.php
http://alexgorbatchev.com/SyntaxHighlighter/manual/installation.html

Source for Javascript Libraries
https://www.javascripting.com/

Javascript Tags Must Use

<!-- Redirect in case javascript is disabled on the page -->
<noscript>
   <meta http-equiv="refresh" content="0; url=http://www.espncricinfo.com/australia-v-india-2014-15/engine/current/match/754741.html?version=iframe" />
</noscript>

<!-- Redirect in case of browsers less than IE8 -->
<!--[if lt IE 8]>
   <meta http-equiv="refresh" content="0; url=http://www.espncricinfo.com/australia-v-india-2014-15/engine/current/match/754741.html?version=iframe" />
<![endif]-->


LightBox

HOW TO USE
====================
Step 1 - Load the Javascript and CSS

  1. Download and unzip the latest version of Lightbox.
  2. Look inside the js folder to find jquery-1.11.0.min.js and lightbox.min.js and load both of these files. Load jQuery first.
  3. <script src="js/jquery-1.11.0.min.js"></script>
  4. <script src="js/lightbox.min.js"></script>
  5. Look inside the css folder to find lightbox.css and load it.
  6. <link href="css/lightbox.css" rel="stylesheet" />
  7. Look inside the img folder to find close.png, loading.gif, prev.png, and next.png. These files are used in lightbox.css. By default, lightbox.css will look for these images in a folder called img.

Step 2 - Turn it on

  1. Add a data-lightbox attribute to any image link to activate Lightbox. For the value of the attribute, use a unique name for each image. For example:
  2. <a href="img/image-1.jpg" data-lightbox="image-1" data-title="My caption">Image #1</a>
  3. Optional: Add a data-title attribute if you want to show a caption.
  4. If you have a group of related images that you would like to combine into a set, use the same data-lightbox attribute value for all of the images. 
For example:
<a href="img/image-2.jpg" data-lightbox="roadtrip">Image #2</a>
<a href="img/image-3.jpg" data-lightbox="roadtrip">Image #3</a>
<a href="img/image-4.jpg" data-lightbox="roadtrip">Image #4</a>


Source:
http://lokeshdhakar.com/projects/lightbox2/

Retina JS

Retina graphics for your website. retina.js is an open source script that makes it easy to serve high-resolution images to devices with retina displays.

How it works
===============
When your users load a page, retina.js checks each image on the page to see if there is a high-resolution version of that image on your server. If a high-resolution variant exists, the script will swap in that image in-place.

The script assumes you use Apple's prescribed high-resolution modifier (@2x) to denote high-resolution image variants on your server.

For example, if you have an image on your page that looks like this:
<img src="/images/my_image.png" />

The script will check your server to see if an alternative image exists at this path:
"/images/my_image@2x.png"

How to use
===============
JavaScript
The JavaScript helper script automatically replaces images on your page with high-resolution variants (if they exist). To use it, download the script and include it at the bottom of your page.

  • Place the retina.js file on your server
  • Include the script on your page 

<script type="text/javascript" src="/scripts/retina.js"></script> 

(put it at the bottom of your template, before your closing </body> tag)
That's it!

LESS
============
The LESS CSS mixin is a helper for applying high-resolution background images in your stylesheet. You provide it with an image path and the dimensions of the original-resolution image. The mixin creates a media query specifically for Retina displays, changes the background image for the selector elements to use the high-resolution (@2x) variant and applies a background-size of the original image in order to maintain proper dimensions. To use it, download the mixin, import or include it in your LESS stylesheet, and apply it to elements of your choice.

Steps:
Syntax:
.at2x(@path, [optional] @width: auto, [optional] @height: auto);

Steps:

  • Add the .at2x() mixin from retina.less to your LESS stylesheet
  • In your stylesheet, call the .at2x() mixin anywhere instead of using background-image 

#logo {
  .at2x('/images/my_image.png', 200px, 100px);
} 

Will compile to: 

#logo {
  background-image: url('/images/my_image.png');
}
@media all and (-webkit-min-device-pixel-ratio: 1.5) {
  #logo {
    background-image: url('/images/my_image@2x.png');
    background-size: 200px 100px;
  }
}

Saturday, December 13, 2014

Jquery Learning

  1. Write less and do more
  2. $ is a alias of jquery
  3. every element must have it's name and id
  4. Jquery get the details of each element when the document load
  5. sometimes here we gives fake classes to identify element


Thursday, December 11, 2014

Javascript Learning

Script has the 6 attributes
async, charset, defer, language, src, type

If src path given with inline JS then only external JS will execute

defer
=============
defer attribute on a <script> element tells browser that download should begin immediately but execution should be deferred:
<script type="text/javascript" defer src="example1.js"></script>

async
==============
It signals the browser to begin downloading the file immediately
<script type="text/javascript" async src="example1.js"></script>

noscript
==============
noscript element provides alternate content for browsers without JavaScript.
<head>
    <script src="example1.js"></script>
</head>
<body>
 <noscript>
   <p>This page requires a JavaScript-enabled browser.</p>
 </noscript>

Functions 
==============
NaN
isNaN
isFinite
Math.sqrt
Math.exp
parseInt()
parseFloat()
toString()
String()
log.console()
prompt()
alert()
toString()
document.write()
onClick()
onBlur()
onChange()
function()
onSubmit()

Constants
=================
Number.MIN_VALUE -> Smallest Value in JS
Number.MAX_VALUE -> stores the largest number.
Number.NEGATIVE_INFINITY -> is the negative infinity.
Number.POSITIVE_INFINITY -> is the positive infinity.