Fechin 8 years ago
parent
commit
8cf5fe10f6
1 changed files with 204 additions and 206 deletions
  1. 204 206
      source/js/diaspora.js

+ 204 - 206
source/js/diaspora.js

@@ -4,9 +4,8 @@
  * @url http://lorem.in
  * @url http://lorem.in
  */
  */
 var Home = location.href,
 var Home = location.href,
-    Pages = 4,
-    xhr,
-    xhrUrl = '';
+Pages = 4,
+xhr, xhrUrl = '';
 
 
 var Diaspora = {
 var Diaspora = {
 
 
@@ -26,8 +25,7 @@ var Diaspora = {
             url: url,
             url: url,
             timeout: 10000,
             timeout: 10000,
             success: function(data) {
             success: function(data) {
-                f(data)
-                xhrUrl = '';
+                f(data) xhrUrl = '';
             },
             },
             error: function(a, b, c) {
             error: function(a, b, c) {
                 if (b == 'abort') {
                 if (b == 'abort') {
@@ -41,15 +39,20 @@ var Diaspora = {
     },
     },
 
 
     P: function() {
     P: function() {
-        return !!('ontouchstart' in window);
+        return !! ('ontouchstart' in window);
     },
     },
 
 
     PS: function() {
     PS: function() {
-        if (!(window.history && history.pushState)) return;
+        if (! (window.history && history.pushState)) return;
 
 
-        history.replaceState({u: Home, t: document.title}, document.title, Home)
+        history.replaceState({
+            u: Home,
+            t: document.title
+        },
+        document.title, Home)
 
 
-        window.addEventListener('popstate', function(e) {
+        window.addEventListener('popstate',
+        function(e) {
             var state = e.state;
             var state = e.state;
 
 
             if (!state) return;
             if (!state) return;
@@ -57,20 +60,18 @@ var Diaspora = {
             document.title = state.t;
             document.title = state.t;
 
 
             if (state.u == Home) {
             if (state.u == Home) {
-                $('#preview').css('position', 'fixed')
-                setTimeout(function() {
-                    $('#preview').removeClass('show').addClass('trans')
-                    $('#container').show()
-                    window.scrollTo(0, parseInt($('#container').data('scroll')))
-                    setTimeout(function() {
-                        $('#preview').html('')
-                        $(window).trigger('resize')
-                    }, 300)
-                }, 0)
+                $('#preview').css('position', 'fixed') setTimeout(function() {
+                    $('#preview').removeClass('show').addClass('trans') $('#container').show() window.scrollTo(0, parseInt($('#container').data('scroll'))) setTimeout(function() {
+                        $('#preview').html('') $(window).trigger('resize')
+                    },
+                    300)
+                },
+                0)
             } else {
             } else {
                 Diaspora.loading()
                 Diaspora.loading()
 
 
-                Diaspora.L(state.u, function(data) {
+                Diaspora.L(state.u,
+                function(data) {
 
 
                     document.title = state.t;
                     document.title = state.t;
 
 
@@ -78,7 +79,10 @@ var Diaspora = {
 
 
                     Diaspora.preview()
                     Diaspora.preview()
 
 
-                    setTimeout(function() { Diaspora.player() }, 0)
+                    setTimeout(function() {
+                        Diaspora.player()
+                    },
+                    0)
                 })
                 })
             }
             }
 
 
@@ -87,16 +91,21 @@ var Diaspora = {
 
 
     HS: function(tag, flag) {
     HS: function(tag, flag) {
         var id = tag.data('id') || 0,
         var id = tag.data('id') || 0,
-            url = tag.attr('href'),
-            title = tag.attr('title') || tag.text();
+        url = tag.attr('href'),
+        title = tag.attr('title') || tag.text();
 
 
         if (!$('#preview').length || !(window.history && history.pushState)) location.href = url;
         if (!$('#preview').length || !(window.history && history.pushState)) location.href = url;
 
 
         Diaspora.loading()
         Diaspora.loading()
 
 
-        var state = {d: id, t: title, u: url};
+        var state = {
+            d: id,
+            t: title,
+            u: url
+        };
 
 
-        Diaspora.L(url, function(data) {
+        Diaspora.L(url,
+        function(data) {
 
 
             if (!$(data).filter('#single').length) {
             if (!$(data).filter('#single').length) {
                 location.href = url;
                 location.href = url;
@@ -105,13 +114,11 @@ var Diaspora = {
 
 
             switch (flag) {
             switch (flag) {
 
 
-                case 'push':
-                    history.pushState(state, title, url)
-                    break;
+            case 'push':
+                history.pushState(state, title, url) break;
 
 
-                case 'replace':
-                    history.replaceState(state, title, url)
-                    break;
+            case 'replace':
+                history.replaceState(state, title, url) break;
 
 
             }
             }
 
 
@@ -121,14 +128,11 @@ var Diaspora = {
 
 
             switch (flag) {
             switch (flag) {
 
 
-                case 'push':
-                    Diaspora.preview()
-                    break;
+            case 'push':
+                Diaspora.preview() break;
 
 
-                case 'replace':
-                    window.scrollTo(0, 0)
-                    Diaspora.loaded()
-                    break;
+            case 'replace':
+                window.scrollTo(0, 0) Diaspora.loaded() break;
             }
             }
 
 
             setTimeout(function() {
             setTimeout(function() {
@@ -137,28 +141,28 @@ var Diaspora = {
                 if (flag == 'replace') {
                 if (flag == 'replace') {
                     $('#top').show()
                     $('#top').show()
                 }
                 }
-            }, 0)
+            },
+            0)
 
 
         })
         })
     },
     },
 
 
     preview: function() {
     preview: function() {
         setTimeout(function() {
         setTimeout(function() {
-            $('#preview').addClass('show')
-            $('#container').data('scroll', window.scrollY)
-            setTimeout(function() {
-                $('#container').hide()
-                setTimeout(function() {
+            $('#preview').addClass('show') $('#container').data('scroll', window.scrollY) setTimeout(function() {
+                $('#container').hide() setTimeout(function() {
                     $('#preview').css({
                     $('#preview').css({
                         'position': 'static',
                         'position': 'static',
                         'overflow-y': 'auto'
                         'overflow-y': 'auto'
-                    }).removeClass('trans')
-                    $('#top').show()
+                    }).removeClass('trans') $('#top').show()
 
 
                     Diaspora.loaded()
                     Diaspora.loaded()
-                }, 500)
-            }, 300)
-        }, 0)
+                },
+                500)
+            },
+            300)
+        },
+        0)
     },
     },
 
 
     player: function() {
     player: function() {
@@ -168,8 +172,7 @@ var Diaspora = {
             $('.icon-play').css({
             $('.icon-play').css({
                 'color': '#dedede',
                 'color': '#dedede',
                 'cursor': 'not-allowed'
                 'cursor': 'not-allowed'
-            })
-            return
+            }) return
         }
         }
 
 
         if (p.eq(0).data("autoplay") == true) {
         if (p.eq(0).data("autoplay") == true) {
@@ -182,7 +185,7 @@ var Diaspora = {
                 $('.bar').css('width', progress + '%');
                 $('.bar').css('width', progress + '%');
                 if (progress / 5 <= 1) {
                 if (progress / 5 <= 1) {
                     p[0].volume = progress / 5;
                     p[0].volume = progress / 5;
-                }else {
+                } else {
                     p[0].volume = 1;
                     p[0].volume = 1;
                 }
                 }
             },
             },
@@ -197,15 +200,10 @@ var Diaspora = {
 
 
     loading: function() {
     loading: function() {
         var w = window.innerWidth;
         var w = window.innerWidth;
-        var css = '<style class="loaderstyle" id="loaderstyle'+ w +'">'+
-            '@-moz-keyframes loader'+ w +'{100%{background-position:'+ w +'px 0}}'+
-            '@-webkit-keyframes loader'+ w +'{100%{background-position:'+ w +'px 0}}'+
-            '.loader'+ w +'{-webkit-animation:loader'+ w +' 3s linear infinite;-moz-animation:loader'+ w +' 3s linear infinite;}'+
-            '</style>';
-        $('.loaderstyle').remove()
-        $('head').append(css)
-
-        $('#loader').removeClass().addClass('loader'+ w).show()
+        var css = '<style class="loaderstyle" id="loaderstyle' + w + '">' + '@-moz-keyframes loader' + w + '{100%{background-position:' + w + 'px 0}}' + '@-webkit-keyframes loader' + w + '{100%{background-position:' + w + 'px 0}}' + '.loader' + w + '{-webkit-animation:loader' + w + ' 3s linear infinite;-moz-animation:loader' + w + ' 3s linear infinite;}' + '</style>';
+        $('.loaderstyle').remove() $('head').append(css)
+
+        $('#loader').removeClass().addClass('loader' + w).show()
     },
     },
 
 
     loaded: function() {
     loaded: function() {
@@ -214,19 +212,19 @@ var Diaspora = {
 
 
     F: function(id, w, h) {
     F: function(id, w, h) {
         var _height = $(id).parent().height(),
         var _height = $(id).parent().height(),
-            _width = $(id).parent().width(),
-            ratio = h / w;
+        _width = $(id).parent().width(),
+        ratio = h / w;
 
 
         if (_height / _width > ratio) {
         if (_height / _width > ratio) {
-            id.style.height = _height +'px';
-            id.style.width = _height / ratio +'px';
+            id.style.height = _height + 'px';
+            id.style.width = _height / ratio + 'px';
         } else {
         } else {
-            id.style.width = _width +'px';
-            id.style.height = _width * ratio +'px';
+            id.style.width = _width + 'px';
+            id.style.height = _width * ratio + 'px';
         }
         }
 
 
-        id.style.left = (_width - parseInt(id.style.width)) / 2 +'px';
-        id.style.top = (_height - parseInt(id.style.height)) / 2 +'px';
+        id.style.left = (_width - parseInt(id.style.width)) / 2 + 'px';
+        id.style.top = (_height - parseInt(id.style.height)) / 2 + 'px';
     }
     }
 
 
 }
 }
@@ -244,20 +242,29 @@ $(function() {
         cover.w = cover.t.attr('width');
         cover.w = cover.t.attr('width');
         cover.h = cover.t.attr('height');
         cover.h = cover.t.attr('height');
 
 
-        ;(cover.o = function() {
+        ; (cover.o = function() {
             $('#mark').height(window.innerHeight)
             $('#mark').height(window.innerHeight)
         })();
         })();
 
 
         if (cover.t.prop('complete')) {
         if (cover.t.prop('complete')) {
             // why setTimeout ?
             // why setTimeout ?
-            setTimeout(function() { cover.t.load() }, 0)
+            setTimeout(function() {
+                cover.t.load()
+            },
+            0)
         }
         }
 
 
-        cover.t.on('load', function() {
+        cover.t.on('load',
+        function() {
 
 
-            ;(cover.f = function() {
+            ; (cover.f = function() {
 
 
-                var _w = $('#mark').width(), _h = $('#mark').height(), x, y, i, e;
+                var _w = $('#mark').width(),
+                _h = $('#mark').height(),
+                x,
+                y,
+                i,
+                e;
 
 
                 e = (_w >= 1000 || _h >= 1000) ? 1000 : 500;
                 e = (_w >= 1000 || _h >= 1000) ? 1000 : 500;
 
 
@@ -274,8 +281,8 @@ $(function() {
                 $('.layer').css({
                 $('.layer').css({
                     'width': _w + x,
                     'width': _w + x,
                     'height': _h + y,
                     'height': _h + y,
-                    'marginLeft': - 0.5 * x,
-                    'marginTop': - 0.5 * y
+                    'marginLeft': -0.5 * x,
+                    'marginTop': -0.5 * y
                 })
                 })
 
 
                 if (!cover.w) {
                 if (!cover.w) {
@@ -289,7 +296,8 @@ $(function() {
 
 
             setTimeout(function() {
             setTimeout(function() {
                 $('html, body').removeClass('loading')
                 $('html, body').removeClass('loading')
-            }, 1000)
+            },
+            1000)
 
 
             $('#mark').parallax()
             $('#mark').parallax()
 
 
@@ -297,8 +305,7 @@ $(function() {
             var swatches = vibrant.swatches()
             var swatches = vibrant.swatches()
 
 
             if (swatches['DarkVibrant']) {
             if (swatches['DarkVibrant']) {
-                $('#vibrant polygon').css('fill', swatches['DarkVibrant'].getHex())
-                $('#vibrant div').css('background-color', swatches['DarkVibrant'].getHex())
+                $('#vibrant polygon').css('fill', swatches['DarkVibrant'].getHex()) $('#vibrant div').css('background-color', swatches['DarkVibrant'].getHex())
             }
             }
             if (swatches['Vibrant']) {
             if (swatches['Vibrant']) {
                 $('.icon-menu').css('color', swatches['Vibrant'].getHex())
                 $('.icon-menu').css('color', swatches['Vibrant'].getHex())
@@ -317,19 +324,20 @@ $(function() {
         $('.pview a').addClass('pviewa')
         $('.pview a').addClass('pviewa')
 
 
         var T;
         var T;
-        $(window).on('resize', function() {
+        $(window).on('resize',
+        function() {
             clearTimeout(T)
             clearTimeout(T)
 
 
             T = setTimeout(function() {
             T = setTimeout(function() {
                 if (!Diaspora.P() && location.href == Home) {
                 if (!Diaspora.P() && location.href == Home) {
-                    cover.o()
-                    cover.f()
+                    cover.o() cover.f()
                 }
                 }
 
 
                 if ($('#loader').attr('class')) {
                 if ($('#loader').attr('class')) {
                     Diaspora.loading()
                     Diaspora.loading()
                 }
                 }
-            }, 500)
+            },
+            500)
         })
         })
 
 
     } else {
     } else {
@@ -338,9 +346,11 @@ $(function() {
 
 
         setTimeout(function() {
         setTimeout(function() {
             $('html, body').removeClass('loading')
             $('html, body').removeClass('loading')
-        }, 1000)
+        },
+        1000)
 
 
-        window.addEventListener('popstate', function(e) {
+        window.addEventListener('popstate',
+        function(e) {
 
 
             if (e.state) location.href = e.state.u;
             if (e.state) location.href = e.state.u;
 
 
@@ -354,16 +364,17 @@ $(function() {
 
 
     }
     }
 
 
-    $(window).on('scroll', function() {
+    $(window).on('scroll',
+    function() {
         if ($('.scrollbar').length && !Diaspora.P() && !$('.icon-images').hasClass('active')) {
         if ($('.scrollbar').length && !Diaspora.P() && !$('.icon-images').hasClass('active')) {
             var st = $(window).scrollTop(),
             var st = $(window).scrollTop(),
-                ct = $('.content').height();
+            ct = $('.content').height();
 
 
             if (st > ct) {
             if (st > ct) {
                 st = ct
                 st = ct
             }
             }
 
 
-            $('.scrollbar').width((50 + st) / ct * 100 +'%')
+            $('.scrollbar').width((50 + st) / ct * 100 + '%')
 
 
             if (st > 80 && window.innerWidth > 800) {
             if (st > 80 && window.innerWidth > 800) {
                 $('.subtitle').fadeIn()
                 $('.subtitle').fadeIn()
@@ -373,168 +384,155 @@ $(function() {
         }
         }
     })
     })
 
 
-    $(window).on('touchmove', function(e) {
+    $(window).on('touchmove',
+    function(e) {
         if ($('body').hasClass('mu')) {
         if ($('body').hasClass('mu')) {
             e.preventDefault()
             e.preventDefault()
         }
         }
     })
     })
 
 
-    $('body').on('click', function(e) {
+    $('body').on('click',
+    function(e) {
         var tag = $(e.target).attr('class') || '',
         var tag = $(e.target).attr('class') || '',
-            rel = $(e.target).attr('rel') || '';
+        rel = $(e.target).attr('rel') || '';
 
 
         if (!tag && !rel) return;
         if (!tag && !rel) return;
 
 
         switch (true) {
         switch (true) {
 
 
             // nav menu
             // nav menu
-            case (tag.indexOf('switchmenu') != -1):
-                window.scrollTo(0, 0)
-                $('html, body').toggleClass('mu');
+        case(tag.indexOf('switchmenu') != -1) : window.scrollTo(0, 0) $('html, body').toggleClass('mu');
 
 
-                break;
+            break;
 
 
             // next page
             // next page
-            case (tag.indexOf('more') != -1):
-                tag = $('.more');
+        case (tag.indexOf('more') != -1) : tag = $('.more');
 
 
-                if (tag.data('status') == 'loading') {
-                    return false
-                }
+            if (tag.data('status') == 'loading') {
+                return false
+            }
 
 
-                var num = parseInt(tag.data('page')) || 1;
+            var num = parseInt(tag.data('page')) || 1;
 
 
-                if (num == 1) {
-                    tag.data('page', 1)
-                }
+            if (num == 1) {
+                tag.data('page', 1)
+            }
 
 
-                if (num >= Pages) {
-                    return
-                }
+            if (num >= Pages) {
+                return
+            }
 
 
-                tag.html('åŠ è½½ä¸­..').data('status', 'loading')
-                Diaspora.loading()
+            tag.html('åŠ è½½ä¸­..').data('status', 'loading') Diaspora.loading()
 
 
-                Diaspora.L(tag.attr('href'), function(data) {
-                    var link = $(data).find('.more').attr('href');
-                    if (link != undefined) {
-                        tag.attr('href', link).html('åŠ è½½æ›´å¤š').data('status', 'loaded')
-                        tag.data('page', parseInt(tag.data('page')) + 1)
-                    } else {
-                        $('#pager').remove()
-                    }
+            Diaspora.L(tag.attr('href'),
+            function(data) {
+                var link = $(data).find('.more').attr('href');
+                if (link != undefined) {
+                    tag.attr('href', link).html('åŠ è½½æ›´å¤š').data('status', 'loaded') tag.data('page', parseInt(tag.data('page')) + 1)
+                } else {
+                    $('#pager').remove()
+                }
 
 
-                    $('#primary').append($(data).find('.post'))
+                $('#primary').append($(data).find('.post'))
 
 
-                    Diaspora.loaded()
-                }, function() {
-                    tag.html('åŠ è½½æ›´å¤š').data('status', 'loaded')
-                })
+                Diaspora.loaded()
+            },
+            function() {
+                tag.html('åŠ è½½æ›´å¤š').data('status', 'loaded')
+            })
 
 
-                return false;
-                break;
+            return false;
+            break;
 
 
             // home
             // home
-            case (tag.indexOf('icon-home') != -1):
-                if ($('#preview').hasClass('show')) {
-                    history.back();
-                } else {
-                    location.href = "/";
-                }
-                break;
-
+        case (tag.indexOf('icon-home') != -1) : if ($('#preview').hasClass('show')) {
+                history.back();
+            } else {
+                location.href = "/";
+            }
+            break;
 
 
             // qrcode
             // qrcode
-            case (tag.indexOf('icon-scan') != -1):
-                if ($('.icon-scan').hasClass('tg')) {
-                    $('#qr').toggle()
-                } else {
-                    $('.icon-scan').addClass('tg')
-                    $('#qr').qrcode({ width: 128, height: 128, text: location.href}).toggle()
-                }
-                break;
+        case (tag.indexOf('icon-scan') != -1) : if ($('.icon-scan').hasClass('tg')) {
+                $('#qr').toggle()
+            } else {
+                $('.icon-scan').addClass('tg') $('#qr').qrcode({
+                    width: 128,
+                    height: 128,
+                    text: location.href
+                }).toggle()
+            }
+            break;
 
 
             // audio play
             // audio play
-            case (tag.indexOf('icon-play') != -1):
-                $('#audio')[0].play()
-                $('.icon-play').removeClass('icon-play').addClass('icon-pause')
-                break;
+        case (tag.indexOf('icon-play') != -1) : $('#audio')[0].play() $('.icon-play').removeClass('icon-play').addClass('icon-pause') break;
 
 
             // audio pause
             // audio pause
-            case (tag.indexOf('icon-pause') != -1):
-                $('#audio')[0].pause()
-                $('.icon-pause').removeClass('icon-pause').addClass('icon-play')
-                break;
-
+        case (tag.indexOf('icon-pause') != -1) : $('#audio')[0].pause() $('.icon-pause').removeClass('icon-pause').addClass('icon-play') break;
 
 
             // history state
             // history state
-            case (tag.indexOf('cover') != -1):
-                Diaspora.HS($(e.target).parent(), 'push')
-                return false;
-                break;
+        case (tag.indexOf('cover') != -1) : Diaspora.HS($(e.target).parent(), 'push') return false;
+            break;
 
 
             // history state
             // history state
-            case (tag.indexOf('posttitle') != -1):
-                Diaspora.HS($(e.target), 'push')
-                return false;
-                break;
+        case (tag.indexOf('posttitle') != -1) : Diaspora.HS($(e.target), 'push') return false;
+            break;
 
 
             // prev, next post
             // prev, next post
-            case (rel == 'prev' || rel == 'next'):
-                if (rel == 'prev') {
-                    var t = $('#prev_next a')[0].text
-                } else {
-                    var t = $('#prev_next a')[1].text
-                }
-                $(e.target).attr('title', t)
+        case (rel == 'prev' || rel == 'next') : if (rel == 'prev') {
+                var t = $('#prev_next a')[0].text
+            } else {
+                var t = $('#prev_next a')[1].text
+            }
+            $(e.target).attr('title', t)
 
 
-                Diaspora.HS($(e.target), 'replace')
-                return false;
-                break;
+            Diaspora.HS($(e.target), 'replace') return false;
+            break;
 
 
             // quick view
             // quick view
-            case (tag.indexOf('pviewa') != -1):
-                $('body').removeClass('mu')
-
-                setTimeout(function() {
-                    Diaspora.HS($(e.target), 'push')
-                }, 300)
-
-                return false;
-                break;
-
-				// comment
-			case - 1 != tag.indexOf("comment") && - 1 != tag.indexOf("link"):
-                Diaspora.loading();
-				$(".comment").removeClass("link").html("");
-				var id = $(".comment").data("id"),
-				    title = $(".comment").data("title"),
-				    url = $(".comment").data("url"),
-				    shortname = $(".comment").data("shortname");
-                window.duoshuoQuery = {short_name: shortname};
-				var f = function() {
-					var a = document.createElement("div");
-					a.setAttribute("data-thread-key", id);
-					a.setAttribute("data-title", title);
-					a.setAttribute("data-url", url);
-					DUOSHUO.EmbedThread(a);
-					$(".comment").html(a);
-					Diaspora.loaded();
-				};
-				window.DUOSHUO ? f() : $.getScript("http://static.duoshuo.com/embed.js",
-				function() {
-					f()
-				});
-				return false;
-				break;
-
-            default:
-                return;
-                break;
+        case (tag.indexOf('pviewa') != -1) : $('body').removeClass('mu')
+
+            setTimeout(function() {
+                Diaspora.HS($(e.target), 'push')
+            },
+            300)
+
+            return false;
+            break;
+
+            // comment
+        case - 1 != tag.indexOf("comment") && -1 != tag.indexOf("link") : Diaspora.loading();
+            $(".comment").removeClass("link").html("");
+            var id = $(".comment").data("id"),
+            title = $(".comment").data("title"),
+            url = $(".comment").data("url"),
+            shortname = $(".comment").data("shortname");
+            window.duoshuoQuery = {
+                short_name: shortname
+            };
+            var f = function() {
+                var a = document.createElement("div");
+                a.setAttribute("data-thread-key", id);
+                a.setAttribute("data-title", title);
+                a.setAttribute("data-url", url);
+                DUOSHUO.EmbedThread(a);
+                $(".comment").html(a);
+                Diaspora.loaded();
+            };
+            window.DUOSHUO ? f() : $.getScript("http://static.duoshuo.com/embed.js",
+            function() {
+                f()
+            });
+            return false;
+            break;
+
+        default:
+            return;
+            break;
         }
         }
 
 
     })
     })
 
 
-    console.log("%c Github %c","background:#24272A; color:#ffffff","","https://github.com/Fechin/hexo-theme-diaspora")
+    console.log("%c Github %c", "background:#24272A; color:#ffffff", "", "https://github.com/Fechin/hexo-theme-diaspora")
 
 
 })
 })