Advertisement
patadejaguar

resources.bb.js Strings.xml on Blackberry WebWorks

Mar 7th, 2013
203
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.  */
  8.  
  9. /**
  10.  * @return the Resources class instance
  11.  */
  12. var LocalResources = function() {
  13. };
  14.  
  15. /**
  16.  * Returns the named resources defined in R.strings Note the last parameter,
  17.  * this method is synchronous
  18.  *
  19.  * @param successCallback
  20.  *            The callback which will be called when directory listing is
  21.  *            successful
  22.  * @param failureCallback
  23.  *            The callback which will be called when directory listing encouters
  24.  *            an error
  25.  */
  26. LocalResources.prototype.getStrings = function(params, successCallback, failureCallback) {
  27.    
  28.     if (failureCallback == null) { failureCallback = function() {}; };
  29.     if (typeof failureCallback != "function")  {
  30.         failureCallback = function(){};
  31.     }
  32.     if (typeof successCallback != "function")  {
  33.         successCallback = function(){};
  34.     }
  35.    
  36.     //read xml
  37.     var xFile       = "../res/values/strings.xml";
  38.     var arrRs       = {};
  39.     arrRs["SYSTEM_LANG"]    = "en";
  40.    
  41.     $.ajax({
  42.         url:xFile, // relative path to www folder
  43.         type:"get",
  44.         contentType:"xml",
  45.         success: function(xml){
  46.             //todo:
  47.             //read nodes string
  48.             $(xml).find("string").each(function()
  49.             {
  50.                 arrRs[$(this).attr("name")]   = $(this).text();
  51.             });
  52.             //execute the function
  53.             successCallback(arrRs);
  54.         }
  55.     });
  56.    
  57. };
  58.  
  59. if(!window.plugins) {
  60.     window.plugins = {};
  61. }
  62.  
  63. if (!window.plugins.resources) {
  64.     window.plugins.resources = new LocalResources();
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement