[ Index ]
 

Code source de Dotclear 2.0-beta6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/plugins/metadata/ -> post.js (source)

   1  $(function()
   2  {
   3      $('#edit-entry').onetabload(function() {
   4          document.post_tags = document.getElementById('post_tags');
   5          
   6          var meta_edit_tags = document.getElementById('meta-edit-tags');
   7          var post_id = document.getElementById('id');
   8          if (meta_edit_tags != undefined && post_id != undefined)
   9          {
  10              post_id = post_id.value;
  11              // Remove everything in meta_edit_tags
  12              while (meta_edit_tags.hasChildNodes()) {
  13                  meta_edit_tags.removeChild(meta_edit_tags.firstChild)
  14              }
  15              
  16              // Add tags
  17              var mEdit = new metaEditor(meta_edit_tags);
  18              mEdit.displayMeta('tag',post_id);
  19          }
  20      });
  21  });
  22  
  23  function metaEditor(target_element) {
  24      this.target_element = target_element;
  25  };
  26  
  27  metaEditor.prototype = {
  28      text_confirm_remove: 'Are you sure you want to remove this %s?',
  29      text_add_meta: 'Add a %s to this entry',
  30      text_choose: 'Choose from list',
  31      text_more: 'more',
  32      text_all: 'all',
  33      
  34      service_uri: 'services.php',
  35      
  36      displayMeta: function(meta_type,post_id)
  37      {
  38          var params = {
  39              f: 'getMeta',
  40              metaType: meta_type,
  41              sortBy: 'metaId asc',
  42              postId: post_id
  43          }
  44          
  45          var This = this;
  46          $.get(this.service_uri,params,function(data) {
  47              var tags = $(data).children('meta')[0];
  48              
  49              if ($(data).find('rsp').attr('status') != 'ok') { return; }
  50              
  51              while (This.target_element.hasChildNodes()) {
  52                  This.target_element.removeChild(This.target_element.firstChild)
  53              }
  54              
  55              if ($(data).find('meta').length > 0) {
  56                  var ul = document.createElement('ul');
  57                  ul.className = 'metaList';
  58                  var meta_id, li, a_tag, a_remove;
  59                  $(data).find('meta').each(function() {
  60                      meta_id = $(this).text();
  61                      li = document.createElement('li');
  62                      a_tag = document.createElement('a');
  63                      a_tag.href='plugin.php?p=metadata&m=tag_posts&tag='+$(this).attr('uri');
  64                      a_tag.appendChild(document.createTextNode(meta_id));
  65                      
  66                      a_remove = document.createElement('a');
  67                      a_remove.className = 'metaRemove';
  68                      a_remove.href='#';
  69                      a_remove.appendChild(document.createTextNode('[x]'));
  70                      
  71                      a_remove.meta_type = meta_type;
  72                      a_remove.meta_id = meta_id;
  73                      
  74                      a_remove.onclick = function() {
  75                          This.removePostMeta(post_id,this.meta_type,this.meta_id);
  76                          return false;
  77                      };
  78                      
  79                      li.appendChild(a_tag);
  80                      li.appendChild(document.createTextNode(String.fromCharCode(160)));
  81                      li.appendChild(a_remove);
  82                      ul.appendChild(li);
  83                      This.target_element.appendChild(ul);
  84                  });
  85              }
  86              
  87              var p_add = document.createElement('p');
  88              var a_add = document.createElement('a');
  89              p_add.appendChild(a_add);
  90              a_add.href='#';
  91              
  92              a_add.meta_type = meta_type;
  93              a_add.post_id = post_id;
  94              
  95              a_add.appendChild(document.createTextNode(This.text_add_meta.replace(/%s/,meta_type)));
  96              
  97              a_add.onclick = function() {
  98                  This.addMetaDialog(this,this.meta_type,this.post_id);
  99                  return false;
 100              };
 101              
 102              
 103              This.target_element.appendChild(p_add);
 104          });
 105      },
 106      
 107      addMetaDialog: function(a,meta_type,post_id)
 108      {
 109          var This = this;
 110          
 111          var I = document.createElement('input'); // Input element to add meta
 112          I.id = 'meta-text-field';
 113          I.setAttribute('type','text');
 114          I.className = '';
 115          $(I).keypress(function(evt) { // We don't want to submit form!
 116              if (evt.keyCode == 13) {
 117                  var v = This.splitMetaValues(this.value).join(',');
 118                  This.addPostMeta(post_id,meta_type,v);
 119                  return false;
 120              }
 121              return true;
 122          });
 123          
 124          var S = document.createElement('input'); // Button to add meta
 125          S.setAttribute('type','button');
 126          S.value = 'ok';
 127          S.onclick = function() {
 128              var target = document.getElementById('meta-text-field').value; // Opera sucks!
 129              var v = This.splitMetaValues(target).join(',');
 130              This.addPostMeta(post_id,meta_type,v);
 131              return false;
 132          };
 133          
 134          // View meta list
 135          var P = a.parentNode;
 136          P.removeChild(a);
 137          
 138          P.appendChild(I);
 139          P.appendChild(document.createTextNode(' '));
 140          P.appendChild(S);
 141          
 142          var p = document.createElement('p');
 143          var A = document.createElement('a');
 144          A.href = '#';
 145          A.appendChild(document.createTextNode(this.text_choose));
 146          A.onclick = function() {
 147              This.showMetaList('small',p,I);
 148              return false;
 149          };
 150          
 151          p.appendChild(A);
 152          P.parentNode.appendChild(p);
 153      },
 154      
 155      showMetaList: function(type,target,input_target)
 156      {
 157          while (target.hasChildNodes()) {
 158              target.removeChild(target.firstChild)
 159          }
 160          var w = document.createTextNode('...');
 161          target.appendChild(w);
 162          
 163          target.className = 'addMeta';
 164          
 165          var params = {
 166              f: 'getMeta',
 167              sortby: 'metaId,asc'
 168          };
 169          
 170          if (type == 'small') {
 171              params.limit = '15';
 172          } else if (type == 'more') {
 173              params.limit = '30';
 174          }
 175          
 176          var This = this;
 177          
 178          $.get(this.service_uri,params,function(data) {
 179              if ($(data).find('meta').length > 0) {
 180                  target.removeChild(w);
 181                  var meta_id, A;
 182                  
 183                  $(data).find('meta').each(function() {
 184                      meta_id = $(this).text();
 185                      A = document.createElement('a');
 186                      A.href = '#';
 187                      A.meta_id = meta_id;
 188                      
 189                      A.onclick = function() {
 190                          var v = This.splitMetaValues(input_target.value+','+this.meta_id);
 191                          input_target.value = v.join(', ');
 192                          return false;
 193                      };
 194                      
 195                      A.appendChild(document.createTextNode(meta_id));
 196                      target.appendChild(A);
 197                      target.appendChild(document.createTextNode(' '));
 198                  });
 199                  
 200                  
 201                  if (type == 'small') {
 202                      var new_type = 'more';
 203                      var new_text = This.text_more;
 204                  } else if (type == 'more') {
 205                      var new_type = 'all';
 206                      var new_text = This.text_all;
 207                  }
 208                  
 209                  if (type == 'small' || type == 'more') {
 210                      var a_more = document.createElement('a');
 211                      a_more.className = 'metaGetMore';
 212                      a_more.href = '#';
 213                      a_more.onclick = function() {
 214                          This.showMetaList(new_type,target,input_target);
 215                          return false;
 216                      };
 217                      a_more.appendChild(document.createTextNode(new_text +
 218                          String.fromCharCode(160)+String.fromCharCode(187)));
 219                      
 220                      target.appendChild(a_more);
 221                  }
 222              }
 223          });
 224      },
 225      
 226      addPostMeta: function(post_id,meta_type,meta)
 227      {
 228          var params = {
 229              f: 'setPostMeta',
 230              postId: post_id,
 231              metaType: meta_type,
 232              meta: meta
 233          };
 234          
 235          var This = this;
 236          $.post(this.service_uri,params,function(data) {
 237              if ($(data).find('rsp').attr('status') == 'ok') {
 238                  This.displayMeta(meta_type,post_id);
 239              } else {
 240                  alert($(data).find('message').text());
 241              }
 242          });
 243      },
 244      
 245      removePostMeta: function(post_id,meta_type,meta_id)
 246      {
 247          var text_confirm_msg = this.text_confirm_remove.replace(/%s/,meta_type);
 248          var This = this;
 249          
 250          if (window.confirm(text_confirm_msg)) {
 251              var params = {
 252                  f: 'delMeta',
 253                  postId: post_id,
 254                  metaId: meta_id,
 255                  metaType: meta_type
 256              };
 257              
 258              $.post(this.service_uri,params,function(data) {
 259                  if ($(data).find('rsp').attr('status') == 'ok') {
 260                      This.displayMeta(meta_type,post_id);
 261                  } else {
 262                      alert($(data).find('message').text());
 263                  }
 264              });
 265          }
 266      },
 267      
 268      splitMetaValues: function(str)
 269      {
 270  		function inArray(needle,stack) {
 271              for (var i=0; i<stack.length; i++) {
 272                  if (stack[i] == needle) {
 273                      return true;
 274                  }
 275              }
 276              return false;
 277          }
 278          
 279          var res = new Array();
 280          var v = str.split(',');
 281          v.sort();
 282          for (var i=0; i<v.length; i++) {
 283              v[i] = v[i].replace(/^\s*/,'').replace(/\s*$/,'');
 284              if (v[i] != '' && !inArray(v[i],res)) {
 285                  res.push(v[i]);
 286              }
 287          }
 288          res.sort();
 289          return res;
 290      }
 291  };
 292  
 293  // Toolbar button for tags
 294  jsToolBar.prototype.elements.tagSpace = {type: 'space'};
 295  
 296  jsToolBar.prototype.elements.tag = {type: 'button', title: 'Keyword', fn:{} };
 297  jsToolBar.prototype.elements.tag.context = 'post';
 298  jsToolBar.prototype.elements.tag.icon = 'index.php?pf=metadata/tag-add.png';
 299  jsToolBar.prototype.elements.tag.addTag = function(content) {
 300      if (!content) { return false; }
 301      
 302      var meta_edit_tags = document.getElementById('meta-edit-tags');
 303      var post_tags = document.getElementById('post_tags');
 304      var post_id = document.getElementById('id');
 305      
 306      if (meta_edit_tags && post_id) {
 307          var mEdit = new metaEditor(meta_edit_tags);
 308          mEdit.addPostMeta(post_id.value,'tag',content);
 309          return true;
 310      } else if (post_tags != undefined) {
 311          post_tags.value += content+', ';
 312      }
 313      return false;
 314  };
 315  jsToolBar.prototype.elements.tag.fn.wiki = function() {
 316      this.encloseSelection('','',function(str) {
 317          if (str == '') { return ''; }
 318          if (str.indexOf(',') != -1) {
 319              return str;
 320          } else {
 321              this.elements.tag.addTag(str);
 322              return '['+str+'|tag:'+str+']';
 323          }
 324      });
 325  };
 326  jsToolBar.prototype.elements.tag.fn.xhtml = function() {
 327      var url = this.elements.tag.url;
 328      this.encloseSelection('','',function(str) {
 329          if (str == '') { return ''; }
 330          if (str.indexOf(',') != -1) {
 331              return str;
 332          } else {
 333              this.elements.tag.addTag(str);
 334              return '<a href="'+this.stripBaseURL(url+'/'+str)+'">'+str+'</a>';
 335          }
 336      });
 337  };
 338  jsToolBar.prototype.elements.tag.fn.wysiwyg = function() {
 339      var t = this.getSelectedText();
 340      
 341      if (t == '') { return; }
 342      if (t.indexOf(',') != -1) { return; }
 343      
 344      var n = this.getSelectedNode();
 345      var a = document.createElement('a');
 346      a.href = this.stripBaseURL(this.elements.tag.url+'/'+t);
 347      a.appendChild(n);
 348      this.insertNode(a);
 349      this.elements.tag.addTag(t);
 350  };


Généré le : Fri Feb 23 22:16:06 2007 par Balluche grâce à PHPXref 0.7