Dotclear

source: plugins/tags/js/post.js @ 1392:f654316f6e43

Revision 1392:f654316f6e43, 2.9 KB checked in by Dsls, 11 years ago (diff)
  • Added foldable sidebar entries,
  • Added new behavior : adminPostFormSidebarItems
  • Sidebar entries are now manageable from plugins

see #1533

Line 
1$(function() {
2     $('#edit-entry').onetabload(function() {
3          var tags_edit = $('#tags-edit');
4          var post_id = $('#id');
5          var meta_field = null;
6         
7          if (tags_edit.length > 0) {
8               post_id = (post_id.length > 0) ? post_id.get(0).value : false;
9               if (post_id == false) {
10                    meta_field = $('<input type="hidden" name="post_tags" />');
11                    meta_field.val($('#post_tags').val());
12               }
13               var mEdit = new metaEditor(tags_edit,meta_field,'tag');
14               mEdit.meta_url = 'plugin.php?p=tags&m=tag_posts&amp;tag=';
15               mEdit.displayMeta('tag',post_id);
16               
17               // mEdit object reference for toolBar
18               window.dc_tag_editor = mEdit;
19          }
20         
21          $('#post_meta_input').autocomplete(mEdit.service_uri, {
22               extraParams: {
23                    'f': 'searchMeta',
24                    'metaType': 'tag'
25               },
26               delay: 1000,
27               multiple: true,
28               matchSubset: false,
29               matchContains: true,
30               parse: function(xml) { 
31                    var results = [];
32                    $(xml).find('meta').each(function(){
33                         results[results.length] = {
34                              data: {
35                                   "id": $(this).text(),
36                                   "count": $(this).attr("count"),
37                                   "percent":  $(this).attr("roundpercent")
38                              },
39                              result: $(this).text()
40                         }; 
41                    });
42                    return results;
43               },
44               formatItem: function(tag) {
45                    return tag.id + ' <em>(' +
46                    dotclear.msg.tags_autocomplete.
47                         replace('%p',tag.percent).
48                         replace('%e',tag.count + ' ' +
49                              (tag.count > 1 ?
50                              dotclear.msg.entries :
51                              dotclear.msg.entry)
52                         ) +
53                    ')</em>';
54               },
55               formatResult: function(tag) { 
56                    return tag.result; 
57               }
58          });
59     });
60               
61     $('h5 .s-tags').toggleWithLegend($('.s-tags').not('label'),{
62               cookie: 'post_tags'
63     });
64
65});
66
67// Toolbar button for tags
68jsToolBar.prototype.elements.tagSpace = {type: 'space'};
69
70jsToolBar.prototype.elements.tag = {type: 'button', title: 'Keyword', fn:{} };
71jsToolBar.prototype.elements.tag.context = 'post';
72jsToolBar.prototype.elements.tag.icon = 'index.php?pf=tags/img/tag-add.png';
73jsToolBar.prototype.elements.tag.fn.wiki = function() {
74     this.encloseSelection('','',function(str) {
75          if (str == '') { window.alert(dotclear.msg.no_selection); return ''; }
76          if (str.indexOf(',') != -1) {
77               return str;
78          } else {
79               window.dc_tag_editor.addMeta(str);
80               return '['+str+'|tag:'+str+']';
81          }
82     });
83};
84jsToolBar.prototype.elements.tag.fn.xhtml = function() {
85     var url = this.elements.tag.url;
86     this.encloseSelection('','',function(str) {
87          if (str == '') { window.alert(dotclear.msg.no_selection); return ''; }
88          if (str.indexOf(',') != -1) {
89               return str;
90          } else {
91               window.dc_tag_editor.addMeta(str);
92               return '<a href="'+this.stripBaseURL(url+'/'+str)+'">'+str+'</a>';
93          }
94     });
95};
96jsToolBar.prototype.elements.tag.fn.wysiwyg = function() {
97     var t = this.getSelectedText();
98     
99     if (t == '') { window.alert(dotclear.msg.no_selection); return; }
100     if (t.indexOf(',') != -1) { return; }
101     
102     var n = this.getSelectedNode();
103     var a = document.createElement('a');
104     a.href = this.stripBaseURL(this.elements.tag.url+'/'+t);
105     a.appendChild(n);
106     this.insertNode(a);
107     window.dc_tag_editor.addMeta(t);
108};
Note: See TracBrowser for help on using the repository browser.

Sites map