Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- YUI({
- modules: {
- 'gallery-accordion': {
- fullpath: 'http://yui.yahooapis.com/gallery-2009.12.08-22/build/gallery-accordion/gallery-accordion-min.js',
- requires: ['event','anim-easing','widget','widget-stdmod','json-parse'],
- optional: ['dd-constrain','dd-proxy','dd-drop'],
- supersedes: []
- }
- }
- }).use('gallery-accordion','io','json', function(Y) {
- var accordion = new Y.Accordion( {
- contentBox: "#acc1",
- useAnimation: false,
- collapseOthersOnExpand: true
- });
- accordion.render();
- accordion.on("complete", accordionInit());
- accordion.on('itemAdded', function( e ) { Y.log( "itemAdded" ); } );
- accordion.on( "itemExpanded", Y.bind(function( attrs ) {
- //accordion.on( "beforeItemExpand", Y.bind(function( attrs ) {
- var dbID=attrs.item.get( "dbID" );
- var bodyContent=attrs.item.get( "bodyContent" )._nodes[0].textContent;
- Y.log( 'dbID ' + dbID + ' expanded');
- if( typeof bodyContent == "undefined" || bodyContent.length == 1) {
- //if no content, query db for it
- Y.log( 'dbID ' + dbID + ' has no content, querying for content' );
- Y.on('io:complete', itemClickCallback, this, [ attrs ]);
- var reply = Y.io("controller.php?task=query&target=schedule&id=" + dbID);
- }
- }, this));
- accordion.on( "itemCollapsed", Y.bind(function( attrs ) {
- var dbID=attrs.item.get( "dbID" );
- Y.log( 'dbID ' + dbID + ' collapsed');
- }, this));
- function accordionInit() {
- Y.log('accordion loaded')
- Y.on('io:complete', accordionInitCallback, accordion);
- var request = Y.io( "controller.php?task=query&target=schedule&id=" );
- }
- function accordionInitCallback (id, o, args) {
- var id = id; // Transaction ID.
- var data = Y.JSON.parse(o.responseText);
- //var args = args[1]; // 'ipsum'.
- for(var i=0; i < data.length; i++) {
- var item = new Y.AccordionItem( {
- label: data[i].ACCORDION_TITLE, // + " (" + data[i].TEST_ID + ")"
- expanded: false,
- contentBox: "accordionItemContentBox"+ data[i].ACCORDION_ID,
- contentHeight: { method: "auto" }
- // if we want to populate the accordion on load,
- // uncomment next line
- //,bodyContent: "<div>" + data[i].ACCORDION_BODY + "</div>"
- } );
- item.set( "dbID", data[i].ACCORDION_ID );
- if(!accordion.addItem( item )) { Y.log( 'addItem failed' ); } ;
- }
- Y.detach('io:complete', accordionInitCallback);
- };
- function itemClickCallback ( id, o, args ) {
- // populate the bodyContent from the item expanding. only called if
- // there is no content.
- Y.log("itemClickCallback called");
- var response = Y.JSON.parse(o.responseText);
- var item = args[0].item;
- item.set( "bodyContent", "<div>"+ response[0].ACCORDION_BODY + "</div>" );
- item.set( "expanded", false ); // temporary fix? close it, then reopen it.
- item.set( "expanded", true );
- Y.log( "bodyContent loaded" );
- Y.detach('io:complete', itemClickCallback);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement