home *** CD-ROM | disk | FTP | other *** search
/ 202.64.131.39 / 202.64.131.39.tar / 202.64.131.39 / coco-ichibanya / coco-ichibanya03-04-14-2014_htm_files / datamap.js < prev    next >
Text File  |  2014-04-14  |  2KB  |  55 lines

  1. // this function scans the page for divs containing the class xwidget
  2. // and triggers the constructor for the widget type
  3. // the widget type is derived from the id (e.g. imageSlider_001)
  4. function xaraSwidgets_processPage()
  5. {
  6.     $('.xwidget').each(function() {
  7.  
  8.         // the id of the div on the page
  9.         var componentID = $(this).attr('id');
  10.         
  11.         // the component 'type' - used to trigger the correct component constructor
  12.         var componentType = componentID.replace(/_\d+$/gi, "");
  13.     
  14.         // the component data - accessed using the id
  15.         var componentData = window['local_' + componentID + '_data'];
  16.         
  17.         // do we have any remotely injected data? in which case use that
  18.         if(window['remote_' + componentID + '_data'])
  19.         {
  20.             componentData = window['remote_' + componentID + '_data'];
  21.         }
  22.         
  23.         // this actually calls the constructor for the component based on the component type
  24.         // this has already been included in the page by the componentID_config.js include
  25.         
  26.         window['xaraSwidgets_' + componentType + 'Constructor'](componentID, componentData);
  27.         
  28.     });
  29. }
  30.  
  31. // this will compile the source code with the properties provided
  32. function xaraSwidgets_compileTemplate(templateCode, templateVariables)
  33. {
  34.     var html = '' + templateCode;
  35.                     
  36.     for(var prop in templateVariables)
  37.     {
  38.         html = html.replace(RegExp('{' + prop + '}', 'g'), templateVariables[prop]);
  39.     }
  40.                     
  41.     return html;
  42. }
  43.  
  44. function xaraSwidgets_tohtml(str)
  45. {
  46.     return $("<p>").text(str).html().replace(RegExp("\n", "g"), "<br/>");
  47. }
  48.  
  49. // this is the entry point!
  50. $(function() {
  51.     
  52.     xaraSwidgets_processPage();
  53.     
  54. });
  55.