Fossil

Check-in [20362c85]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Enable side by side editing and preview. While automatic updating of the preview 'pane'. Tested with Chrome and Firefox under Linux. Only Chrome works.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | side-by-side-edit
Files: files | file ages | folders
SHA1:20362c85a832af48310cd7edd0a5b3af9c87a834
User & Date: renez 2012-04-29 05:05:33
Context
2012-04-29
05:12
Put back the rows='%d(n)". Although an other option is, after the page has loaded, to change the offsetHeight of the text area to the height of the previewdiv. check-in: 55e7e245 user: renez tags: side-by-side-edit
05:05
Enable side by side editing and preview. While automatic updating of the preview 'pane'. Tested with Chrome and Firefox under Linux. Only Chrome works. check-in: 20362c85 user: renez tags: side-by-side-edit
04:54
Create new branch named "side-by-side-edit" check-in: 68a8a7e9 user: renez tags: side-by-side-edit
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/wiki.c.

256
257
258
259
260
261
262

263
264
265
266
267
268
269
...
334
335
336
337
338
339
340









341
342
343
344
345
346
347

348
349
350
351
352
353










354
355
356


357
358
359

360

361
362


363











































































































364
365
366
























367
368
369
370
371
372
373
  int rid = 0;
  int isSandbox;
  Blob wiki;
  Manifest *pWiki = 0;
  const char *zPageName;
  char *zHtmlPageName;
  int n;

  const char *z;
  char *zBody = (char*)P("w");

  if( zBody ){
    zBody = mprintf("%s", zBody);
  }
  login_check_credentials();
................................................................................
    return;
  }
  if( zBody==0 ){
    zBody = mprintf("<i>Empty Page</i>");
  }
  zHtmlPageName = mprintf("Edit: %s", zPageName);
  style_header(zHtmlPageName);









  if( P("preview")!=0 ){
    blob_zero(&wiki);
    blob_append(&wiki, zBody, -1);
    @ Preview:<hr />
    wiki_convert(&wiki, 0, 0);
    @ <hr />
    blob_reset(&wiki);

  }
  for(n=2, z=zBody; z[0]; z++){
    if( z[0]=='\n' ) n++;
  }
  if( n<20 ) n = 20;
  if( n>40 ) n = 40;










  @ <form method="post" action="%s(g.zTop)/wikiedit"><div>
  login_insert_csrf_secret();
  @ <input type="hidden" name="name" value="%h(zPageName)" />


  @ <textarea name="w" class="wikiedit" cols="80" 
  @  rows="%d(n)" wrap="virtual">%h(zBody)</textarea>
  @ <br />

  @ <input type="submit" name="preview" value="Preview Your Changes" />

  @ <input type="submit" name="submit" value="Apply These Changes" />
  @ <input type="submit" name="cancel" value="Cancel" />


  @ </div></form>











































































































  manifest_destroy(pWiki);
  style_footer();
}

























