Tuesday, 19 March 2013

The jQuery noConflict() Method


Example---------shiv's refined

$.noConflict();
jQuery(document).ready(function(){
  jQuery("button").click(function(){
    jQuery("p").text("jQuery is still working!");
  });
});

jQuery Event Methods

MethodDescription
bind()Attaches event handlers to elements
blur()Attaches/Triggers the blur event
change()Attaches/Triggers the change event
click()Attaches/Triggers the click event
dblclick()Attaches/Triggers the double click event
delegate()Attaches a handler to current, or future, specified child elements of the matching elements
die()Removed in version 1.9. Removes all event handlers added with the live() method
error()Attaches/Triggers the error event
event.currentTargetThe current DOM element within the event bubbling phase
event.dataContains the optional data passed to an event method when the current executing handler is bound
event.delegateTargetReturns the element where the currently-called jQuery event handler was attached
event.isDefaultPrevented()Returns whether event.preventDefault() was called for the event object
event.isImmediatePropagationStopped()Returns whether event.stopImmediatePropagation() was called for the event object
event.isPropagationStopped()Returns whether event.stopPropagation() was called for the event object
event.namespaceReturns the namespace specified when the event was triggered
event.pageXReturns the mouse position relative to the left edge of the document
event.pageYReturns the mouse position relative to the top edge of the document
event.preventDefault()Prevents the default action of the event
event.relatedTargetReturns which element being entered or exited on mouse movement.
event.resultContains the last/previous value returned by an event handler triggered by the specified event
event.stopImmediatePropagation()Prevents other event handlers from being called
event.stopPropagation()Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event
event.targetReturns which DOM element triggered the event
event.timeStampReturns the number of milliseconds since January 1, 1970, when the event is triggered
event.typeReturns which event type was triggered
event.whichReturns which keyboard key or mouse button was pressed for the event
focus()Attaches/Triggers the focus event
focusin()Attaches an event handler to the focusin event
focusout()Attaches an event handler to the focusout event
hover()Attaches two event handlers to the hover event
keydown()Attaches/Triggers the keydown event
keypress()Attaches/Triggers the keypress event
keyup()Attaches/Triggers the keyup event
live()Removed in version 1.9. Adds one or more event handlers to current, or future, selected elements
load()Attaches an event handler to the load event
mousedown()Attaches/Triggers the mousedown event
mouseenter()Attaches/Triggers the mouseenter event
mouseleave()Attaches/Triggers the mouseleave event
mousemove()Attaches/Triggers the mousemove event
mouseout()Attaches/Triggers the mouseout event
mouseover()Attaches/Triggers the mouseover event
mouseup()Attaches/Triggers the mouseup event
off()Removes event handlers attached with the on() method
on()Attaches event handlers to elements
one()Adds one or more event handlers to selected elements. This handler can only be triggered once per element
$.proxy()Takes an existing function and returns a new one with a particular context
ready()Specifies a function to execute when the DOM is fully loaded
resize()Attaches/Triggers the resize event
scroll()Attaches/Triggers the scroll event
select()Attaches/Triggers the select event
submit()Attaches/Triggers the submit event
toggle()Removed in version 1.9. Attaches two or more functions to toggle between for the click event
trigger()Triggers all events bound to the selected elements
triggerHandler()Triggers all functions bound to a specified event for the selected elements
unbind()Removes an added event handler from selected elements
undelegate()Removes an event handler to selected elements, now or in the future
unload()Attaches an event handler to the unload event

jQuery Callback Functions

Typical syntax: $(selector).hide(speed,callback);


Example with Callback

$("button").click(function(){
  $("p").hide("slow",function(){
    alert("The paragraph is now hidden");
  });
});

Example without Callback

$("button").click(function(){
  $("p").hide(1000);
  alert("The paragraph is now hidden");
});

Monday, 18 March 2013

Shivendra's Programmed


Constructors (basics)


Using Constructors (C# Programming Guide)

public class Taxi
{
    public bool isInitialized;
    public Taxi()
    {
        isInitialized = true;
    }
}

class TestTaxi
{
    static void Main()
    {
        Taxi t = new Taxi();
        Console.WriteLine(t.isInitialized);
    }
}

public class Employee
{
    public int salary;

    public Employee(int annualSalary)
    {
        salary = annualSalary;
    }

    public Employee(int weeklySalary, int numberOfWeeks)
    {
        salary = weeklySalary * numberOfWeeks;
    }
}
This class can be created by using either of the following statements:
Employee e1 = new Employee(30000);
Employee e2 = new Employee(500, 52);
A constructor can use the base keyword to call the constructor of a base class. For example:
public class Manager : Employee
{
    public Manager(int annualSalary)
        : base(annualSalary)
    {
        //Add further instructions here.
    }
}
public Manager(int initialdata)
{
    //Add further instructions here.
}
public Manager(int initialdata)
    : base()
{
    //Add further instructions here.
}
public Employee(int weeklySalary, int numberOfWeeks)
    : this(weeklySalary * numberOfWeeks)
{
}
The use of the this keyword in the previous example causes this constructor to be called:
public Employee(int annualSalary)
{
    salary = annualSalary;
}
shivendra mani.................%$#%^$#

.NET and Object Serialization


//Core Serialization
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace MyObjSerial
{
    [Serializable()]    //Set this attribute to all the classes that want to serialize
    public class Employee : ISerializable //derive your class from ISerializable
    {
        public int EmpId;
        public string EmpName;
        
        //Default constructor
        public Employee()
        {
            EmpId = 0;
            EmpName = null;
        }
        }
}
//Main class
public class ObjSerial
{
    public static void Main(String[] args)
    {
        //Create a new Employee object
        Employee mp = new Employee();
        mp.EmpId = 10;
        mp.EmpName = "Omkumar";
                
        //Add code below for serialization
    }
}
            
// Open a file and serialize the object into it in binary format.
// EmployeeInfo.osl is the file that we are creating. 
// Note:- you can give any extension you want for your file
// If you use custom extensions, then the user will now 
//   that the file is associated with your program.
Stream stream = File.Open("EmployeeInfo.osl", FileMode.Create);
BinaryFormatter bformatter = new BinaryFormatter();
            
Console.WriteLine("Writing Employee Information");
bformatter.Serialize(stream, mp);
stream.Close();
//Clear mp for further usage.
mp = null;
            
//Open the file written above and read values from it.
stream = File.Open("EmployeeInfo.osl", FileMode.Open);
bformatter = new BinaryFormatter();
        
Console.WriteLine("Reading Employee Information");
mp = (Employee)bformatter.Deserialize(stream);
stream.Close();
            
Console.WriteLine("Employee Id: {0}",mp.EmpId.ToString());
Console.WriteLine("Employee Name: {0}",mp.EmpName);

Friday, 15 March 2013