Dotclear

source: plugins/dcRevisions/js/_revision.js @ 338:2d7dcf33cd6f

Revision 338:2d7dcf33cd6f, 4.0 KB checked in by sacha, 14 years ago (diff)

Added dcRevisions plugin

Line 
1/*
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of dcRevisions, a plugin for Dotclear.
4#
5# Copyright (c) 2010 Tomtom and contributors
6# http://blog.zenstyle.fr/
7#
8# Licensed under the GPL version 2.0 license.
9# A copy of this license is available in LICENSE file or at
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11# -- END LICENSE BLOCK ------------------------------------
12*/
13dotclear.revisionExpander = function() {
14     $('#revisions-list tr.line').each(function() {
15          var img = document.createElement('img');
16          img.src = dotclear.img_plus_src;
17          img.alt = dotclear.img_plus_alt;
18          img.className = 'expand';
19          $(img).css('cursor','pointer');
20          img.line=this;
21          img.onclick = function() {
22               dotclear.viewRevisionContent(this,this.line);
23          };
24          $(this).find('td.rid').prepend(img);
25     });
26};
27
28dotclear.viewRevisionContent = function(img,line) {
29     var revisionId = line.id.substr(1);
30     var postId = $("#id").val();
31     var tr = document.getElementById('re'+revisionId);
32     if(!tr){
33          tr = document.createElement('tr');
34          tr.id = 're'+revisionId;
35          var td = document.createElement('td');
36          td.colSpan = 5;
37          td.className = 'expand';
38          tr.appendChild(td);
39          img.src = dotclear.img_minus_src;
40          img.alt = dotclear.img_minus_alt;
41          $.get(
42               'services.php',{
43                    f: 'getPatch',
44                    pid: postId,
45                    rid: revisionId
46               },
47               function(data){
48                    var rsp = $(data).children('rsp')[0];
49                    if(rsp.attributes[0].value == 'ok'){
50                         var excerpt = $(rsp).find('post_excerpt_xhtml');
51                         var content = $(rsp).find('post_content_xhtml');
52                         var table = '<table class="preview-rev">';
53                         table += dotclear.viewRevisionRender($(rsp).find('post_excerpt_xhtml'),dotclear.msg.excerpt,revisionId);
54                         table += dotclear.viewRevisionRender($(rsp).find('post_content_xhtml'),dotclear.msg.content,revisionId);
55                         table += '</table>';
56                         $(td).append(table)
57                    }
58                    else {
59                         alert($(rsp).find('message').text());
60                    }
61               }
62          );
63          $(line).toggleClass('expand');
64          line.parentNode.insertBefore(tr,line.nextSibling);
65     }
66     else if (tr.style.display=='none') {
67          $(tr).toggle();
68          $(line).toggleClass('expand');
69          img.src = dotclear.img_minus_src;
70          img.alt = dotclear.img_minus_alt
71     }
72     else {
73          $(tr).toggle();
74          $(line).toggleClass('expand');
75          img.src = dotclear.img_plus_src;
76          img.alt = dotclear.img_plus_alt;
77     }
78};
79
80dotclear.viewRevisionRender = function(content,title,revisionId){
81     var res = '<thead><tr class="rev-header"><th colspan="3">'+title+'</th></tr>'+
82     '<tr class="rev-number"><th class="minimal nowrap">'+dotclear.msg.current+
83     '</th><th class="minimal nowrap">r'+revisionId+
84     '</th><th class="maximal"></th></tr></thead><tbody>';
85     if (content.size() > 0) {
86          var previous = '';
87          content.find('line').each(function() {
88               var class = '';
89               
90               var o = this.attributes[0].value;
91               var n = this.attributes[1].value;
92               var line = this.attributes[2].value;
93               console.log(previous+" - "+line);
94               if (o != '' && n == '') {
95                    class = ' delete';
96                    if (previous == '') class += ' start';
97                    previous = 'o';
98               } 
99               if (o == '' && n != '') {
100                    class = ' insert';
101                    if (previous == '') class += ' start';
102                    previous = 'n';
103               }
104               if (o != '' && n != '') {
105                    if (previous == 'o') class = ' delete-end';
106                    if (previous == 'n') class = ' insert-end';
107                    previous = '';
108               }
109               res += '<tr><td class="minimal col-line">'+o+
110               '</td><td class="minimal col-line">'+n+
111               '</td><td class="maximal'+class+'">'+line+
112               '</td></tr>';
113          });
114     }
115     res += '</tbody>';
116     return res;
117};
118
119$(function() {
120     $('#edit-entry').onetabload(function() {
121          $('#revisions-area label').toggleWithLegend(
122               $('#revisions-area').children().not('label'),{
123                    cookie:'dcx_post_revisions',
124                    hide:$('#revisions_area').val() == '<p></p>',
125                    fn:dotclear.revisionExpander()
126               }
127          );
128          $('#revisions-list tr.line a.patch').click(function() {
129               return window.confirm(dotclear.msg.confirm_apply_patch);
130          });
131     });
132});
Note: See TracBrowser for help on using the repository browser.

Sites map