Login   Register  
Icontem

File: example.html

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Evert Ulises German Soto  >  LocalStorage  >  example.html  >  Download  
File: example.html
Role: Example script
Content type: text/plain
Description: Example of use
Class: LocalStorage
Set and get application data in local storage
Author: By
Last change: Added delete elements example
Date: 2013-12-04 05:48
Size: 5,129 bytes
 

Contents

Class file image Download
<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <title>wArLeY996_Storage.js by GoPanga.com</title>
  <script src="wArLeY996_Storage.js" type="text/javascript"></script>
  <script type="text/javascript">
    //------------------------------------------------------------------------------------------
    //If you want clear all content in localStorage (careful with another values).
    //------------------------------------------------------------------------------------------
    wArLeY996_Storage.clearStorage();

    //------------------------------------------------------------------------------------------
    //Alert about developer
    //------------------------------------------------------------------------------------------
    wArLeY996_Storage.printAbout();

    //------------------------------------------------------------------------------------------
    //Rename the default values in class (required for your app)
    //------------------------------------------------------------------------------------------
    wArLeY996_Storage.nameSpace = "coppel.com.campaigns";
    wArLeY996_Storage.appModule = "captura_correos";
    wArLeY996_Storage.objElement = "suscribed";

    //------------------------------------------------------------------------------------------
    //Creating and assign values to elements
    //------------------------------------------------------------------------------------------
    wArLeY996_Storage.setElement('extra', 'full retrieve');
    wArLeY996_Storage.setElement('suscribed', true);
    wArLeY996_Storage.setElement('suscribed.test', "test 1");
    wArLeY996_Storage.setElement('suscribed.prueba', "prueba 1");

    //------------------------------------------------------------------------------------------
    //Get specified element value
    //------------------------------------------------------------------------------------------
    var elementValue = wArLeY996_Storage.getElement('suscribed');
    console.log("Response: " + elementValue);

    //------------------------------------------------------------------------------------------
    //Getting all elements in your application
    //------------------------------------------------------------------------------------------
    var objJson_full = wArLeY996_Storage.getElements();
    console.log(objJson_full);
    //Accessing the values if response was succesful
    if(objJson_full.success==true){
      alert(objJson_full['coppel.com.campaigns.captura_correos.extra']);
      alert(objJson_full['coppel.com.campaigns.captura_correos.suscribed.test']);
    }

    //------------------------------------------------------------------------------------------
    //Deleting by key or array keys
    //------------------------------------------------------------------------------------------
    // For group of keys
    if(typeof(wArLeY996_Storage)=='object'){
		if(wArLeY996_Storage.supportsLocalStorage()==true){
		    wArLeY996_Storage.nameSpace = "coppel.com.campaigns";
    		wArLeY996_Storage.appModule = "captura_correos";
    		wArLeY996_Storage.objElement = "suscribed";

		    var arrSessions = ['suscribed', 'session_email'];

		    wArLeY996_Storage.delElement(arrSessions);
	    }
    }
    // For only unique key
    if(typeof(wArLeY996_Storage)=='object'){
		if(wArLeY996_Storage.supportsLocalStorage()==true){
		    wArLeY996_Storage.nameSpace = "coppel.com.campaigns";
    		wArLeY996_Storage.appModule = "captura_correos";
    		wArLeY996_Storage.objElement = "suscribed";

		    var strSession = 'suscribed';

		    wArLeY996_Storage.delElement(strSession);
	    }
    }

    //------------------------------------------------------------------------------------------
    //Getting only derivatives nodes of 'suscribed' of your application
    //------------------------------------------------------------------------------------------
    var objJson_node = wArLeY996_Storage.getElements('suscribed');
    console.log(objJson_node);
    //Accessing the values if response was succesful
    if(objJson_full.success==true){
      alert(objJson_full['coppel.com.campaigns.captura_correos.suscribed.prueba']);
    }

    //------------------------------------------------------------------------------------------
    //Getting only derivatives nodes of 'not_exist' (not exist this node)
    //------------------------------------------------------------------------------------------
    var objJson_fail = wArLeY996_Storage.getElements('not_exist');
    console.log(objJson_fail);
    if(objJson_fail.success==false) alert("An unexpected error has occurred");
  </script>
</head>
<body style="background-color: #FFFFFF">
<h1>wArLeY996_Storage.js</h1>
<h2>This is a simple class to manage your localStorage for specific application.</h2>

<p>Requeriments: This class require a modern browser with HTML5 support, such as Google Chrome, Mozilla Firefox, Opera, Safari, &#191;IE9+&#63;</p>

<hr />

Developed by wArLeY996 © GoPanga.com, 2013

</body>
</html>