Changeset 14100 in project


Ignore:
Timestamp:
04/06/09 01:17:46 (11 years ago)
Author:
azul
Message:

Start using svnwikiJavascript extension's code, 'javascript' type of extension and also moved some code from the svnwiki sources to here.

Location:
release/3/svnwiki-folksonomy/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/3/svnwiki-folksonomy/trunk/svnwiki-folksonomy.meta

    r12533 r14100  
    66 (synopsis "Utilities for managing folksonomies.  Shows the tags that pages have underneath them.")
    77 (category web)
    8  (needs svnwiki-extensions  svnwiki-extensions html-stream srfi-40 stream-ext format-modular)
     8 (needs svnwiki-extensions html-stream srfi-40 stream-ext format-modular)
    99 (license "GPL-3"))
  • release/3/svnwiki-folksonomy/trunk/svnwiki-folksonomy.scm

    r12572 r14100  
    55(declare (export))
    66(use svnwiki-extensions-support html-stream srfi-40 stream-ext format-modular)
    7 
    8 (define (archive-start-update-notify env)
    9   (let-from-environment env (path-in path path-out path-out-real program)
    10     ; path-out should always be true, but lets make sure to avoid a crash if
    11     ; some day in some weird situation it isn't.
    12     (when path-out
    13       (let ((dir (svnwiki-make-pathname (list path-out "xsvnwiki-helper" "tags"))))
    14         (unless (directory? dir)
    15           (create-directory dir)))
    16       (write-file-with-tmp
    17         (svnwiki-make-pathname (list "xsvnwiki-helper" "tags") "tags")
    18         "text/javascript"
    19         path-out
    20         (string->stream *tags-script*)))))
    217
    228(define (show-tags-related env)
     
    3420            env
    3521            (html-stream
    36               ((script type "text/javascript"
    37                        src (make-link-url path-out-real (svnwiki-make-pathname (list "xsvnwiki-helper" "tags") "tags") #f)))
    3822              ((ul class "render-bottom-div render-bottom-div-tags")
    3923               (stream-fold-right-delay
     
    6650            (make-link-url path-out-real "" #f))))
    6751
    68 (define *tags-script*
     52(svnwiki-extension-define 'render-bottom-div 'folksonomy show-tags-related)
     53
     54(define (folksonomy-javascript env)
    6955#<<EOF
    70 if (typeof(svnwikiTagsLoader) != "object") {
    7156var svnwikiTagsLoader = new Object();
    72 
    73 // We use this to avoid the GC from collecting objects from loadXml before
    74 // they have actually loaded their documents and processed them:
    75 
    76 svnwikiTagsLoader.requests = new Array();
    77 
    78 svnwikiTagsLoader.loadXml = function (href, process)
    79 {
    80   var xmlDoc;
    81   var len = svnwikiTagsLoader.requests.length;
    82 
    83   if (document.implementation && document.implementation.createDocument)
    84     {
    85       xmlDoc = document.implementation.createDocument("", "", null);
    86       xmlDoc.onload = function () { svnwikiTagsLoader.removeRequest(xmlDoc); process(xmlDoc) };
    87     }
    88   else if (window.ActiveXObject)
    89     {
    90       xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    91       xmlDoc.onreadystatechange = function () { if (xmlDoc.readyState == 4) { svnwikiTagsLoader.removeRequest(xmlDoc); process(xmlDoc); } };
    92     }
    93   else
    94     {
    95       alert('Your browser can\'t handle this script');
    96       return;
    97     }
    98 
    99   svnwikiTagsLoader.requests.push(xmlDoc);
    100   xmlDoc.load(href);
    101 }
    102 
    103 svnwikiTagsLoader.removeRequest = function (element)
    104 {
    105   var rd, wr;
    106   for (rd = 0, wr = 0; rd < svnwikiTagsLoader.requests.length; rd ++)
    107     if (svnwikiTagsLoader.requests[rd] != element)
    108       svnwikiTagsLoader.requests[wr ++] = svnwikiTagsLoader.requests[rd];
    109   while (wr < svnwikiTagsLoader.requests.length)
    110     svnwikiTagsLoader.requests.pop();
    111 }
    11257
    11358svnwikiTagsLoader.showTags = function (url, id, adjust)
     
    11661  if (container.style.display == 'none') {
    11762    if (!container.hasChildNodes()) {
    118       container.appendChild(svnwikiTagsLoader.makeElement('li', document.createTextNode("Loading ...")));
    119       svnwikiTagsLoader.loadXml(url, function (xmlDoc) { svnwikiTagsLoader.updateTags(xmlDoc, container, adjust); });
     63      container.appendChild(svnwikiJavascript.makeElement('li', document.createTextNode("Loading ...")));
     64      svnwikiJavascript.loadXml(url, function (xmlDoc) { svnwikiTagsLoader.updateTags(xmlDoc, container, adjust); });
    12065    }
    12166    container.style.display = 'inline';
     
    12469}
    12570
    126 svnwikiTagsLoader.cleanContent = function (element)
    127 {
    128   while (element.hasChildNodes())
    129     element.removeChild(element.firstChild);
    130 }
    131 
    132 svnwikiTagsLoader.makeLink = function ( target, content )
    133 {
    134   var link = svnwikiTagsLoader.makeElement('a', content);
    135   link.setAttribute('href', target);
    136   return link;
    137 }
    138 
    139 svnwikiTagsLoader.makeElement = function (type, content)
    140 {
    141   var elem = document.createElement(type);
    142   if (content)
    143     elem.appendChild(content);
    144   return elem;
    145 }
    146 
    14771svnwikiTagsLoader.makeLinkFile = function (link, text)
    14872{
    149   var linkObj = svnwikiTagsLoader.makeLink(link, document.createTextNode(text));
     73  var linkObj = svnwikiJavascript.makeLink(link, document.createTextNode(text));
    15074  linkObj.setAttribute('class', 'related-pages');
    151   return (svnwikiTagsLoader.makeElement('li', linkObj));
     75  return (svnwikiJavascript.makeElement('li', linkObj));
    15276}
    15377
     
    16488svnwikiTagsLoader.updateTags = function (xmlDoc, container, adjust)
    16589{
    166   svnwikiTagsLoader.cleanContent(container);
     90  svnwikiJavascript.cleanContent(container);
    16791  svnwikiTagsLoader.iterateListOfLinks(xmlDoc.getElementById("files-for-tag"),
    16892    function (href, name) {
     
    191115
    192116svnwikiTagsLoader.relatedUpdate = function (info) {
    193   svnwikiTagsLoader.cleanContent(info.div);
     117  svnwikiJavascript.cleanContent(info.div);
    194118
    195119  if (info.filesFound.length == 0) {
    196     info.div.appendChild(svnwikiTagsLoader.makeElement('p', document.createTextNode("Ooops, we don't know how to compute the tags related to an empty tag.")))
     120    info.div.appendChild(svnwikiJavascript.makeElement('p', document.createTextNode("Ooops, we don't know how to compute the tags related to an empty tag.")))
    197121    return;
    198122  }
    199123
    200   var p = svnwikiTagsLoader.makeElement('p');
     124  var p = svnwikiJavascript.makeElement('p');
    201125  if (info.filesLoaded == info.filesFound.length) {
    202126    p.appendChild(document.createTextNode("The following are tags related with the tag "));
    203     p.appendChild(svnwikiTagsLoader.makeElement('i', document.createTextNode(info.tag)));
     127    p.appendChild(svnwikiJavascript.makeElement('i', document.createTextNode(info.tag)));
    204128    p.appendChild(document.createTextNode(":"));
    205129  } else {
    206130    p.appendChild(document.createTextNode("Loading tags for file "));
    207     p.appendChild(svnwikiTagsLoader.makeElement('i', document.createTextNode(info.filesFound[info.filesLoaded])));
     131    p.appendChild(svnwikiJavascript.makeElement('i', document.createTextNode(info.filesFound[info.filesLoaded])));
    208132    p.appendChild(document.createTextNode(" (" + Math.round(100 * info.filesLoaded / info.filesFound.length) + "%)"));
    209133  }
    210134  info.div.appendChild(p);
    211135
    212   var ul = svnwikiTagsLoader.makeElement('ul');
     136  var ul = svnwikiJavascript.makeElement('ul');
    213137  ul.setAttribute("class", "tags-list");
    214138  var copy = new Array;
     
    218142  for (var i in copy) {
    219143    var tag = copy[i];
    220     var linkObj = svnwikiTagsLoader.makeLink(tag, document.createTextNode(tag + " (" + info.tagsFound[tag] + ")"));
     144    var linkObj = svnwikiJavascript.makeLink(tag, document.createTextNode(tag + " (" + info.tagsFound[tag] + ")"));
    221145    //linkObj.setAttribute("class", "tag");
    222     var li = svnwikiTagsLoader.makeElement('li', linkObj);
     146    var li = svnwikiJavascript.makeElement('li', linkObj);
    223147    //li.setAttribute("class", "tag");
    224148    ul.appendChild(li);
     
    228152
    229153  if (info.filesError.length > 0) {
    230     info.div.appendChild(svnwikiTagsLoader.makeElement('p', document.createTextNode("Errors were detected with the following files:")));
    231     var ul = svnwikiTagsLoader.makeElement('ul');
     154    info.div.appendChild(svnwikiJavascript.makeElement('p', document.createTextNode("Errors were detected with the following files:")));
     155    var ul = svnwikiJavascript.makeElement('ul');
    232156    ul.setAttribute("class", "files-list");
    233157    for (var i = 0; i < info.filesError.length; i ++) {
    234       var li = svnwikiTagsLoader.makeElement('li', document.createTextNode(info.filesError[i]));
     158      var li = svnwikiJavascript.makeElement('li', document.createTextNode(info.filesError[i]));
    235159      li.setAttribute("class", "file");
    236160      ul.appendChild(li);
     
    246170      file = file + (file == "" ? "" : "/") + components[i];
    247171    file = file + ".xhtml";
    248     svnwikiTagsLoader.loadXml(file, function (xmlDoc) { svnwikiTagsLoader.relatedRegister(info, xmlDoc); });
     172    svnwikiJavascript.loadXml(file, function (xmlDoc) { svnwikiTagsLoader.relatedRegister(info, xmlDoc); });
    249173  }
    250174}
     
    262186  svnwikiTagsLoader.relatedUpdate(info);
    263187}
    264 } // Close the if in the first line.
    265188EOF
    266189)
    267190
    268 (svnwiki-extension-define 'render-bottom-div 'folksonomy show-tags-related)
    269 (svnwiki-extension-define 'start-update-notify 'folksonomy archive-start-update-notify)
     191(svnwiki-extension-define 'javascript 'folksonomy folksonomy-javascript)
     192
     193(define (html-body-top env)
     194  (let-from-environment env (db path-in path return)
     195    (let ((ignore (svnwiki-ignore-errors path-in path)))
     196      (assert (and 'folksonomy:html-body-top (stream? ignore)))
     197      (when (and (not (is-discuss? path))
     198                 (file-exists? (svnwiki-make-pathname path path-in))
     199                 (not (stream-find (cut eq? 'empty-tags <>) ignore))
     200                 (stream-null? (db-get-tags-page db path-in path)))
     201        (make-wiki-error
     202          (html-stream
     203            (p (svnwiki-translate env "This page has no tags.  Please contribute to the wiki by ")
     204               ((a href (get-edit-url path-in path))
     205                (svnwiki-translate env "editing it"))
     206               (svnwiki-translate env " and adding some."))))))))
     207
     208(svnwiki-extension-define 'html-body-top 'folksonomy html-body-top)
Note: See TracChangeset for help on using the changeset viewer.