jQuery Clone

Its very Interesting topic Of jQuery..

The .clone() method performs a deep copy of the set of matched elements,

meaning that it copies the matched elements as well as all of their descendant elements and text nodes.

When used in conjunction with one of the insertion methods,

.clone() is a convenient way to duplicate elements on a page.

You Will Found Interesting.

Try It.

Go Through Below Code, And Found Use Of Clone..

<html>
<head>
<script src=”http://code.jquery.com/jquery-latest.js”></script&gt;
<script type=”text/javascript”>
$(document).ready(function(){
$(“.add”).click(function(){
$(“#one”).clone(true).insertAfter(“#one”)
.find(‘input[type=”text”]’).val(”).end()
});
$(‘.delete’).click(function(){
$(this).parents(“#one”).remove();
});
});
</script>
</head>
<tbody id=”mainDiv”>
<table>
<tr id=”one”>
<td><input type=”text” value=”” name=””/></td>
<td><input type=”text” value=”” name=””/></td>
<td><input type=”button” value=”add” name=”add” class=”add”/></td>
<td><input type=”button” value=”delete” name=”delete” class=”delete”/></td>
</tr>
</table>
</tbody>
</html>

it will output Like This…
//  You can add row by click on add and remove by just simply click on remove.

//

Awsome Java Script.

Copy The Code Below And Paste it. save with .html extension. You Will get Flying Bats On Your Screen…

EnjoYY Itt…….bat_1

<html>
<head>
<script language=”JavaScript1.2″>
Bat=new Image();
//////////CONFIGURE THE BATs SCRIPT HERE//////////////////

Bat.src=”image/bat_1.gif”; // Specify path to your bat image
amount=3; // Number of Bats, minimum must be 3
dismissafter=20; // Seconds after which Bats should disappear, in seconds
step=0.3; // Animation speed (smaller is slower)

//////////DO NOT EDIT PAST THIS LINE//////////////////

Xpos=700; //Bats x coordinates, in pixel
Ypos=200; //Bats y coordinates, in pixel

var ns6=document.getElementById&&!document.all
bats=new Array(3)
if (document.layers){
for (i=0; i < amount; i++)
{document.write(“<layer name=n”+i+” left=0 top=-50><a href=’http://rainbow.arch.scriptmania.com’><img src='”+Bat.src+”‘ name=’nsi’ width=69 height=60 border=0></a></layer>”)}
}
else if (document.all||ns6){
document.write(‘<div id=”out” style=”position:absolute;top:0;left:0″><div id=”in” style=”position:relative”>’);
for (i=0; i < amount; i++){
if (document.all)
document.write(‘<a href=”http://rainbow.arch.scriptmania.com”><img src=”‘+Bat.src+'” id=”msieBats” style=”position:absolute;top:-50;left:0″ border=0></a>’)
else
document.write(‘<a href=”http://rainbow.arch.scriptmania.com”><img src=”‘+Bat.src+'” id=”ns6Bats’+i+'” width=69 height=60 style=”position:absolute;top:-50;left:0″ border=0></a>’)
}
document.write(‘</div></div>’);
}

yBase=xBase=currStep=a_count=0;
b_count=1;
c_count=2;
d_count=3;
move=1;
if (document.layers||ns6){
yBase=window.innerHeight/3;
xBase=window.innerWidth/6;
if (document.layers)
window.captureEvents(Event.MOUSEMOVE);

}
if (document.all){
yBase = window.document.body.offsetHeight/3;
xBase = window.document.body.offsetWidth/6;
}

function dismissBat(){
clearInterval(flyBat)
if (document.layers){
for (i2=0; i2 < amount; i2++){
document.layers[‘n’+i2].visibility=”hide”
}
}
else if (document.all)
document.all.out.style.visibility=”hidden”
else if (ns6)
document.getElementById(“out”).style.visibility=”hidden”
}

if (document.layers){
for (i=0; i < amount; i++)
document.layers[‘n’+i].document.images[‘nsi’].src=Bat.src
}
else if (document.all){
for (i=0; i < amount; i++)
document.all.msieBats[i].src=Bat.src
}
else if (ns6){
for (i=0; i < amount; i++)
document.getElementById(“ns6Bats”+i).src=Bat.src
}

function Animate(){
a_count+=move;
b_count+=move;
c_count+=move;
currStep+=step;
if (a_count >= bats.length) a_count=0;
if (b_count >= bats.length) b_count=0;
if (c_count >= bats.length) c_count=0;
if (document.layers){
for (i=0; i < amount; i++) {
var NewL=”n”+i
document.layers[NewL].top = Ypos+yBase*Math.sin(((currStep)+i*3.7)/4)*Math.cos((currStep+i*35)/10)
document.layers[NewL].left =Xpos+xBase*Math.cos(((currStep)+i*3.7)/4)*Math.cos((currStep+i*35)/62)
}
}

if (document.all){
for (i=0; i < amount; i++){
document.all.msieBats[i].style.pixelTop = Ypos+yBase*Math.sin(((currStep)+i*3.7)/4)*Math.cos((currStep+i*35)/10)
document.all.msieBats[i].style.pixelLeft =Xpos+xBase*Math.cos(((currStep)+i*3.7)/4)*Math.cos((currStep+i*35)/62)
}
}

if (ns6){
for (i=0; i < amount; i++){
document.getElementById(“ns6Bats”+i).style.top = Ypos+yBase*Math.sin(((currStep)+i*3.7)/4)*Math.cos((currStep+i*35)/10)
document.getElementById(“ns6Bats”+i).style.left =Xpos+xBase*Math.cos(((currStep)+i*3.7)/4)*Math.cos((currStep+i*35)/62)
}
}

}
flyBat=setInterval(‘Animate()’,30);
setTimeout(“dismissBat()”,dismissafter*1000)
//–>
</script>
</head>
</html>

EnjoY It.

click By mouse And Feed Fishes.. You Will Like It..

For Each Loop

To Understand FOREACH Loops First You Must Have Learnt Arrays. The foreach construct provides an easy way to iterate over arrays.When using a loop with an array, instead of having a counter that goes until proven false the FOREACH loop continues until it has used all values in the array. So for example if an array contained 5 pieces of data, then the FOREACH loop would execute 5 times. More uses for arrays and FOREACH loops will become apparent when you start importing data from MySQL.

Syntax 1:   foreach (array_expression as $key => $value)
                      statement
Syntax 2:   foreach (array_expression as $key => $value)
                      statement

Lets Start With Simple Example.

<?php
$a = array('Sangna','jani');
foreach($a as $value)
{
print $value . " ";
}
// it will output: Sangna Jani
?>

Now Try Another Example, Here Is An Array contains the ages of 5 family members Then we will make a FOREACH loop that will determine how much it costs for each of them to travel  that has varied prices based on age. We will use the following pricing system: Under 5 costs $165, 5-12 years costs $200 and over 12 years is $350.

<?php 
 $tot = 0; 
 $age = array(34, 30, 12, 9, 4); 
 foreach ($age as $a) 
 { 
 if ($a < 5) 
 {
 $p = 165;
 } 
 else 
 { 
 if ($a < 12) 
 {
 $p = 200;
 } 
 else 
 {
 $p = 350;
 } 
 } 
 $tot = $tot + $p; 
 print "$". $p . "<br>"; 
 } 
 print "The total is: $" . $tot; 
 ?>

Mixins

Basic About Mixins:–

In general computer science, a mixin is a class that defines a set of functions relating to a type (e.g. Person, Circle, Observer). Mixins classes are usually considered abstract in that they will not themselves be instantiated – instead their functions are copied (or ‘borrowed’) by concrete classes as a means of ‘inheriting’ behaviour without entering into a formal relationship with the behaviour provider.

Its Very Useful Concept Of Javascript…

In java script we have objects(instances) which offer clarity and flexibility: our mixin can be a regular object, a prototype, a function – whatever, and the mixin process becomes transparent and obvious.

Re-Using Functions:–

a single prototype instance can define properties for an infinite number of dependent instances. Prototypes may also inherit from other prototypes, thus forming prototype chains which more-or-less mimic the inheritance hierarchies of classical languages like Java and C++. Multi-tiered inheritance hierarchies are occasionally useful for describing the natural order of objects but if the primary motivation is function re-use they can quickly become gnarly labyrinths of meaningless subtypes, frustrating redundancies and unmanageable logic

they are only common behaviors or functionalities (common properties or common methods) that let you use them anywhere.

Fortunately, when it comes to function re-use, JavaScript offers viable alternatives. In contrast to more rigidly structured languages, JavaScript objects can invoke any public function regardless of lineage.

The most straightforward approach is delegation – any public function can be invoked directly via call or apply. It’s a powerful feature and I use it extensively. However delegation is so convenient that sometimes it actually works against structural discipline in your code; moreover the syntax can get a little wordy.

Mixins are a great compromise, allowing entire functional units to be borrowed and accessed with minimal syntax and they play very well with prototypes. They offer the descriptive prowess of hierarchical inheritance without the brain-cracking issues associated with multi-tiered, single-rooted ancestry.

How To Use Mixins:–

It is possible to do a mixin class in JavaScript as in Ruby. This is another way to make our code reuse without inheritance. Consider you have a function, and you wish to use in many classes. In practice, you create a class that contains your general-purpose methods, and then use it to augment other classes.

Class with these general-purpose methods is called Mixin class. It is generally not instantiated or called directly, instead it exists to provide methods to other classes.

var Mixin = function() {};
Mixin.prototype = {
   serialize: function() {
      var output = [];
      for(key in this) {
         output.push(key + ': ' + this[key]);
      }
      return output.join(', ');
   }
};

This sort of method could potentially be useful in many different types of classes, but it doesn’t make sense to have each of these classes inherit from Mixin.

Similarly, duplicating the code in each class doesn’t make much sense either. The best approach is to use the augment function to add this method to each class that needs it:

augment(Author, Mixin);

var author = new Author('Ross Harmes', ['JavaScript Design Patterns']);
var serializedString = author.serialize();

This can be thought of as a way to implement multiple inheritance in JavaScript.

/* Augment function. */
function augment(receivingClass, givingClass) {
   for(methodName in givingClass.prototype) {
      if(!receivingClass.prototype[methodName]) {
         receivingClass.prototype[methodName] = givingClass.prototype[methodName];
      }
   }
}

A more robust augment allows copying one or two of them over to another class.

/* Augment function, improved. */
function augment(receivingClass, givingClass) {
   if(arguments[2]) { // Only give certain methods.
      for(var i = 2, len = arguments.length; i < len; i++) {
         receivingClass.prototype[arguments[i]] = givingClass.prototype[arguments[i]];
      }
   }
   else { // Give all methods.
      for(methodName in givingClass.prototype) {
         if(!receivingClass.prototype[methodName]) {
            receivingClass.prototype[methodName] = givingClass.prototype[methodName];
         }
      }
   }
}

You can now write augment(Author, Mixin, ‘serialize’); to only augment Author with the single serialize method.

In other times, you don’t have to need this augment function in order to do Mixins. You could do this by using apply or call method inside constructor function.

var Author = function(name, books) {
   this.name = name || "";
   this.books = books || [];

   Mixin.apply(this);
};

Often it makes more sense to augment a class with a few methods than it does to make
one class inherit from another. This is a lightweight way to prevent code duplication.

Unfortunately, there aren’t many situations where it can be used. Only methods general enough to be used in very dissimilar classes make good candidates for sharing (if the classes aren’t that dissimilar, normal inheritance is often a better choice).

Overloading

Traditionally Overloading means to have a Multiple methods with same Name but different Arguments,

But In PHP its different than other languages.

OVERLOADING maeans to create Property and methods Dynamically.

Overloading method invokes while interacting with Properties or Methods, That have not been declared or not visible in the Current Scope.

All Overloading Methods Must Be Declared Public.

Follow

Get every new post delivered to your Inbox.