// This is a roxen module. // by Azundris // inspired by roxen foldlist. constant cvs_version = "$Id: azoufold.pike,v 2.00 2002/02/27 06:47:43 azundris Exp $"; constant thread_safe=1; #include inherit "module"; inherit "roxenlib"; inherit "state"; constant module_type = MODULE_PARSER; constant module_name = "Azundris' folding lists"; constant module_doc = "Provides the <foldlist> tag, which is used to " "build folding lists. The folding lists work like <dl> lists " "where each item can be folded or unfolded."; TAGDOCUMENTATION #ifdef manual constant tagdoc=([ "foldlist":({#" This tag is used to build folding lists, that are like <dl> lists, but where each element can be unfolded. The tags used to build the lists elements are ft and fd. Will make all the elements in the list unfolded by default. ", (["ft":({#" This tag is used within the foldlist tag. The contents of this container, that is not within an fd, tag will be visible both when the element is folded and unfolded. Will make this element folded by default. Overrides an unfolded attribute set in the foldlist tag. Will make this element unfolded by default. Picture to flag a folded <ft>. Picture to flag an unfolded <ft>. Background picture for the text. Background picture for the folded/unfolded icon. ", (["fd":#" The contents of this container will only be visible when the element it is written in is unfolded."]) })]) })]); #endif string encode_url(array states, object state, RequestID id){ string value=""; foreach(states,int tmp) { if(tmp>-1) value+=(string)tmp; else return id->not_query+"?cmd=fold&v1="+ state->uri_encode(value); } return id->not_query+"?cmd=fold&v1="+ state->uri_encode(value); } //It seems like the fold/unfold images are mixed up. private string tag_ft(string tag, mapping m, string cont, RequestID id, object state, mapping fl) { int index=fl->cnt++; int co=0; array states=copy_value(fl->states); if(fl->section&&strlen(fl->section)) { string s=(cont/">")[1]; s=(s/"<")[0]; if(fl->section!=s) return ""; co=strlen((lower_case(cont)/"unfolded && states[index]==-1) || ((indextxt=""; fl->states[index]=1; id->misc->foldlist_id=fl->inh+(fl->cnt>10?":":"")+(string)fl->cnt; states[index]=0; if(co) { cont=cont[co..]; parse_html(cont,([]),(["fd": lambda(string tag, mapping m, string cont) { fl->txt+=parse_rxml(cont,id); return ""; } ])); return ""+fl->txt+"\n"; } return "textbg+"\">"+ (strlen(fl->textbg)?"\"\"textbg+"\">":"")+ "
"+ parse_html(cont,([]),(["fd": lambda(string tag, mapping m, string cont) { fl->txt+=parse_rxml(cont,id); return ""; } ]))+ ""+ "iconbg+"\" "+ "valign=\"top\" align=\"right\" rowspan=\"2\">"+ (strlen(fl->fsrc)? "unfoldedsrc||fl->ufsrc)+ "\" border=\"0\" alt=\"-\" />":"")+""+ "textbg+"\">  "+ "textbg+"\">"+ ""+fl->txt+""; } if(indexstates[index]=0; states[index]=1; } return "textbg+"\">"+ (strlen(fl->textbg)?"\"\"textbg+"\">":"")+ "
"+ parse_html(cont,([]),(["fd":""]))+ "iconbg+"\">"+ (strlen(fl->fsrc)? "foldedsrc||fl->fsrc)+ "\" border=\"0\" alt=\"+\" />":"")+""; } string container_foldlist(string tag, mapping m, string c, RequestID id) { array states; int fds=sizeof(lower_case(c)/"misc->foldlist_id) id->misc->foldlist_id=""; //Make an initial guess of what should be folded and what should not. if(m->unfolded) states=allocate(fds,1); //All unfolded else if(m->folded) states=allocate(fds,0); //All folded else states=allocate(fds,-1); //All unknown //Register ourselfs as state consumers and incorporate our initial state. string fl_name = (m->name || "fl")+fds+(id->misc->foldlist_id!=""?":"+id->misc->foldlist_id:""); object state=Page_state(id); string state_id = state->register_consumer(fl_name, id); if(!m->fixed) { if(id->misc->session_variables->fold) id->variables->state=id->misc->session_variables->fold; if(id->variables->state && !state->uri_decode(id->variables->state)) RXML.run_error("Error in state."); } //Get our real state array new=(state->get(state_id)||"")/""; for(int i=0; imisc->foldlist_id, "txt":"", "textbg":m->textbg||"", "iconbg":m->iconbg||"", "section":m->section||"", "fsrc":m->foldedsrc||"/internal-roxen-unfold", "ufsrc":m->unfoldedsrc||"/internal-roxen-fold"]); //Do the real thing. c=parse_html(c,([]),(["ft":tag_ft]),id,state,fl); id->misc->foldlist_id=fl->inh; return (id->misc->debug?"":"")+ "\n\n\n"+ c+ "\n\n\n"; } // ends