aboutsummaryrefslogtreecommitdiff
path: root/js/v2/share.js
blob: b8dee52b887b3e13a6982515961520cf9b9cf9aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
   Cheetah News JS/v2 Share
   Copyright (C) 2008, 2009, 2010 Wojciech Polak.

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 3 of the License, or (at your
   option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

Modules.Share = new function () {

  var menu = null;

  this.init = function () {
    menu = document.createElement ('DIV');
    menu.id = 'shareMenu';
    menu.className = 'contextMenu';
    document.body.appendChild (menu);
    return true;
  };

  this.attach = function (n) {
    n.innerHTML = _('share this');
    n.title = _('Share this entry');
    n.onclick = showMenu;
  };

  function showMenu (e) {
    var link = this;
    if (!menu) return false;
    initMenu (link);
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation ();
    var x = findPosX (link);
    menu.style.left = (x + 14) + 'px';
    var y = findPosY (link);
    y -= main.scrollTop;
    menu.style.top = y + 'px';
    menu.style.display = 'inline';

    var yBottom = y + parseInt (menu.clientHeight);
    var yDiff = yBottom - getWindowHeight () - getScrollY ();
    if (yDiff > 0)
      menu.style.top = (y - yDiff - 15) + 'px';

    var xRight = x + 14 + parseInt (menu.clientWidth);
    var xDiff = xRight - getWindowWidth ();
    if (xDiff > 0)
      menu.style.left = (x - xDiff - 9) + 'px';

    $(document).bind ('click', hideMenu);
  }

  function hideMenu () {
    $(document).unbind ('click', hideMenu);
    menu.style.display = 'none';
  }

  function initMenu (n) {
    menu.innerHTML = '';
    var href = n.getAttribute ('href');
    href = encodeURIComponent (href.replace (/[&\?]from=rss/, ''));
    var desc = encodeURIComponent (n.getAttribute ('desc'));
    var mail = DCE ('a',
      {className:'linkCM',
       href:'mailto:?subject=' + encodeURIComponent ('[Cheetah News] ' + n.getAttribute ('desc'))
       + '&body=' + encodeURIComponent (n.getAttribute ('desc') + ':\n' + n.getAttribute ('href'))},
      ['&nbsp;<img class="share-email" src="images/t.gif" width="16" height="16" alt="" />&nbsp;E-mail&nbsp;</span>']);
    var ff = DCE ('a',
      {className:'linkCM', target:'friendfeed',
       href:'http://friendfeed.com/share?url=' + href + '&title=' + desc},
      ['&nbsp;<img class="share-ff" src="images/t.gif" width="16" height="16" alt="" />&nbsp;FriendFeed&nbsp;</span>']);
    var dlc = DCE ('a',
      {className:'linkCM', target:'delicious',
       href:'http://delicious.com/save?url=' + href + '&title=' + desc},
      ['&nbsp;<img class="share-delicious" src="images/t.gif" width="16" height="16" alt="" />&nbsp;Delicious&nbsp;</span>']);
    var dig = DCE ('a',
      {className:'linkCM', target:'digg',
       href:'http://digg.com/submit?phase=2&url=' + href + '&title=' + desc},
      ['&nbsp;<img class="share-digg" src="images/t.gif" width="16" height="16" alt="" />&nbsp;Digg&nbsp;</span>']);
    var red = DCE ('a',
      {className:'linkCM', target:'reddit',
       href:'http://reddit.com/submit?url=' + href + '&title=' + desc},
      ['&nbsp;<img class="share-reddit" src="images/t.gif" width="16" height="16" alt="" />&nbsp;Reddit&nbsp;</span>']);
    var fac = DCE ('a',
      {className:'linkCM', target:'facebook',
       href:'http://www.facebook.com/sharer.php?u=' + href + '&t=' + desc},
      ['&nbsp;<img class="share-facebook" src="images/t.gif" width="16" height="16" alt="" />&nbsp;Facebook&nbsp;</span>']);
    var stu = DCE ('a',
      {className:'linkCM', target:'stumbleupon',
       href:'http://www.stumbleupon.com/submit?url=' + href + '&title=' + desc},
      ['&nbsp;<img class="share-stumbleupon" src="images/t.gif" width="16" height="16" alt="" />&nbsp;StumbleUpon&nbsp;</span>']);
    var goo = DCE ('a',
      {className:'linkCM', target:'google',
       href:'http://www.google.com/bookmarks/mark?op=add&bkmk=' + href + '&title=' + desc},
      ['&nbsp;<img class="share-google" src="images/t.gif" width="16" height="16" alt="" />&nbsp;Google&nbsp;</span>']);
    var bzz = DCE ('a',
      {className:'linkCM', target:'buzz',
       href:'http://www.google.com/buzz/post?url=' + href},
      ['&nbsp;<img class="share-buzz" src="images/t.gif" width="16" height="16" alt="" />&nbsp;Buzz&nbsp;</span>']);
    var twt = DCE ('a',
      {className:'linkCM', target:'twitter',
       href:'http://twitter.com/?status=' + href},
      ['&nbsp;<img class="share-twitter" src="images/t.gif" width="16" height="16" alt="" />&nbsp;Twitter&nbsp;</span>']);

    setCmhLink (mail, null);
    setCmhLink (ff, null);
    setCmhLink (dlc, null);
    setCmhLink (dig, null);
    setCmhLink (red, null);
    setCmhLink (fac, null);
    setCmhLink (stu, null);
    setCmhLink (goo, null);
    setCmhLink (bzz, null);
    setCmhLink (twt, null);

    menu.appendChild (mail);
    menu.appendChild (fac);
    menu.appendChild (bzz);
    menu.appendChild (ff);
    menu.appendChild (dlc);
    menu.appendChild (dig);
    menu.appendChild (red);
    menu.appendChild (stu);
    menu.appendChild (twt);
    menu.appendChild (goo);

    menu.style.width = (menuLength * 0.50 + 1) + 'em';
  }
}

Return to:

Send suggestions and report system problems to the System administrator.