Advertisement
patadejaguar

resources.bb.js

Dec 18th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Resources
  3.  * Implements the javascript access to the phonegap plugin for retrieving specific resource information
  4.  * Based in original resources from Olivier Brand. Tested in Cordova 2.0
  5.  * @version 1.0
  6.  * @author Luis Balam
  7.  * Modified for Blackberry
  8.  */
  9.  
  10. /**
  11.  * @return the Resources class instance
  12.  */
  13. var LocalResources = function() {
  14. };
  15.  
  16. /**
  17.  * Returns the named resources defined in R.strings Note the last parameter,
  18.  * this method is synchronous
  19.  *
  20.  * @param successCallback
  21.  *            The callback which will be called when directory listing is
  22.  *            successful
  23.  * @param failureCallback
  24.  *            The callback which will be called when directory listing encouters
  25.  *            an error
  26.  */
  27. LocalResources.prototype.getStrings = function(params, successCallback, failureCallback) {
  28.    
  29.     if (failureCallback == null) { failureCallback = function() {}; };
  30.     if (typeof failureCallback != "function")  {
  31.         failureCallback = function(){};
  32.     }
  33.     if (typeof successCallback != "function")  {
  34.         successCallback = function(){};
  35.     }
  36.    
  37.     //read xml
  38.     var xFile       = "../res/values/strings.xml";
  39.     var arrRs       = {};
  40.     arrRs["SYSTEM_LANG"]    = "en";
  41.    
  42.     $.ajax({
  43.         url:xFile, // relative path to www folder
  44.         type:"get",
  45.         contentType:"xml",
  46.         success: function(xml){
  47.             //todo:
  48.             //read nodes string
  49.             $(xml).find("string").each(function()
  50.             {
  51.                 arrRs[$(this).attr("name")]   = $(this).text();
  52.             });
  53.             //execute the function
  54.             successCallback(arrRs);
  55.         }
  56.     });
  57.    
  58. };
  59.  
  60. if(!window.plugins) {
  61.     window.plugins = {};
  62. }
  63.  
  64. if (!window.plugins.resources) {
  65.     window.plugins.resources = new LocalResources();
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement