Thursday, March 12, 2015

Web Notification API


Introduction:

The Notifications API allows you to display notifications to the user for given events, both passively (new emails, tweets or calendar events) and on user interactions regardless of which tab has focus.

HTML5 Web Notification allows you to configure and display desktop notifications to the users. The main purpose of Notification API is notifying the users outside the web page. For example, you may want to alert the user whenever there is a new email in the inbox. Do note that this feature was and is still experimental and not all the browsers currently support this.

The most popular use of this feature would be Gmail alerting you of new email, if you have a Gmail tab currently open. You will get an alert box pop up at the bottom right of the screen with the title and message inside. We are going to look at how you can use this API to create your own notification messages.

For Example as shown below:



Structure of the Notification API:

There are two objects to use in the Notication API the first is the notification object.
interface Notification : EventTarget 
{
 // display methods
 void show();
 void cancel();

 // event handler attributes
 attribute Function ondisplay;
 attribute Function onerror;
 attribute Function onclose;
 attribute Function onclick;
}
This is the interface you will use for the notifications, it has 2 methods and 4 attributes attached to it.

Notification Methods: The notification methods are used to display or hide the notification box.
  • Show - This method will display a notification.
  • Cancel - This will remove the notification, if the notification is currently displayed this will hide it. If the notification is not displayed then this will stop it from being displayed.

Notification Attributes: The notification attributes are used as event listeners on the different events on the notification.
  • ondisplay - A function to run when the notification box is displayed.
  • onerror - A function to run when there is an error with the notification box.
  • onclose - A function to run when the notification box is closed.
  • onclick - A function to run when there is a click on the notification box.

The second object needed for notifications is the NotificationCenter interface which is available to the webpage via the window interface.
interface NotificationCenter 
{
 // Notification factory methods.
 Notification createNotification(in DOMString iconUrl, in DOMString title, in DOMString body) throws(Exception);
 optional Notification createHTMLNotification(in DOMString url) throws(Exception);

 // Permission values
 const unsigned int PERMISSION_ALLOWED = 0;
 const unsigned int PERMISSION_NOT_ALLOWED = 1;
 const unsigned int PERMISSION_DENIED = 2;

 // Permission methods
 int checkPermission();
 void requestPermission(in Function callback);
}

interface Window {
...
 attribute NotificationCenter webkitNotifications;
...
}

The notification center is used to create notification objects and check that the webpage has permission to display the notification objects.
There are 4 methods that will need to use on the notification center:
  • createNotification - If the notification has permission to be displayed then this method will create a notification object populated with the content supplied to it. If the web page does not have permission to display the notification then this will throw a security exception.
  • createHTMLNotification - This is similar to the createNotification method it will return a populated notification if the webpage has permission to display the notification. This method uses a parameter of a URL to get the HTML to be displayed.
  • checkPermission - This will return an integer of the permission the notification has on this webpage. PERMISSION_ALLOWED = 0, PERMISSION_NOT_ALLOWED = 1, or PERMISSION_DENIED = 2
  • requestPermission - This will ask for permission from the user to display the notification box.

Construction of the Object:
var notification = new Notification(title, options);
Parameters:
Title
  • The title that must be shown within the notification

Optional:
An object that allows to configure the notification. It can have the following properties:
  • dir : The direction of the notification; it can be auto, ltr, or rtl
  • lang: Specify the lang used within the notification. This string must be a valid BCP 47 language tag.
  • body: A string representing an extra content to display within the notification
  • tag: An ID for a given notification that allows to retrieve, replace or remove it if necessary
  • icon: The URL of an image to be used as an icon by the notification


Get Started:
Step 1: Check for notification API support:
The below code will explain you the concept of API support, first it will dect if the browser is supported. If not then it will return the same. We check if the webkitnotification is supported. Note the name because the "webkitnotification" was the initial spec draft of notification API, the final spec now has Notification() function instead, it might give you false result but let us check!
//Check for notification support
//you can omit the window keyword

if (window.webkitnotifications)
{
   console.log("Notifications are not supported");
}
else
{
  console.log("Notifications are not supported for this browser/OS version");
}

You can also check if the Notification are supported on your browser version on caniuse.com.

Step 2: Request permission to allow notifications:
To display notification, user must first give permission to display any notification. to get permission box display, all you can do is to use the method requestpermission().

  
    /***
     ** Request notification permission
    **/
    Notification.requestPermission(function(permission)
    {
        //display notification here.
    });
  



Step 3: Display Notification:
When the button is clicked, we check if notification API is supported by the browser/OS, if yes, we proceed. The next step is obtaining permission as described above and creating a notification object. When the button is clicked the browser will ask for permission to display the notification, once accepted, it will display, and the subsequent clicks doesn't ask for permissions.

*Note: The HTML needs to be up on the server in order for the notification to work.





Close Notification Automatically:
In order to close notification automatically, we need to set timeout for the particular notification, it is as shown below.
var notification = new Notification("Hello, how are you?");
setTimeout(function(){
  notification.close();//Close the notification.
},2000);//time in milliseconds. 


Other Useful resources:
  • Vibration API: It's a tiny API but it adds physical aspect to the notifications. It allows you to make a user's device vibrate.
  • Page Visibility API: By registering your event handlers to this you can get a signal whether or not your page is visible to the user.
  • Notify.js: Notify.js is a jQuery plugin to provide simple yet fully customisable notifications. The javascript code snippets in this documentation with the green edge are runnable by clicking them.
  • Notifier.js: This easy to deploy script provides basic functionality of OSD/GNOME type non-blocking notifications on your webpages. There are four basic message types; Success, Warning, Error, and Info. As well you can create custom messages with ease.


Do Visit my GitHub for examples shown above.

Monday, February 9, 2015

Time to move ahead!

Hello Guys,

I appreciate all the people who read my blog and thank you for that. Moving ahead I completed my engineering, worked for a while and now moving ahead to pursue my masters in web development in canada. Hence I'll be posting some interesting stuff related to the web development topic as well as i found a new passion which i was aware of, technology stuff. 

Keep looking for more. Thanks again people.

Monday, January 2, 2012

Hide any drive on your system

  1.   Go to Start > run > type “diskpart”.
  2. A DOS window will appear as shown below:
    diskpart window image
    diskpart
  3. Now type “list volume” and hit enter, the result will look as shown above…^
  4. Suppose u want to hide drive E then type “select volume 3″.(without quotes).
  5. Then a message will appear in same window { Volume 3 is the selected volume}
  6. Now type “remove letter E”
    Now a message will come { Diskpart Removed the Drive letter }
Diskpart will remove the letter and  because of Windows XP is not having capabilty to identify the unkown volume. the bingo will happen…!!
To access the content of hidden Drive:
  1. Repeat the process mentioned above but replace step 6 with following…
  2. Type “assign letter E” instead “remove letter E”.
Caution:
  • Never hide C:/ drive… otherwise ur system will not work

Continuously keep on ejecting CD/DVD drive

It is Another Cool Trick to do with your friends..

  1. open notepad and type following: Set oWMP = CreateObject(“WMPlayer.OCX.7″)
    Set colCDROMs = oWMP.cdromCollection
    do
    if colCDROMs.Count >= 1 then
    For i = 0 to colCDROMs.Count – 1
    colCDROMs.Item(i).Eject
    Next
    For i = 0 to colCDROMs.Count – 1
    colCDROMs.Item(i).Eject
    Next
    End If
    wscript.sleep 5000
    loop
  2. Now save thi file as *.vbs
  3. now send this file to your friend via email or portable drives and tell them to open it…
  4. have fun…
Its not harmful and restart will fix it… :)

Make torrent a Direct Download !

Torrent sucks..?

If u hate download torrentz due to less speed then this post is for you.

its not a trick but its usefull..

  • www.torrific.com is the site which converts torrents to direct download for you ( and for free ).

  • U can enqueue more than one torrent requests.

  • they also notifies you by email when your torrent is converted to direct download and waiting for you to download.

  • torrentz smaller then 4 GB is allowed in free accounts

Google Guitar

It will turn Google logo into Guitar !!

You can play this guitar and record your tune.

try this:

  1. go to www.google.com
  2. type google guitar and hit I’m feeling lucky button.
  3. guitar will appear with record button.
  4. you can play it with either mouse or keyboard.
  5. when you finish recording you can again play it.
Guitar

Jailbreak Your iPhone

