mothra: support fragment urls

This commit is contained in:
cinap_lenrek 2011-10-13 13:49:29 +02:00
parent e4048c1380
commit c92ddf3fb5
2 changed files with 33 additions and 15 deletions

View file

@ -481,14 +481,29 @@ char *genwww(Panel *, int index){
return buf;
}
void scrollto(char *tag){
Rtext *tp;
Action *ap;
if(current == nil || text == nil)
return;
if(tag && tag[0]){
for(tp=current->text;tp;tp=tp->next){
ap=tp->user;
if(ap && ap->name && strcmp(ap->name, tag)==0){
current->yoffs=tp->topy;
break;
}
}
}
plsetpostextview(text, current->yoffs);
flushimage(display, 1);
}
/*
* selected text should be a url.
* get the document, scroll to the given tag
*/
void setcurrent(int index, char *tag){
Www *new;
Rtext *tp;
Action *ap;
int i;
new=www(index);
if(new==current && (tag==0 || tag[0]==0)) return;
@ -500,18 +515,8 @@ void setcurrent(int index, char *tag){
plinitlabel(cururl, PACKE|EXPAND, current->url->fullname);
if(defdisplay) pldraw(cururl, screen);
plinittextview(text, PACKE|EXPAND, Pt(0, 0), current->text, dolink);
if(tag && tag[0]){
for(tp=current->text;tp;tp=tp->next){
ap=tp->user;
if(ap && ap->name && strcmp(ap->name, tag)==0){
current->yoffs=tp->topy;
break;
}
}
}
plsetpostextview(text, current->yoffs);
scrollto(tag);
donecurs();
flushimage(display, 1);
}
char *arg(char *s){
do ++s; while(*s==' ' || *s=='\t');
@ -694,7 +699,12 @@ void docmd(Panel *p, char *s){
}
void hiturl(int buttons, char *url, int map){
switch(buttons){
case 1: geturl(url, GET, 0, 0, map); break;
case 1:
if(*url == '#')
scrollto(url+1);
else
geturl(url, GET, 0, 0, map);
break;
case 2: selurl(url); break;
case 4: message("Button 3 hit on url can't happen!"); break;
}

View file

@ -628,6 +628,14 @@ void plrdhtml(char *name, int fd, Www *dst){
pl_pushstate(&g, g.tag);
break;
}
if(str=pl_getattr(g.attr, "id")){
char swap[NNAME];
strncpy(swap, g.state->name, sizeof(swap));
strncpy(g.state->name, str, sizeof(g.state->name));
pl_htmloutput(&g, 0, "", 0);
strncpy(g.state->name, swap, sizeof(g.state->name));
}
switch(g.tag){
default:
htmlerror(g.name, g.lineno,