From dd0acbbdf64db67bb279b06cda470e753f125e62 Mon Sep 17 00:00:00 2001 From: Seaton Jiang Date: Fri, 20 Aug 2021 12:51:42 +0800 Subject: [PATCH] refactor: formatting code --- assets/js/kratos.js | 422 +++++++++++++++++++--------------------- assets/js/widget.min.js | 17 +- 2 files changed, 220 insertions(+), 219 deletions(-) diff --git a/assets/js/kratos.js b/assets/js/kratos.js index 12e2d3d..874d3b9 100644 --- a/assets/js/kratos.js +++ b/assets/js/kratos.js @@ -2,228 +2,214 @@ * Kratos * Seaton Jiang */ -(function () { - "use strict"; +;(function () { + 'use strict' - var KRATOS_VERSION = "3.3.4"; + var KRATOS_VERSION = '3.3.4' - var navbarConfig = function () { - $("#navbutton").on("click", function () { - $(".navbar-toggler").toggleClass("nav-close"); - }); - }; + var navbarConfig = function () { + $('#navbutton').on('click', function () { + $('.navbar-toggler').toggleClass('nav-close') + }) + } + + var tooltipConfig = function () { + $(function () { + $('[data-toggle="tooltip"]').tooltip() + }) + } + + var gotopConfig = function () { + $(window).on('load', function () { + var $win = $(window) + var setShowOrHide = function () { + if ($win.scrollTop() > 200) { + $('.gotop').addClass('active') + } else { + $('.gotop').removeClass('active') + } + } + setShowOrHide() + $win.scroll(setShowOrHide) + }) + $('.gotop').on('click', function (event) { + event.preventDefault() + $('html, body').animate( + { + scrollTop: $('html').offset().top + }, + 500 + ) + return false + }) + } + + var searchConfig = function () { + $('.search').on('click', function (e) { + $('.search-form').animate( + { + width: '200px' + }, + 200 + ), + $('.search-form input').css('display', 'block') + $(document).one('click', function () { + $('.search-form').animate( + { + width: '0' + }, + 100 + ), + $('.search-form input').hide() + }) + e.stopPropagation() + }) + $('.search-form').on('click', function (e) { + e.stopPropagation() + }) + } + + var wechatConfig = function () { + $('.wechat').mouseout(function () { + $('.wechat-pic')[0].style.display = 'none' + }) + $('.wechat').mouseover(function () { + $('.wechat-pic')[0].style.display = 'block' + }) + } + + var smiliesConfig = function () { + $('#addsmile').on('click', function (e) { + $('.smile').toggleClass('open') + $(document).one('click', function () { + $('.smile').toggleClass('open') + }) + e.stopPropagation() + return false + }) + } + + var postlikeConfig = function () { + $.fn.postLike = function () { + if ($(this).hasClass('done')) { + layer.msg(kratos.repeat, function () {}) + return false + } else { + $(this).addClass('done') + layer.msg(kratos.thanks) + var id = $(this).data('id'), + action = $(this).data('action') + var ajax_data = { + action: 'love', + um_id: id, + um_action: action + } + $.post(kratos.site + '/wp-admin/admin-ajax.php', ajax_data, function (data) {}) + return false + } + } + $(document).on('click', '.btn-thumbs', function () { + $(this).postLike() + }) + } + + var donateConfig = function () { + $('#donate').on('click', function () { + layer.open({ + type: 1, + area: ['300px', '370px'], + title: kratos.donate, + resize: false, + scrollbar: false, + content: + '' + }) + $(".choose-pay input[type='radio']").click(function () { + var id = $(this).attr('id') + if (id == 'alipay') { + $('.qr-pay #alipay_qr').removeClass('d-none') + $('.qr-pay #wechat_qr').addClass('d-none') + } + if (id == 'wechatpay') { + $('.qr-pay #alipay_qr').addClass('d-none') + $('.qr-pay #wechat_qr').removeClass('d-none') + } + }) + }) + } + + var accordionConfig = function () { + $(document).on('click', '.acheader', function (event) { + var $this = $(this) + $this.closest('.accordion').find('.contents').slideToggle(300) + if ($this.closest('.accordion').hasClass('active')) { + $this.closest('.accordion').removeClass('active') + } else { + $this.closest('.accordion').addClass('active') + } + event.preventDefault() + }) + } + + var consoleConfig = function () { + console.log('\n Kratos v' + KRATOS_VERSION + '\n\n https://github.com/vtrois/kratos \n\n') + } + + var lightGalleryConfig = function () { + lightGallery(document.getElementById('lightgallery'), { + selector: 'a' + }) + } - var tooltipConfig = function () { $(function () { - $('[data-toggle="tooltip"]').tooltip(); - }); - }; - - var gotopConfig = function () { - $(window).on("load", function () { - var $win = $(window); - var setShowOrHide = function(){ - if ($win.scrollTop() > 200) { - $(".gotop").addClass("active"); - } else { - $(".gotop").removeClass("active"); - } - } - setShowOrHide(); - $win.scroll(setShowOrHide); - }); - $(".gotop").on("click", function (event) { - event.preventDefault(); - $("html, body").animate( - { - scrollTop: $("html").offset().top, - }, - 500 - ); - return false; - }); - }; - - var searchConfig = function () { - $(".search").on("click", function (e) { - $(".search-form").animate( - { - width: "200px", - }, - 200 - ), - $(".search-form input").css("display", "block"); - $(document).one("click", function () { - $(".search-form").animate( - { - width: "0", - }, - 100 - ), - $(".search-form input").hide(); - }); - e.stopPropagation(); - }); - $(".search-form").on("click", function (e) { - e.stopPropagation(); - }); - }; - - var wechatConfig = function () { - $(".wechat").mouseout(function () { - $(".wechat-pic")[0].style.display = "none"; - }); - $(".wechat").mouseover(function () { - $(".wechat-pic")[0].style.display = "block"; - }); - }; - - var smiliesConfig = function () { - $("#addsmile").on("click", function (e) { - $(".smile").toggleClass("open"); - $(document).one("click", function () { - $(".smile").toggleClass("open"); - }); - e.stopPropagation(); - return false; - }); - }; - - var postlikeConfig = function () { - $.fn.postLike = function () { - if ($(this).hasClass("done")) { - layer.msg(kratos.repeat, function () {}); - return false; - } else { - $(this).addClass("done"); - layer.msg(kratos.thanks); - var id = $(this).data("id"), - action = $(this).data("action"); - var ajax_data = { - action: "love", - um_id: id, - um_action: action, - }; - $.post( - kratos.site + "/wp-admin/admin-ajax.php", - ajax_data, - function (data) {} - ); - return false; - } - }; - $(document).on("click", ".btn-thumbs", function () { - $(this).postLike(); - }); - }; - - var donateConfig = function () { - $("#donate").on("click", function () { - layer.open({ - type: 1, - area: ["300px", "370px"], - title: kratos.donate, - resize: false, - scrollbar: false, - content: - '', - }); - $(".choose-pay input[type='radio']").click(function () { - var id = $(this).attr("id"); - if (id == "alipay") { - $(".qr-pay #alipay_qr").removeClass("d-none"); - $(".qr-pay #wechat_qr").addClass("d-none"); - } - if (id == "wechatpay") { - $(".qr-pay #alipay_qr").addClass("d-none"); - $(".qr-pay #wechat_qr").removeClass("d-none"); - } - }); - }); - }; - - var accordionConfig = function () { - $(document).on("click", ".acheader", function (event) { - var $this = $(this); - $this.closest(".accordion").find(".contents").slideToggle(300); - if ($this.closest(".accordion").hasClass("active")) { - $this.closest(".accordion").removeClass("active"); - } else { - $this.closest(".accordion").addClass("active"); - } - event.preventDefault(); - }); - }; - - var consoleConfig = function () { - console.log( - "\n Kratos v" + - KRATOS_VERSION + - "\n\n https://github.com/vtrois/kratos \n\n" - ); - }; - - var lightGalleryConfig = function () { - lightGallery(document.getElementById("lightgallery"), { - selector: "a", - }); - }; - - $(function () { - accordionConfig(); - navbarConfig(); - tooltipConfig(); - gotopConfig(); - searchConfig(); - wechatConfig(); - smiliesConfig(); - postlikeConfig(); - donateConfig(); - consoleConfig(); - lightGalleryConfig(); - }); -})(); + accordionConfig() + navbarConfig() + tooltipConfig() + gotopConfig() + searchConfig() + wechatConfig() + smiliesConfig() + postlikeConfig() + donateConfig() + consoleConfig() + lightGalleryConfig() + }) +})() function grin(tag) { - var myField; - tag = " " + tag + " "; - if ( - document.getElementById("comment") && - document.getElementById("comment").type == "textarea" - ) { - myField = document.getElementById("comment"); - } else { - return false; - } - if (document.selection) { - myField.focus(); - sel = document.selection.createRange(); - sel.text = tag; - myField.focus(); - } else if (myField.selectionStart || myField.selectionStart == "0") { - var startPos = myField.selectionStart; - var endPos = myField.selectionEnd; - var cursorPos = endPos; - myField.value = - myField.value.substring(0, startPos) + - tag + - myField.value.substring(endPos, myField.value.length); - cursorPos += tag.length; - myField.focus(); - myField.selectionStart = cursorPos; - myField.selectionEnd = cursorPos; - } else { - myField.value += tag; - myField.focus(); - } + var myField + tag = ' ' + tag + ' ' + if (document.getElementById('comment') && document.getElementById('comment').type == 'textarea') { + myField = document.getElementById('comment') + } else { + return false + } + if (document.selection) { + myField.focus() + sel = document.selection.createRange() + sel.text = tag + myField.focus() + } else if (myField.selectionStart || myField.selectionStart == '0') { + var startPos = myField.selectionStart + var endPos = myField.selectionEnd + var cursorPos = endPos + myField.value = myField.value.substring(0, startPos) + tag + myField.value.substring(endPos, myField.value.length) + cursorPos += tag.length + myField.focus() + myField.selectionStart = cursorPos + myField.selectionEnd = cursorPos + } else { + myField.value += tag + myField.focus() + } } diff --git a/assets/js/widget.min.js b/assets/js/widget.min.js index 4efc70e..e93a063 100644 --- a/assets/js/widget.min.js +++ b/assets/js/widget.min.js @@ -1 +1,16 @@ -jQuery(document).ready(function($){$(document).on("click","button[class*='upload_']",function(e){e.preventDefault();var $button=$(this);if(file_frame){file_frame.open();return}var file_frame=wp.media.frames.file_frame=wp.media({library:{type:'image'},multiple:false});file_frame.on('select',function(){var attachment=file_frame.state().get('selection').first().toJSON();$button.siblings('input').val(attachment.url).change();});file_frame.open()})}); \ No newline at end of file +jQuery(document).ready(function ($) { + $(document).on('click', "button[class*='upload_']", function (e) { + e.preventDefault() + var $button = $(this) + if (file_frame) { + file_frame.open() + return + } + var file_frame = (wp.media.frames.file_frame = wp.media({ library: { type: 'image' }, multiple: false })) + file_frame.on('select', function () { + var attachment = file_frame.state().get('selection').first().toJSON() + $button.siblings('input').val(attachment.url).change() + }) + file_frame.open() + }) +})