/[drupal]/contributions/modules/carbon/carbon_view.js
ViewVC logotype

Diff of /contributions/modules/carbon/carbon_view.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1 by johnackers, Tue Dec 30 21:32:59 2008 UTC revision 1.2 by johnackers, Sat Jan 10 15:46:14 2009 UTC
# Line 1  Line 1 
1  /* $Id: carbon_view.js,v 1.1 2007/05/01 22:28:55 johnackers Exp $  /* $Id: carbon_view.js,v 1.1 2008/12/30 21:32:59 johnackers Exp $
2   *   *
3   *   *
4   * Javascript to handle carbon_view page   * Javascript to handle carbon_view page
# Line 7  Line 7 
7   * and JQuery built requests for data.   * and JQuery built requests for data.
8   */   */
9    
10    /**
11     * Initialize all the elements that can be loaded using Ajax/JSON
12     * Think you can only have one of these scripts per document.
13     */
14    
15  if (Drupal.jsEnabled){  if (Drupal.jsEnabled){
16    $(document).ready(function() {    $(document).ready(function() {
17          var num = 0 ;          var num = 0 ;
18  //      $('fieldset > A.loadOnDemand').each(function () {          $('A.loadOnDemand').each(function () {
19          $('A.loadOnDemand').each(function () {        $(this).click(function() { return carbonRequestDataLoad(this.id, this.href + "&datatype=json"); }); // must return to suppress link click
  //     logObject(this);  
       $(this).click(function() { return panelClick(this.id, this.href + "&datatype=json"); }); // must return to suppress link click  
20        num++ ;        num++ ;
21      })  // A tag      })  // A tag
22      log(num + " elements initialised by carbon_view.js");      log(num + " elements initialised by carbon_view.js");
23    });  // ready    });  // ready
24  }  }
25    
26    /**
27     * Respond to a link clicked on by a user
28     * @param id  unique id for each panel on the page
29     * @param url
30     * @return
31     */
32    
33  function panelClick(id, url)  function carbonRequestDataLoad(id, url)
34  {  {
35    log(id + ": panelClick " + url);  //  log(id + ": carbonRequestDataLoad " + url);
36    var div = document.getElementById(id);    var div = document.getElementById(id);
37    
38    var container = div.parentNode;    // navigate up to the fieldset
39    
40      var container = $(div).parents('fieldset')[0];
41    
42    if (isNaN(div.loaded))    if (isNaN(div.loaded))
43      div.loaded = 0 ;      div.loaded = 0 ;
# Line 37  function panelClick(id, url) Line 47  function panelClick(id, url)
47          body = document.createElement('DIV');          body = document.createElement('DIV');
48          body.className = "bodyLoadedOnDemand" ;          body.className = "bodyLoadedOnDemand" ;
49          container.appendChild(body);          container.appendChild(body);
50      body.innerHTML = "loading.. " + url ;      body.innerHTML = "<a href=\""+ url + "\">loading...</a>" ;
51          log (id + ": fetching data via getJSON:" + url);          log (id + ": using getJSON to load:" + url);
52          jQuery.getJSON(url, { datatype: "json"} , function(msg) { panelFill(id, url, body, msg); }) ;          jQuery.getJSON(url, { datatype: "json"} , function(msg) { carbonDataLoad(id, url, body, msg); }) ;
53    }    }
54    else    else
55    {    {
# Line 53  function panelClick(id, url) Line 63  function panelClick(id, url)
63    return false ;    return false ;
64  }  }
65    
66    /**
67     * Respond to a callback from the browser to receive data from the host
68     *
69     * @param id    unique id for each panel on the page
70     * @param url
71     * @param body
72     * @param msg   replaace HTML
73     * @return
74     */
75    
76    
77  function panelFill(id, url, body, msg)  function carbonDataLoad(id, url, body, msg)
78  {  {
   log (id + ": processing response from:" + url);  
79    div = document.getElementById(id);    div = document.getElementById(id);
80    div.loaded++ ;    div.loaded++ ;
81    body.innerHTML = msg ;    body.innerHTML = msg ;
82      log (id + ": loaded " + url);
83  }  }
84    
85    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.3