/*
** WEBPAGE: wikinew
** URL /wikinew
**
** Prompt the user to enter the name of a new wiki page.  Then redirect
** to the wikiedit screen for that new page.







>







 







>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
>






>
>
>
>
>
>
>
>
>
>
|


>
>
|
|

>
|
>


>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
...
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
  int rid = 0;
  int isSandbox;
  Blob wiki;
  Manifest *pWiki = 0;
  const char *zPageName;
  char *zHtmlPageName;
  int n;
  int ss;
  const char *z;
  char *zBody = (char*)P("w");

  if( zBody ){
    zBody = mprintf("%s", zBody);
  }
  login_check_credentials();
................................................................................
    return;
  }
  if( zBody==0 ){
    zBody = mprintf("<i>Empty Page</i>");
  }
  zHtmlPageName = mprintf("Edit: %s", zPageName);
  style_header(zHtmlPageName);
  ss = 0;
  if(P("ss")) ss = atoi(P("ss"));
  if( P("ssb")!=0 ){
      ss= ss ? 0 : 1;
  }
  if(ss){
    blob_zero(&wiki);
    blob_append(&wiki, zBody, -1);
  } else {
    if( P("preview")!=0 ){
      blob_zero(&wiki);
      blob_append(&wiki, zBody, -1);
      @ Preview:<hr />
      wiki_convert(&wiki, 0, 0);
      @ <hr />
      blob_reset(&wiki);
    }
  }
  for(n=2, z=zBody; z[0]; z++){
    if( z[0]=='\n' ) n++;
  }
  if( n<20 ) n = 20;
  if( n>40 ) n = 40;

  if(ss){
    @ <div id="twocolumns" style="width: 100%%;overflow:hidden">
    @ <div id="colright" style="display:block;float:right;width:50%%;">
    @ <div><h3>Preview</h3></div><div id="previewdiv">
    wiki_convert(&wiki, 0, 0);
    blob_reset(&wiki);
    @ </div></div>
    @ <div id="colleft" style="width:50%%;">
  }
  @ <form method="POST" action="%s(g.zTop)/wikiedit">
  login_insert_csrf_secret();
  @ <input type="hidden" name="name" value="%h(zPageName)" />
  @ <div>  <input type="submit" id="ssb" name="ssb" value="Toggle Side-by-side" />
  @ </div><input type="hidden" name="ss" value="%d(ss)" />
  @ <textarea id="w" name="w" class="wikiedit" cols="70" rows="40"
  @  >%h(zBody)</textarea>
  @ <br />
  if(!ss){
    @ <input type="submit" name="preview" value="Preview Your Changes" />
  }
  @ <input type="submit" name="submit" value="Apply These Changes" />
  @ <input type="submit" name="cancel" value="Cancel" />
  @ </form>
  if(ss){
    @ </div>
    @ <script type='text/javascript'>
    @ function ajax(u,a,cb,errcb){
    @   var _url = u;
    @   var _method ='POST';
    @   var _async = a;
    @   var _userCallback = cb ;
    @   var _defError = function(s,t){ alert('Ajax err('+s+') : '+t);} ;
    @   var _errorCallback = errcb === undefined ? _defError : errcb;
    @ 
    @   var _starting; 
    @   var _request = false; 
    @   var _debug = false; 
    @   var _busy = function(){
    @                 return (0 < _request.readyState && 4 > _request.readyState);
    @               } 
    @   
    @  if (window.XMLHttpRequest){ // Non-IE browsers
    @     _request = new XMLHttpRequest();
    @    } else if (window.ActiveXObject) { // IE
    @     try {
    @       _request = new ActiveXObject("Msxml2.XMLHTTP");
    @     } catch(e) {
    @       try {
    @         _request = new ActiveXObject("Microsoft.XMLHTTP");
    @       } catch(E) {
    @         _request = false;
    @       }
    @     }
    @   } else {
    @     _request = false;
    @     _errrorCallback(-1,'Ajax not available!');
    @   }
    @   var _callback =function(){
    @     if(4 == _request.readyState){
    @       if(200 == _request.status) {
    @         if(_debug){
    @           var _ending = new Date();
    @           var sec = (_ending.getTime() - _starting.getTime())/1000;
    @           alert(sec+" seconds. Callback with text\n "+_request.responseText);
    @         }
    @         _userCallback(_request.responseText,_request.responseXML);
    @       } else {
    @         _errorCallback(_request.status,_request.status);
    @       }
    @     }
    @   }
    @   this.abort = function(){ if(_busy()) {_request.abort(); } }
    @   this.setDebug = function(onOff){ _debug = onOff;} 
    @   this.setMethod = function(onOff){ _method = onOff ? 'POST' : 'GET' ; }
    @   this.setUrl = function(u){ _url = u; }
    @   this.setAsync = function(onOff){ _async = onOff; }
    @   this.send = function(data){
    @     if(_debug) alert("in send function\nurl: "+_url
    @           +"\nmethode "+_method
    @           +"\nAsync "+_async
    @           //+"\ndata "+data
    @         );
    @     if(_busy()){
    @       if(_debug) alert('call in progress');
    @       return 1;
    @     }
    @     try {
    @       _starting = new Date();
    @       _request.open(_method,_url,_async)
    @       if(_async)
    @         _request.onreadystatechange = _callback;
    @       _request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    @       _request.send(data);
    @       if(!_async){
    @         _callback();
    @         return _request.status;
    @       }
    @     } catch (e) {
    @       _request.abort();
    @     }
    @   }
    @ }
    @ x = new ajax("%s(g.zTop)/wikipreview",true,cb)
    @ //x.setDebug(true)
    @ 
    @ var sto  = 10000
    @ window.ta = document.getElementById('w')
    @ window.ta.onkeydown= changed; 
    @ window.onload = pageLoaded
    @ window.prvw = document.getElementById('previewdiv')
    @ window.isChanged
    @ function cb(text,xml){
    @   window.prvw.innerHTML = text;
    @   return true;
    @ }
    @ function preview(){
    @   if(window.isChanged){
    @     window.isChanged =0
    @     x.send("w="+encodeURIComponent(window.ta.value))
    @   }
    @   setTimeout(preview,sto)
    @ }
    @ function pageLoaded(e){
    @   window.isChanged =0
    @   setTimeout(preview,sto)
    @ }
    @ function changed(e){
    @   window.isChanged++
    @   return true
    @ }
    @ </script>
  }
  manifest_destroy(pWiki);
  style_footer();
}

/*
** WEBPAGE: wikipreview
** URL: /wikipreview
**
** render the contents of w
** for use with Ajax. This is NOT
** a complete web-page!
*/
void wikipreview_page(void){
  Blob wiki;
  char *zBody = (char*)P("w");
  if( zBody ){
    zBody = mprintf("%s", zBody);
  }
  login_check_credentials();
  if( zBody==0 ){
    zBody = mprintf("<i>Empty Page</i>");
  }
  blob_zero(&wiki);
  blob_append(&wiki, zBody, -1);
  wiki_convert(&wiki, 0, 0);
  blob_reset(&wiki);
}

/*
** WEBPAGE: wikinew
** URL /wikinew
**
** Prompt the user to enter the name of a new wiki page.  Then redirect
** to the wikiedit screen for that new page.