Advertisement
Guest User

hpbrantley

a guest
Feb 16th, 2010
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. YUI({
  2. modules: {
  3. 'gallery-accordion': {
  4. fullpath: 'http://yui.yahooapis.com/gallery-2009.12.08-22/build/gallery-accordion/gallery-accordion-min.js',
  5. requires: ['event','anim-easing','widget','widget-stdmod','json-parse'],
  6. optional: ['dd-constrain','dd-proxy','dd-drop'],
  7. supersedes: []
  8. }
  9. }
  10. }).use('gallery-accordion','io','json', function(Y) {
  11. var accordion = new Y.Accordion( {
  12. contentBox: "#acc1",
  13. useAnimation: false,
  14. collapseOthersOnExpand: true
  15. });
  16. accordion.render();
  17. accordion.on("complete", accordionInit());
  18. accordion.on('itemAdded', function( e ) { Y.log( "itemAdded" ); } );
  19.  
  20. accordion.on( "itemExpanded", Y.bind(function( attrs ) {
  21. //accordion.on( "beforeItemExpand", Y.bind(function( attrs ) {
  22. var dbID=attrs.item.get( "dbID" );
  23. var bodyContent=attrs.item.get( "bodyContent" )._nodes[0].textContent;
  24. Y.log( 'dbID ' + dbID + ' expanded');
  25. if( typeof bodyContent == "undefined" || bodyContent.length == 1) {
  26. //if no content, query db for it
  27. Y.log( 'dbID ' + dbID + ' has no content, querying for content' );
  28. Y.on('io:complete', itemClickCallback, this, [ attrs ]);
  29. var reply = Y.io("controller.php?task=query&target=schedule&id=" + dbID);
  30. }
  31. }, this));
  32.  
  33. accordion.on( "itemCollapsed", Y.bind(function( attrs ) {
  34. var dbID=attrs.item.get( "dbID" );
  35. Y.log( 'dbID ' + dbID + ' collapsed');
  36. }, this));
  37.  
  38. function accordionInit() {
  39. Y.log('accordion loaded')
  40. Y.on('io:complete', accordionInitCallback, accordion);
  41. var request = Y.io( "controller.php?task=query&target=schedule&id=" );
  42. }
  43.  
  44. function accordionInitCallback (id, o, args) {
  45. var id = id; // Transaction ID.
  46. var data = Y.JSON.parse(o.responseText);
  47. //var args = args[1]; // 'ipsum'.
  48. for(var i=0; i < data.length; i++) {
  49. var item = new Y.AccordionItem( {
  50. label: data[i].ACCORDION_TITLE, // + " (" + data[i].TEST_ID + ")"
  51. expanded: false,
  52. contentBox: "accordionItemContentBox"+ data[i].ACCORDION_ID,
  53. contentHeight: { method: "auto" }
  54. // if we want to populate the accordion on load,
  55. // uncomment next line
  56. //,bodyContent: "<div>" + data[i].ACCORDION_BODY + "</div>"
  57. } );
  58. item.set( "dbID", data[i].ACCORDION_ID );
  59. if(!accordion.addItem( item )) { Y.log( 'addItem failed' ); } ;
  60. }
  61. Y.detach('io:complete', accordionInitCallback);
  62. };
  63.  
  64. function itemClickCallback ( id, o, args ) {
  65. // populate the bodyContent from the item expanding. only called if
  66. // there is no content.
  67. Y.log("itemClickCallback called");
  68. var response = Y.JSON.parse(o.responseText);
  69. var item = args[0].item;
  70. item.set( "bodyContent", "<div>"+ response[0].ACCORDION_BODY + "</div>" );
  71. item.set( "expanded", false ); // temporary fix? close it, then reopen it.
  72. item.set( "expanded", true );
  73. Y.log( "bodyContent loaded" );
  74. Y.detach('io:complete', itemClickCallback);
  75. }
  76. });
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement