Fossil SCM

Create a javascript function $(id) which is an alias for document.getElementById(id). Use the $(id) function everywhere that document.getElementById(id) was used.

drh 2012-07-19 21:44 trunk
Commit 97d651b85a74ba6cb56a7ad752c4dd2f076fee1c
+3 -7
--- src/info.c
+++ src/info.c
@@ -1388,15 +1388,11 @@
13881388
if( z[0]=='\n' ) z++;
13891389
}
13901390
if( n<iEnd ) cgi_printf("</div>");
13911391
@ </pre>
13921392
if( iStart ){
1393
- @ <script type="text/JavaScript">
1394
- @ /* <![CDATA[ */
1395
- @ document.getElementById('topln').scrollIntoView(true);
1396
- @ /* ]]> */
1397
- @ </script>
1393
+ @ <script>$('topln').scrollIntoView(true);</script>
13981394
}
13991395
}
14001396
14011397
14021398
/*
@@ -2008,11 +2004,11 @@
20082004
@ <tr><td align="right" valign="top"><b>Tags:</b></td>
20092005
@ <td valign="top">
20102006
@ <input type="checkbox" id="newtag" name="newtag"%s(zNewTagFlag) />
20112007
@ Add the following new tag name to this check-in:
20122008
@ <input type="text" style="width:15;" name="tagname" value="%h(zNewTag)"
2013
- @ onkeyup="document.getElementById('newtag').checked=!!this.value" />
2009
+ @ onkeyup="$('newtag').checked=!!this.value" />
20142010
db_prepare(&q,
20152011
"SELECT tag.tagid, tagname FROM tagxref, tag"
20162012
" WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid"
20172013
" ORDER BY CASE WHEN tagname GLOB 'sym-*' THEN substr(tagname,5)"
20182014
" ELSE tagname END /*sort*/",
@@ -2040,11 +2036,11 @@
20402036
@ <tr><td align="right" valign="top"><b>Branching:</b></td>
20412037
@ <td valign="top">
20422038
@ <input id="newbr" type="checkbox" name="newbr"%s(zNewBrFlag) />
20432039
@ Make this check-in the start of a new branch named:
20442040
@ <input type="text" style="width:15;" name="brname" value="%h(zNewBranch)"
2045
- @ onkeyup="document.getElementById('newbr').checked=!!this.value" />
2041
+ @ onkeyup="$('newbr').checked=!!this.value" />
20462042
@ </td></tr>
20472043
20482044
if( is_a_leaf(rid)
20492045
&& !db_exists("SELECT 1 FROM tagxref "
20502046
" WHERE tagid=%d AND rid=%d AND tagtype>0",
20512047
--- src/info.c
+++ src/info.c
@@ -1388,15 +1388,11 @@
1388 if( z[0]=='\n' ) z++;
1389 }
1390 if( n<iEnd ) cgi_printf("</div>");
1391 @ </pre>
1392 if( iStart ){
1393 @ <script type="text/JavaScript">
1394 @ /* <![CDATA[ */
1395 @ document.getElementById('topln').scrollIntoView(true);
1396 @ /* ]]> */
1397 @ </script>
1398 }
1399 }
1400
1401
1402 /*
@@ -2008,11 +2004,11 @@
2008 @ <tr><td align="right" valign="top"><b>Tags:</b></td>
2009 @ <td valign="top">
2010 @ <input type="checkbox" id="newtag" name="newtag"%s(zNewTagFlag) />
2011 @ Add the following new tag name to this check-in:
2012 @ <input type="text" style="width:15;" name="tagname" value="%h(zNewTag)"
2013 @ onkeyup="document.getElementById('newtag').checked=!!this.value" />
2014 db_prepare(&q,
2015 "SELECT tag.tagid, tagname FROM tagxref, tag"
2016 " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid"
2017 " ORDER BY CASE WHEN tagname GLOB 'sym-*' THEN substr(tagname,5)"
2018 " ELSE tagname END /*sort*/",
@@ -2040,11 +2036,11 @@
2040 @ <tr><td align="right" valign="top"><b>Branching:</b></td>
2041 @ <td valign="top">
2042 @ <input id="newbr" type="checkbox" name="newbr"%s(zNewBrFlag) />
2043 @ Make this check-in the start of a new branch named:
2044 @ <input type="text" style="width:15;" name="brname" value="%h(zNewBranch)"
2045 @ onkeyup="document.getElementById('newbr').checked=!!this.value" />
2046 @ </td></tr>
2047
2048 if( is_a_leaf(rid)
2049 && !db_exists("SELECT 1 FROM tagxref "
2050 " WHERE tagid=%d AND rid=%d AND tagtype>0",
2051
--- src/info.c
+++ src/info.c
@@ -1388,15 +1388,11 @@
1388 if( z[0]=='\n' ) z++;
1389 }
1390 if( n<iEnd ) cgi_printf("</div>");
1391 @ </pre>
1392 if( iStart ){
1393 @ <script>$('topln').scrollIntoView(true);</script>
 
 
 
 
1394 }
1395 }
1396
1397
1398 /*
@@ -2008,11 +2004,11 @@
2004 @ <tr><td align="right" valign="top"><b>Tags:</b></td>
2005 @ <td valign="top">
2006 @ <input type="checkbox" id="newtag" name="newtag"%s(zNewTagFlag) />
2007 @ Add the following new tag name to this check-in:
2008 @ <input type="text" style="width:15;" name="tagname" value="%h(zNewTag)"
2009 @ onkeyup="$('newtag').checked=!!this.value" />
2010 db_prepare(&q,
2011 "SELECT tag.tagid, tagname FROM tagxref, tag"
2012 " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid"
2013 " ORDER BY CASE WHEN tagname GLOB 'sym-*' THEN substr(tagname,5)"
2014 " ELSE tagname END /*sort*/",
@@ -2040,11 +2036,11 @@
2036 @ <tr><td align="right" valign="top"><b>Branching:</b></td>
2037 @ <td valign="top">
2038 @ <input id="newbr" type="checkbox" name="newbr"%s(zNewBrFlag) />
2039 @ Make this check-in the start of a new branch named:
2040 @ <input type="text" style="width:15;" name="brname" value="%h(zNewBranch)"
2041 @ onkeyup="$('newbr').checked=!!this.value" />
2042 @ </td></tr>
2043
2044 if( is_a_leaf(rid)
2045 && !db_exists("SELECT 1 FROM tagxref "
2046 " WHERE tagid=%d AND rid=%d AND tagtype>0",
2047
+2 -3
--- src/login.c
+++ src/login.c
@@ -594,11 +594,11 @@
594594
@ <td><input type="submit" name="in" value="Login"
595595
@ onClick="chngAction(this.form)" /></td>
596596
@ </tr>
597597
@ </table>
598598
@ <script type="text/JavaScript">
599
- @ document.getElementById('u').focus()
599
+ @ $('u').focus()
600600
@ function chngAction(form){
601601
if( g.sslNotAvailable==0
602602
&& memcmp(g.zBaseURL,"https:",6)!=0
603603
&& db_get_boolean("https-login",0)
604604
){
@@ -635,12 +635,11 @@
635635
@ <div class="captcha"><table class="captcha"><tr><td><pre>
636636
@ %s(zCaptcha)
637637
@ </pre></td></tr></table>
638638
if( bAutoCaptcha ) {
639639
@ <input type="button" value="Fill out captcha"
640
- @ onclick="document.getElementById('u').value='anonymous';
641
- @ document.getElementById('p').value='%s(zDecoded)';" />
640
+ @ onclick="$('u').value='anonymous'; $('p').value='%s(zDecoded)';" />
642641
}
643642
@ </div>
644643
free(zCaptcha);
645644
}
646645
if( g.zLogin ){
647646
--- src/login.c
+++ src/login.c
@@ -594,11 +594,11 @@
594 @ <td><input type="submit" name="in" value="Login"
595 @ onClick="chngAction(this.form)" /></td>
596 @ </tr>
597 @ </table>
598 @ <script type="text/JavaScript">
599 @ document.getElementById('u').focus()
600 @ function chngAction(form){
601 if( g.sslNotAvailable==0
602 && memcmp(g.zBaseURL,"https:",6)!=0
603 && db_get_boolean("https-login",0)
604 ){
@@ -635,12 +635,11 @@
635 @ <div class="captcha"><table class="captcha"><tr><td><pre>
636 @ %s(zCaptcha)
637 @ </pre></td></tr></table>
638 if( bAutoCaptcha ) {
639 @ <input type="button" value="Fill out captcha"
640 @ onclick="document.getElementById('u').value='anonymous';
641 @ document.getElementById('p').value='%s(zDecoded)';" />
642 }
643 @ </div>
644 free(zCaptcha);
645 }
646 if( g.zLogin ){
647
--- src/login.c
+++ src/login.c
@@ -594,11 +594,11 @@
594 @ <td><input type="submit" name="in" value="Login"
595 @ onClick="chngAction(this.form)" /></td>
596 @ </tr>
597 @ </table>
598 @ <script type="text/JavaScript">
599 @ $('u').focus()
600 @ function chngAction(form){
601 if( g.sslNotAvailable==0
602 && memcmp(g.zBaseURL,"https:",6)!=0
603 && db_get_boolean("https-login",0)
604 ){
@@ -635,12 +635,11 @@
635 @ <div class="captcha"><table class="captcha"><tr><td><pre>
636 @ %s(zCaptcha)
637 @ </pre></td></tr></table>
638 if( bAutoCaptcha ) {
639 @ <input type="button" value="Fill out captcha"
640 @ onclick="$('u').value='anonymous'; $('p').value='%s(zDecoded)';" />
 
641 }
642 @ </div>
643 free(zCaptcha);
644 }
645 if( g.zLogin ){
646
+7 -2
--- src/style.c
+++ src/style.c
@@ -124,11 +124,11 @@
124124
void style_resolve_href(void){
125125
int i;
126126
if( !g.perm.Hyperlink || !g.javascriptHyperlink || nHref==0 ) return;
127127
@ <script type="text/JavaScript">
128128
@ /* <![CDATA[ */
129
- @ function u(i,h){ document.getElementById(i).href=h; }
129
+ @ function u(i,h){$(i).href=h;}
130130
for(i=0; i<nHref; i++){
131131
@ u(%d(i+1),"%s(aHref[i])");
132132
}
133133
@ /* ]]> */
134134
@ </script>
@@ -174,11 +174,12 @@
174174
va_start(ap, zTitleFormat);
175175
zTitle = vmprintf(zTitleFormat, ap);
176176
va_end(ap);
177177
178178
cgi_destination(CGI_HEADER);
179
- cgi_printf("%s","<!DOCTYPE html>");
179
+
180
+ @ <!DOCTYPE html>
180181
181182
if( g.thTrace ) Th_Trace("BEGIN_HEADER<br />\n", -1);
182183
183184
/* Generate the header up through the main menu */
184185
Th_Store("project_name", db_get("project-name","Unnamed Fossil Project"));
@@ -200,10 +201,14 @@
200201
Th_Unstore("title"); /* Avoid collisions with ticket field names */
201202
cgi_destination(CGI_BODY);
202203
g.cgiOutput = 1;
203204
headerHasBeenGenerated = 1;
204205
sideboxUsed = 0;
206
+
207
+ /* Make the $(x) function available as an alias for
208
+ ** document.getElementById(x), since it seems like everybody does this */
209
+ @ <script>function $(x){return document.getElementById(x);}</script>
205210
}
206211
207212
/*
208213
** Append ad unit text if appropriate.
209214
*/
210215
--- src/style.c
+++ src/style.c
@@ -124,11 +124,11 @@
124 void style_resolve_href(void){
125 int i;
126 if( !g.perm.Hyperlink || !g.javascriptHyperlink || nHref==0 ) return;
127 @ <script type="text/JavaScript">
128 @ /* <![CDATA[ */
129 @ function u(i,h){ document.getElementById(i).href=h; }
130 for(i=0; i<nHref; i++){
131 @ u(%d(i+1),"%s(aHref[i])");
132 }
133 @ /* ]]> */
134 @ </script>
@@ -174,11 +174,12 @@
174 va_start(ap, zTitleFormat);
175 zTitle = vmprintf(zTitleFormat, ap);
176 va_end(ap);
177
178 cgi_destination(CGI_HEADER);
179 cgi_printf("%s","<!DOCTYPE html>");
 
180
181 if( g.thTrace ) Th_Trace("BEGIN_HEADER<br />\n", -1);
182
183 /* Generate the header up through the main menu */
184 Th_Store("project_name", db_get("project-name","Unnamed Fossil Project"));
@@ -200,10 +201,14 @@
200 Th_Unstore("title"); /* Avoid collisions with ticket field names */
201 cgi_destination(CGI_BODY);
202 g.cgiOutput = 1;
203 headerHasBeenGenerated = 1;
204 sideboxUsed = 0;
 
 
 
 
205 }
206
207 /*
208 ** Append ad unit text if appropriate.
209 */
210
--- src/style.c
+++ src/style.c
@@ -124,11 +124,11 @@
124 void style_resolve_href(void){
125 int i;
126 if( !g.perm.Hyperlink || !g.javascriptHyperlink || nHref==0 ) return;
127 @ <script type="text/JavaScript">
128 @ /* <![CDATA[ */
129 @ function u(i,h){$(i).href=h;}
130 for(i=0; i<nHref; i++){
131 @ u(%d(i+1),"%s(aHref[i])");
132 }
133 @ /* ]]> */
134 @ </script>
@@ -174,11 +174,12 @@
174 va_start(ap, zTitleFormat);
175 zTitle = vmprintf(zTitleFormat, ap);
176 va_end(ap);
177
178 cgi_destination(CGI_HEADER);
179
180 @ <!DOCTYPE html>
181
182 if( g.thTrace ) Th_Trace("BEGIN_HEADER<br />\n", -1);
183
184 /* Generate the header up through the main menu */
185 Th_Store("project_name", db_get("project-name","Unnamed Fossil Project"));
@@ -200,10 +201,14 @@
201 Th_Unstore("title"); /* Avoid collisions with ticket field names */
202 cgi_destination(CGI_BODY);
203 g.cgiOutput = 1;
204 headerHasBeenGenerated = 1;
205 sideboxUsed = 0;
206
207 /* Make the $(x) function available as an alias for
208 ** document.getElementById(x), since it seems like everybody does this */
209 @ <script>function $(x){return document.getElementById(x);}</script>
210 }
211
212 /*
213 ** Append ad unit text if appropriate.
214 */
215
+5 -5
--- src/timeline.c
+++ src/timeline.c
@@ -567,11 +567,11 @@
567567
if( cSep=='[' ) cgi_printf("[");
568568
cgi_printf("]}%s", pRow->pNext ? ",\n" : "];\n");
569569
}
570570
cgi_printf("var nrail = %d\n", pGraph->mxRail+1);
571571
graph_free(pGraph);
572
- @ var canvasDiv = document.getElementById("canvas");
572
+ @ var canvasDiv = $("canvas");
573573
#if 0
574574
@ var realCanvas = null;
575575
#endif
576576
@ function drawBox(color,x0,y0,x1,y1){
577577
@ var n = document.createElement("div");
@@ -587,11 +587,11 @@
587587
@ n.style.height = h+"px";
588588
@ n.style.backgroundColor = color;
589589
@ canvasDiv.appendChild(n);
590590
@ }
591591
@ function absoluteY(id){
592
- @ var obj = document.getElementById(id);
592
+ @ var obj = $(id);
593593
@ if( !obj ) return;
594594
@ var top = 0;
595595
@ if( obj.offsetParent ){
596596
@ do{
597597
@ top += obj.offsetTop;
@@ -598,11 +598,11 @@
598598
@ }while( obj = obj.offsetParent );
599599
@ }
600600
@ return top;
601601
@ }
602602
@ function absoluteX(id){
603
- @ var obj = document.getElementById(id);
603
+ @ var obj = $(id);
604604
@ if( !obj ) return;
605605
@ var left = 0;
606606
@ if( obj.offsetParent ){
607607
@ do{
608608
@ left += obj.offsetLeft;
@@ -687,11 +687,11 @@
687687
@ drawThinArrow(y0,mx,p.x-5);
688688
@ }
689689
@ }
690690
@ }
691691
@ function renderGraph(){
692
- @ var canvasDiv = document.getElementById("canvas");
692
+ @ var canvasDiv = $("canvas");
693693
@ while( canvasDiv.hasChildNodes() ){
694694
@ canvasDiv.removeChild(canvasDiv.firstChild);
695695
@ }
696696
@ var canvasY = absoluteY("timelineTable");
697697
@ var left = absoluteX("m"+rowinfo[0].id) - absoluteX("canvas") + 15;
@@ -704,11 +704,11 @@
704704
#if 0
705705
@ if( btm<32768 ){
706706
@ canvasDiv.innerHTML = '<canvas id="timeline-canvas" '+
707707
@ 'style="position:absolute;left:'+(left-5)+'px;"' +
708708
@ ' width="'+width+'" height="'+btm+'"><'+'/canvas>';
709
- @ realCanvas = document.getElementById('timeline-canvas');
709
+ @ realCanvas = $('timeline-canvas');
710710
@ }else{
711711
@ realCanvas = 0;
712712
@ }
713713
@ var context;
714714
@ if( realCanvas && realCanvas.getContext
715715
--- src/timeline.c
+++ src/timeline.c
@@ -567,11 +567,11 @@
567 if( cSep=='[' ) cgi_printf("[");
568 cgi_printf("]}%s", pRow->pNext ? ",\n" : "];\n");
569 }
570 cgi_printf("var nrail = %d\n", pGraph->mxRail+1);
571 graph_free(pGraph);
572 @ var canvasDiv = document.getElementById("canvas");
573 #if 0
574 @ var realCanvas = null;
575 #endif
576 @ function drawBox(color,x0,y0,x1,y1){
577 @ var n = document.createElement("div");
@@ -587,11 +587,11 @@
587 @ n.style.height = h+"px";
588 @ n.style.backgroundColor = color;
589 @ canvasDiv.appendChild(n);
590 @ }
591 @ function absoluteY(id){
592 @ var obj = document.getElementById(id);
593 @ if( !obj ) return;
594 @ var top = 0;
595 @ if( obj.offsetParent ){
596 @ do{
597 @ top += obj.offsetTop;
@@ -598,11 +598,11 @@
598 @ }while( obj = obj.offsetParent );
599 @ }
600 @ return top;
601 @ }
602 @ function absoluteX(id){
603 @ var obj = document.getElementById(id);
604 @ if( !obj ) return;
605 @ var left = 0;
606 @ if( obj.offsetParent ){
607 @ do{
608 @ left += obj.offsetLeft;
@@ -687,11 +687,11 @@
687 @ drawThinArrow(y0,mx,p.x-5);
688 @ }
689 @ }
690 @ }
691 @ function renderGraph(){
692 @ var canvasDiv = document.getElementById("canvas");
693 @ while( canvasDiv.hasChildNodes() ){
694 @ canvasDiv.removeChild(canvasDiv.firstChild);
695 @ }
696 @ var canvasY = absoluteY("timelineTable");
697 @ var left = absoluteX("m"+rowinfo[0].id) - absoluteX("canvas") + 15;
@@ -704,11 +704,11 @@
704 #if 0
705 @ if( btm<32768 ){
706 @ canvasDiv.innerHTML = '<canvas id="timeline-canvas" '+
707 @ 'style="position:absolute;left:'+(left-5)+'px;"' +
708 @ ' width="'+width+'" height="'+btm+'"><'+'/canvas>';
709 @ realCanvas = document.getElementById('timeline-canvas');
710 @ }else{
711 @ realCanvas = 0;
712 @ }
713 @ var context;
714 @ if( realCanvas && realCanvas.getContext
715
--- src/timeline.c
+++ src/timeline.c
@@ -567,11 +567,11 @@
567 if( cSep=='[' ) cgi_printf("[");
568 cgi_printf("]}%s", pRow->pNext ? ",\n" : "];\n");
569 }
570 cgi_printf("var nrail = %d\n", pGraph->mxRail+1);
571 graph_free(pGraph);
572 @ var canvasDiv = $("canvas");
573 #if 0
574 @ var realCanvas = null;
575 #endif
576 @ function drawBox(color,x0,y0,x1,y1){
577 @ var n = document.createElement("div");
@@ -587,11 +587,11 @@
587 @ n.style.height = h+"px";
588 @ n.style.backgroundColor = color;
589 @ canvasDiv.appendChild(n);
590 @ }
591 @ function absoluteY(id){
592 @ var obj = $(id);
593 @ if( !obj ) return;
594 @ var top = 0;
595 @ if( obj.offsetParent ){
596 @ do{
597 @ top += obj.offsetTop;
@@ -598,11 +598,11 @@
598 @ }while( obj = obj.offsetParent );
599 @ }
600 @ return top;
601 @ }
602 @ function absoluteX(id){
603 @ var obj = $(id);
604 @ if( !obj ) return;
605 @ var left = 0;
606 @ if( obj.offsetParent ){
607 @ do{
608 @ left += obj.offsetLeft;
@@ -687,11 +687,11 @@
687 @ drawThinArrow(y0,mx,p.x-5);
688 @ }
689 @ }
690 @ }
691 @ function renderGraph(){
692 @ var canvasDiv = $("canvas");
693 @ while( canvasDiv.hasChildNodes() ){
694 @ canvasDiv.removeChild(canvasDiv.firstChild);
695 @ }
696 @ var canvasY = absoluteY("timelineTable");
697 @ var left = absoluteX("m"+rowinfo[0].id) - absoluteX("canvas") + 15;
@@ -704,11 +704,11 @@
704 #if 0
705 @ if( btm<32768 ){
706 @ canvasDiv.innerHTML = '<canvas id="timeline-canvas" '+
707 @ 'style="position:absolute;left:'+(left-5)+'px;"' +
708 @ ' width="'+width+'" height="'+btm+'"><'+'/canvas>';
709 @ realCanvas = $('timeline-canvas');
710 @ }else{
711 @ realCanvas = 0;
712 @ }
713 @ var context;
714 @ if( realCanvas && realCanvas.getContext
715

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button