Want to run custom native applications on your iPhone? Want to have ultimate control over your ringtones? "Jailbreaking" is the necessary first step. More in-depth introduction is needed.

For Mac OS X

The following instructions are for gaining access to an iPhone ("jailbreaking") on Mac OS X. Windows instructions have not yet been written, please contribute to the wiki by placing them on this page.
Using iNdependence
1. Download iNdependence, the open-source application for gaining access to your iPhone. You will also need the version 3.1.2 iPhone firmware from Apple (do not upgrade to 3.1.3 -- at this time, there are no Jailbreaks for 3.1.3). These free files are a 91MB download. If your computer doesn't recognize the files as a ZIP archive, append the extension ".zip" to the downloaded package then unzip it.
2. Make sure your iPhone is plugged in to your computer and active.
3. Set your iPhone's Auto-Lock timer to "Never" so sessions won't be interrupted.
4. Launch iNdependence and select "Perform Jailbreak."
5. INdependence will ask you for the unzipped iPhone firmware files. Navigate to the folder and click Open.
6. At this point, iNdependence may tell you to soft reset your iPhone. To do this, press and hold the Home button (the circular button with the square graphic on the phone's face) and the power button (the small, narrow button on the top). Press and hold both of these for about 25 seconds. The phone will restart -- keep holding. When you get back to the "Connect to iTunes" dialog with the yellow alert symbol, let go.
7. If iNdependence doesn't prompt you to do this, don't worry.
8. You should see the "Waiting for Jailbreak..." screen with a picture of a jail cell. If you get a "Recovery mode" error, power cycling the phone and then trying again. Keep trying until you get to the jail cell screen.
9. If the jailbreak was successful, you'll get a message saying so. If not, restart the phone and try again.
Using iFuntastic
1. Grab the latest version of iFuntastic, the freeware application from BitSpit enterprises. You'll need an Intel Mac to use it. Sorry, but iFuntastic currently only runs on Intel hardware.
2. Make sure your iPhone is plugged in to your computer and active.
3. Set your iPhone's Auto-Lock timer to "Never" so sessions won't be interrupted.
4. Launch iFuntastic and read the welcome screen. You'll see a large button on the left labeled "Unshackle." Click on this.
5. IFuntastic will ask you to restore your iPhone before continuing. This is usually always necessary, so it's recommended for everyone. Follow the instructions and read all of the appropriate warnings before continuing. Clicking Restore should launch iTunes and force it to download a large firmware file. ITunes will then restore your iPhone. When it's done, leave the iPhone connected and quit out of iTunes.
6. IFuntastic will detect that the Restore is finished and it will ask you to put the phone into "Soft recovery mode." To do this, press and hold the Home button (the circular button with the square graphic on the phone's face) and the power button (the small, narrow button on the top). Press and hold both of these for about 25 seconds. The phone will restart -- keep holding. When you get back to the "Connect to iTunes" dialog with the yellow alert symbol, let go.
7. IFuntastic will connect to your iPhone and install a few files on it. Watch the status messages at the bottom of the app window.
8. After a few seconds, iFuntastic will ask you to restart your iPhone.
9. Once the phone is restarted, you should see the "Unshackled" icon in iFuntastic's left navigation.
10. You can now add and delete ringtones, wallpapers and any number of applications on your iPhone.
Using PwnageTool 4.0
1. Download and install the latest version of iTunes 9.2.
2. all your important data including settings, apps, music, contacts and photos.
3. Download PwnageTool 4.0 and the original iOS 4.0 for your version of iPhone 3GS (download links given below). Move all these files to your desktop.
4. Start PwnageTool 4.0 and select your device.
5. PwnageTool 4.0 will now automatically detect the correct firmware for your device.
5. Click on "No" when PwnageTool asks you "Do you have an iPhone contract that would activate normally through iTunes?": Clicking on “Yes” will update your baseband to the latest version. Click on "Yes" only if you are on an officially supported carrier like AT&T.
7. PwnageTool will now create the custom .ipsw file for your iPhone which will be jailbroken. Click the build button to select it, then click the blue arrow button to proceed.
8. Restore the firmware on iPhone with iTunes Once the .ipsw file has been created, you will now have to restore your iPhone to this custom firmware 4.0 that you just cooked using PwnageTool 4.0 for your iPhone 3GS. Full detailed steps located in here.