blob: a2f255d087487be1016bef41f38f427b3a8e0fdc [file] [log] [blame]
Tang Cheng60ba8032016-06-20 15:31:17 +08001(function($){
2
3 // Share
4 $('body').on('click', function(){
5 $('.article-share-box.on').removeClass('on');
6 }).on('click', '.article-share-link', function(e){
7 e.stopPropagation();
8
9 var $this = $(this),
10 url = $this.attr('data-url'),
11 encodedUrl = encodeURIComponent(url),
12 id = 'article-share-box-' + $this.attr('data-id'),
13 offset = $this.offset();
14
15 if ($('#' + id).length){
16 var box = $('#' + id);
17
18 if (box.hasClass('on')){
19 box.removeClass('on');
20 return;
21 }
22 } else {
23 var html = [
24 '<div id="' + id + '" class="article-share-box">',
25 '<input class="article-share-input" value="' + url + '">',
26 '<div class="article-share-links">',
27 '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
28 '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
29 '<a href="http://pinterest.com/pin/create/button/?url=' + encodedUrl + '" class="article-share-pinterest" target="_blank" title="Pinterest"></a>',
30 '<a href="https://plus.google.com/share?url=' + encodedUrl + '" class="article-share-google" target="_blank" title="Google+"></a>',
31 '</div>',
32 '</div>'
33 ].join('');
34
35 var box = $(html);
36
37 $('body').append(box);
38 }
39
40 $('.article-share-box.on').hide();
41
42 box.css({
43 top: offset.top + 25,
44 left: offset.left
45 }).addClass('on');
46 }).on('click', '.article-share-box', function(e){
47 e.stopPropagation();
48 }).on('click', '.article-share-box-input', function(){
49 $(this).select();
50 }).on('click', '.article-share-box-link', function(e){
51 e.preventDefault();
52 e.stopPropagation();
53
54 window.open(this.href, 'article-share-box-window-' + Date.now(), 'width=500,height=450');
55 });
56
57 // Caption
58 $('.article-entry').each(function(i){
59 $(this).find('img').each(function(){
60 if ($(this).parent().hasClass('image-link')) return;
61
62 var alt = this.alt;
63 if (alt) $(this).after('<span class="caption">' + alt + '</span>');
64
65 $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="image-link"></a>');
66 });
67
68 $(this).find('.image-link').each(function(){
69 $(this).attr('rel', 'article' + i);
70 });
71 });
72
73 // Bootstrap table style
74 $('.article-entry table').each(function(i, table) {
75 if ($(this).parent().hasClass('table-responsive')) return;
76 $(this).addClass('table');
77 $(this).wrap('<div class="table-responsive"></div>');
78 });
79
80 // Lightbox plugin
81 if ($.fancybox){
82 $('.image-link').fancybox();
83 }
84
85})(jQuery);