PageSourceSearch

https://sungoal.org/assets/addons/cms/js/common.js?v=1791501192

js sungoal.org collected 2026-10-08 23:14:03 UTC 17,915 bytes, 468 lines download raw bytes

1$(function () {
2    window.isMobile = !!("ontouchstart" in window);
3
4    function AddFavorite(sURL, sTitle) {
5        if (/firefox/i.test(navigator.userAgent)) {
6            return false;
7        } else if (window.external && window.external.addFavorite) {
8            window.external.addFavorite(sURL, sTitle);
9            return true;
10        } else if (window.sidebar && window.sidebar.addPanel) {
11            window.sidebar.addPanel(sTitle, sURL, "");
12            return true;
13        } else {
14            var touch = (navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 'Command' : 'CTRL');
15            layer.msg('请使用 ' + touch + ' + D 添加到收藏夹.');
16            return false;
17        }
18    }
19
20    var len = function (str) {
21        if (!str)
22            return 0;
23        var length = 0;
24        for (var i = 0; i < str.length; i++) {
25            if (str.charCodeAt(i) >= 0x4e00 && str.charCodeAt(i) <= 0x9fa5) {
26                length += 2;
27            } else {
28                length++;
29            }
30        }
31        return length;
32    };
33
34    //new LazyLoad({elements_selector: ".lazy"});
35
36    layer.config({focusBtn: false});
37
38    //栏目高亮
39    var nav = $("header.header .navbar-nav");
40    if ($("li.active", nav).length === 0) {
41        var current = nav.data("current");
42        
43        var currentNav = $("a[href='" + location.href + "']", nav)[0] || $("a[href='" + location.pathname + "']", nav)[0] || $("li[value='" + current + "'] > a", nav)[0];
44        currentNav && $(currentNav, nav).parents("li").addClass("active");
45    }
46
47    $(".collapse.navbar-collapse.active").on("mousedown click", ".dropdown-menu .dropdown-submenu a[data-toggle='dropdown']", function (e) {
48        e.stopPropagation();
49    });
50
51    $("header.header .navbar-right").insertBefore($("header.header .navbar-right").prev());
52
53    //移动浏览器左右滑动
54    $(document).on('touchstart', '.carousel', function (event) {
55        const xClick = event.originalEvent.touches[0].pageX;
56        $(this).one('touchmove', function (event) {
57            const xMove = event.originalEvent.touches[0].pageX;
58            const sensitivityInPx = 5;
59
60            if (Math.floor(xClick - xMove) > sensitivityInPx) {
61                $(this).carousel('next');
62            } else if (Math.floor(xClick - xMove) < -sensitivityInPx) {
63                $(this).carousel('prev');
64            }
65        });
66        $(this).on('touchend', function () {
67            $(this).off('touchmove');
68        });
69    });
70
71    // 点击收藏
72    $(".addbookbark").attr("rel", "sidebar").click(function () {
73        //使用数据库收藏
74        CMS.api.ajax({
75            url: $(this).data("action"),
76            data: {type: $(this).data("type"), aid: $(this).data("aid")}
77        });
78        //使用浏览器收藏
79        //return !AddFavorite(window.location.href, $(this).attr("title"));
80    });
81
82    // 点赞
83    $(document).on("click", ".btn-like", function () {
84        var that = this;
85        var id = $(this).data("id");
86        var type = $(this).data("type");
87        if (CMS.api.storage(type + "vote." + id)) {
88            layer.msg("你已经点过赞了");
89            return false;
90        }
91        CMS.api.ajax({
92            data: $(this).data()
93        }, function (data, ret) {
94            $("span", that).text(type === 'like' ? ret.data.likes : ret.data.dislikes);
95            CMS.api.storage(type + "vote." + id, true);
96            return false;
97        }, function () {
98            return false;
99        });
100    });
101
102    // 加载更多
103    $(document).on("click", ".btn-loadmore", function () {
104        var that = this;
105        var page = parseInt($(this).data("page"));
106        var container = $(this).data("container");
107        container = container ? $(container) : $(".article-list,.product-list");
108        var loadmoreText = $(this).text();
109        $(that).text("正在加载").prop("disabled", true);
110        CMS.api.ajax({
111            url: $(that).attr("href"),
112        }, function (data, ret) {
113            if (data) {
114                $(data).appendTo(container);
115                page++;
116                $(that).attr("href", $(that).data("url").replace("__page__", page)).data("page", page);
117                $(that).text(loadmoreText).prop("disabled", false);
118            } else {
119                $(that).replaceWith('<div class="loadmore loadmore-line loadmore-nodata"><span class="loadmore-tips">暂无更多数据</span></div>');
120            }
121            return false;
122        }, function (data) {
123            $(that).text(loadmoreText).prop("disabled", false);
124        });
125        return false;
126    });
127
128    //滚动加载更多
129    $(window).scroll(function () {
130        var loadmore = $(".btn-loadmore");
131        if (loadmore.length > 0 && !loadmore.prop("disabled") && (loadmore.data("autoload") === undefined || loadmore.data("autoload"))) {
132            if ($(window).scrollTop() - loadmore.height() > loadmore.offset().top - $(window).height()) {
133                loadmore.trigger("click");
134            }
135        }
136    });
137    setTimeout(function () {
138        if ($(window).scrollTop() > 0) {
139            $(window).trigger("scroll");
140        }
141    }, 500);
142
143    //评论列表
144    if ($("#comment-container").length > 0) {
145        var ci, si;
146        $("#commentlist dl dd div,#commentlist dl dd dl dd").on({
147            mouseenter: function () {
148                clearTimeout(ci);
149                var _this = this;
150                ci = setTimeout(function () {
151                    $(_this).find("small:first").find("a").stop(true, true).css('display', 'inline-block');
152                }, 100);
153            },
154            mouseleave: function () {
155                clearTimeout(ci);
156                $(this).find("small:first").find("a").stop(true, true).fadeOut();
157            }
158        });
159        $(".reply").on("click", function () {
160            $("#pid").val($(this).data("id"));
161            $(this).parent().parent().append($("div#postcomment").detach());
162            $("#postcomment h3 a").show();
163            $("#commentcontent").focus().val($(this).attr("title"));
164        });
165        $("#postcomment h3 a").bind("click", function () {
166            $("#comment-container").append($("div#postcomment").detach());
167            $(this).hide();
168        });
169        $(".expandall a").on("click", function () {
170            $(this).parent().parent().find("dl.hide").fadeIn();
171            $(this).fadeOut();
172        });
173
174        $(document).on("click", "#submit", function () {
175            var btn = $(this);
176            var tips = $("#actiontips");
177            tips.removeClass();
178            var content = $("#commentcontent").val();
179            if (len(content) < 3) {
180                tips.addClass("text-danger").html("评论内容长度不正确!最少3个字符").fadeIn().change();
181                return false;
182            }
183            if (btn.prop("disabled")) {
184                return false;
185            }
186            var form = $("#postform");
187            btn.attr("disabled", "disabled");
188            tips.html('正在提交...');
189            $.ajax({
190                url: form.prop("action"),
191                type: 'POST',
192                data: form.serialize(),
193                dataType: 'json',
194                success: function (json) {
195                    btn.removeAttr("disabled");
196                    if (json.code == 1) {
197                        $("#pid").val(0);
198                        tips.addClass("text-success").html(json.msg || "评论成功!").fadeIn(300).change();
199                        $("#commentcontent").val('');
200                        $("#commentcount").text(parseInt($("#commentcount").text()) + 1);
201                        setTimeout(function () {
202                            location.reload();
203                        }, 1500);
204                    } else {
205                        tips.addClass("text-danger").html(json.msg).fadeIn();
206                    }
207                    if (json.data && json.data.token) {
208                        $("#postform input[name='__token__']").val(json.data.token);
209                    }
210                },
211                error: function () {
212                    btn.removeAttr("disabled");
213                    tips.addClass("text-danger").html("评论失败!请刷新页面重试!").fadeIn();
214                }
215            });
216            return false;
217        });
218        $("#commentcontent").on("keydown", function (e) {
219            if ((e.metaKey || e.ctrlKey) && (e.keyCode == 13 || e.keyCode == 10)) {
220                $("#submit").trigger('click');
221                return false;
222            }
223        });
224        $("#actiontips").on("change", function () {
225            clearTimeout(si);
226            si = setTimeout(function () {
227                $("#actiontips").fadeOut();
228            }, 8000);
229        });
230        $(document).on("keyup change", "#commentcontent", function (e) {
231            if (e.metaKey || e.ctrlKey || [13, 10, 18, 91].indexOf(e.keyCode) > -1) {
232                return false;
233            }
234            var max = 1000;
235            var c = $(this).val();
236            var length = len(c);
237            var t = $("#actiontips");
238            if (max >= length) {
239                t.removeClass().show().addClass("loading").html("你还可以输入 <font color=green>" + (Math.floor((max - length) / 2)) + "</font> 字");
240                $("#submit").removeAttr("disabled");
241            } else {
242                t.removeClass().show().addClass("loading").html("你已经超出 <font color=red>" + (Math.ceil((length - max) / 2)) + "</font> 字");
243                $("#submit").attr("disabled", "disabled");
244            }
245        });
246    }
247    // 余额支付提示
248    $(document).on('click', '.btn-balance', function (e) {
249        var that = this;
250        layer.confirm("确认支付¥" + $(this).data("price") + "元用于购买?", function () {
251            CMS.api.ajax({
252                url: $(that).attr("href")
253            }, function (data, ret) {
254                CMS.api.msg(ret.msg, ret.url);
255            }, function (data, ret) {
256                if (ret.msg && ret.msg.indexOf("登录") > -1) {
257                    layer.alert(ret.msg, {btn: ["去登录", "暂不登录"]}, function () {
258                        location.href = ret.url;
259                    });
260                    return false;
261                }
262            });
263        });
264        return false;
265    });
266    // 回到顶部
267    $('#back-to-top').on('click', function (e) {
268        e.preventDefault();
269        $('html,body').animate({
270            scrollTop: 0
271        }, 700);
272    });
273
274    //如果是PC则移除navbar的dropdown点击事件
275    if (!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobi/i.test(navigator.userAgent)) {
276        $("#navbar-collapse [data-toggle='dropdown']").removeAttr("data-toggle");
277    } else {
278        $(".navbar-nav ul li:not(.dropdown-submenu):not(.dropdown) a").removeAttr("data-toggle");
279    }
280
281    if (!isMobile) {
282        var search = $("#searchinput");
283        var form = search.closest("form");
284        search.autoComplete({
285            minChars: 1,
286            cache: false,
287            menuClass: 'autocomplete-searchmenu',
288            header: '',
289            footer: '',
290            source: function (term, response) {
291                try {
292                    xhr.abort();
293                } catch (e) {
294                }
295                xhr = $.getJSON(search.data("suggestion-url"), {q: term}, function (data) {
296                    response(data);
297                });
298            },
299            onSelect: function (e, term, item) {
300                if (typeof callback === 'function') {
301                    callback.call(elem, term, item);
302                } else {
303                    form.trigger("submit");
304                }
305            }
306        });
307    }
308
309    // 手机端左右滑动切换菜单栏
310    if (isMobile && 'ontouchstart' in document.documentElement) {
311        var startX, startY, moveEndX, moveEndY, relativeX, relativeY, element;
312        element = $('#navbar-collapse');
313        $("body").on("touchstart", function (e) {
314            startX = e.originalEvent.changedTouches[0].pageX;
315            startY = e.originalEvent.changedTouches[0].pageY;
316        });
317        $("body").on("touchend", function (e) {
318            moveEndX = e.originalEvent.changedTouches[0].pageX;
319            moveEndY = e.originalEvent.changedTouches[0].pageY;
320            relativeX = moveEndX - startX;
321            relativeY = moveEndY - startY;
322
323            //右滑
324            if (relativeX > 45) {
325                if ((Math.abs(relativeX) - Math.abs(relativeY)) > 50 && !element.hasClass("active") && startX < ($(window).width() / 4)) {
326                    $(".sidebar-toggle").trigger("click");
327                }
328            }
329            //左滑
330            else if (relativeX < -45) {
331                if ((Math.abs(relativeX) - Math.abs(relativeY)) > 50 && element.hasClass("active")) {
332                    $(".sidebar-toggle").trigger("click");
333                }
334            }
335        });
336    }
337
338    // 打赏
339    $(".btn-donate").popover({
340        trigger: 'hover',
341        placement: 'top',
342        html: true,
343        content: function () {
344            return "<img src='" + $(this).data("image") + "' width='250' height='250'/>";
345        }
346    });
347    $(document).on("click", ".btn-paynow", function () {
348        var paytype = $(this).data("paytype");
349        var price = $(this).data("price");
350        var nameArr = {wechat: "微信", alipay: "支付宝", balance: "余额"};
351        var that = this;
352        var tips = function () {
353            layer.confirm("请根据支付状态选择下面的操作按钮", {title: "温馨提示", icon: 0, btn: ["支付成功", "支付失败"]}, function () {
354                location.reload();
355            });
356        };
357        if (paytype) {
358            layer.confirm("确认使用" + (typeof nameArr[paytype] !== 'undefined' ? nameArr[paytype] : "未知") + "进行支付?<br>支付金额:¥" + price + "元", {title: "温馨提示", icon: 3, focusBtn: false, btn: ["立即支付", "取消支付"]}, function (index, layero) {
359                $(".layui-layer-btn0", layero).attr("href", $(that).attr("href")).attr("target", "_blank");
360                tips();
361            });
362            return false;
363        } else {
364            tips();
365        }
366    });
367
368    //点击切换
369    $(document).on("click", ".sidebar-toggle", function () {
370        var collapse = $("#navbar-collapse");
371        if (collapse.hasClass("active")) {
372            $(".navbar-collapse-bg").remove();
373        } else {
374            $("<div />").addClass("navbar-collapse-bg").insertAfter(collapse).on("click", function () {
375                $(".sidebar-toggle").trigger("click");
376            });
377        }
378        collapse.toggleClass("active");
379        $(this).toggleClass("active");
380    });
381
382    //内容中的图片点击事件
383    $(document).on("click", ".article-text img", function () {
384        if ($(this).closest("a").length > 0) {
385            return;
386        }
387        var that = this;
388        var data = [];
389        var index = 0;
390        $(".article-text img").each(function (i, j) {
391            if (that == this) {
392                index = i;
393            }
394            data.push({
395                "src": $(this).attr("src") //原图地址
396            });
397        });
398        layer.photos({
399            photos: {
400                "start": index, "data": data
401            },
402            // scrollbar: true,
403            // full: true,
404            // closeBtn: 1
405        });
406        return false;
407    });
408
409    //分享参数配置
410    var shareConfig = {
411        title: $("meta[property='og:title']").attr("content") || document.title,
412        description: $("meta[property='og:description']").attr("content") || $("meta[name='description']").attr("content") || "",
413        url: $("meta[property='og:url']").attr("content") || location.href,
414        image: $("meta[property='og:image']").attr("content") || ""
415    };
416
417    //微信公众号内分享
418    if (typeof wx != 'undefined') {
419        shareConfig.url = location.href;
420        CMS.api.ajax({
421                url: "/addons/cms/ajax/share",
422                data: {url: shareConfig.url},
423                loading: false
424            }, function (data, ret) {
425                try {
426                    wx.config({
427                        appId: data.appId,
428                        timestamp: data.timestamp,
429                        nonceStr: data.nonceStr,
430                        signature: data.signature,
431                        jsApiList: [
432                            'checkJsApi',
433                            'updateAppMessageShareData',
434                            'updateTimelineShareData',
435                        ]
436                    });
437                    var shareData = {
438                        title: shareConfig.title,
439                        desc: shareConfig.description,
440                        link: shareConfig.url,
441                        imgUrl: shareConfig.image,
442                        success: function () {
443                            layer.closeAll();
444                        },
445                        cancel: function () {
446                            layer.closeAll();
447                        }
448                    };
449                    wx.ready(function () {
450                        wx.updateAppMessageShareData(shareData);
451                        wx.updateTimelineShareData(shareData);
452                    });
453
454                } catch (e) {
455                    console.log(e);
456                }
457                return false;
458            }, function () {
459                return false;
460            }
461        );
462
463        $(".social-share").on("click", ".icon-wechat", function () {
464            layer.msg("请点击右上角的●●●进行分享");
465            return false;
466        }).find(".wechat-qrcode").remove();
467    }
468});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.