titokkf.cc
Open in
urlscan Pro
2606:4700:3031::ac43:9db6
Public Scan
Submitted URL: http://titokkf.cc/static_new/js/dialog.min.js
Effective URL: https://titokkf.cc/static_new/js/dialog.min.js
Submission: On March 31 via api from US — Scanned from US
Effective URL: https://titokkf.cc/static_new/js/dialog.min.js
Submission: On March 31 via api from US — Scanned from US
Form analysis
0 forms found in the DOMText Content
/** * @TODO: */ ;(function($, window, document, undefined) { 'use strict'; var Dialog = (function() { /** * å¼¹çª—æž„é€ å‡½æ•° * @param {dom obj} element 调用对象 * @param {json obj} options 弹窗é…置项 */ function Dialog(element, options) { this.$element = $(element); this.settings = $.extend({}, $.fn.dialog.defaults, options); } Dialog.prototype = { /** * åˆå§‹åŒ–弹窗 */ _init: function() { var self = this; clearTimeout(self.autoCloseTimer); self.isHided = false; // 是å¦å·²ç»éšè— self.tapBug = self._hasTapBug(); // 是å¦æœ‰ç‚¹é€ BUG self.platform = mobileUtil.platform; // è®¿é—®è®¾å¤‡å¹³å° self.dislogStyle = self.settings.style==='default' ? self.platform : self.settings.style; // å¼¹çª—é£Žæ ¼, 默认自动判æ–å¹³å°; å¦åˆ™, ä¸ºæŒ‡å®šå¹³å° // 创建弹窗显示时, ç¦æ¢ body å†…å®¹æ»šåŠ¨çš„æ ·å¼å¹¶ä¸”æ·»åŠ åˆ° head if ($('#dialog-body-no-scroll').length === 0) { var styleContent = '.body-no-scroll { position: absolute; overflow: hidden; width: 100%; }'; $('head').append('<style id="dialog-body-no-scroll">'+ styleContent +'</style>'); } self._renderDOM(); self._bindEvents(); }, /** * 渲染弹窗 DOM 结构 */ _renderDOM: function() { var self = this; self.settings.onBeforeShow(); self._createDialogDOM(self.settings.type); self.settings.onShow(); }, /** * 绑定弹窗相关事件 */ _bindEvents: function() { var self = this; // 确定按钮关é—弹窗 self.$confirmBtn.bind('click', function() { var callback = self.settings.onClickConfirmBtn(); if (callback || callback === undefined) { self.closeDialog(); } }); // å–消按钮关é—弹窗 self.$cancelBtn.bind('click', function(ev) { var callback = self.settings.onClickCancelBtn(); if (callback || callback === undefined) { self.closeDialog(); } }); // å…³é—按钮关é—弹窗 self.$closeBtn.on(mobileUtil.tapEvent, function(ev) { var callback = self.settings.onClickCloseBtn(); if (callback || callback === undefined) { self.closeDialog(); } }).on('touchend', function(ev) { ev.preventDefault(); }); // é®ç½©å±‚å…³é—弹窗 if (self.settings.overlayClose) { $(document).on(mobileUtil.tapEvent, '.dialog-overlay', function(ev) { self.closeDialog(); }); } // 自动关é—弹窗 if(self.settings.autoClose > 0){ self._autoClose(); } // åˆ é™¤å¼¹çª—å’Œ tap ç‚¹é€ BUG é®ç½©å±‚, 在éšè—弹窗的动画结æŸåŽæ‰§è¡Œ $(document).on('webkitAnimationEnd MSAnimationEnd animationend', '.dialog-content', function() { if (self.isHided) { self.removeDialog(); if (self.tapBug) { self._removeTapOverlayer(); } } }); // 为自定义按钮组绑定回调函数 if (self.settings.buttons.length) { $.each(self.settings.buttons, function(index, item) { self.$dialogContentFt.children('button').eq(index).on(mobileUtil.tapEvent, function(ev) { ev.preventDefault(); var callback = item.callback(); if (callback || callback === undefined) { self.closeDialog(); } }); }); } // 如果弹窗有最大高度设置项, 在窗å£å¤§å°æ”¹å˜æ—¶, é‡æ–°è®¾ç½®å¼¹çª—最大高度 $(window).on("onorientationchange" in window ? "orientationchange" : "resize", function() { if (self.settings.contentScroll) { setTimeout(function() { self._resetDialog(); }, 200); } }); // é˜»æ¢ body 内容滑动 $(document).on('touchmove', function(e) { if (self.$dialog.find($(e.target)).length){ return false; } else { return true; } }); // 弹窗有最大高度设置项, 设置æ示内容滑动 if (self.settings.contentScroll) { self._contentScrollEvent(); } }, /** * æ ¹æ®å¼¹çª—类型, 创建弹窗 DOM 结构 * @param {string} dialogType 弹窗类型 */ _createDialogDOM: function(dialogType) { var self = this; self.$dialog = $('<div class="dialog dialog-open '+ self.settings.dialogClass +'" data-style="'+ self.dislogStyle +'"></div>'); self.$dialogOverlay = $('<div class="dialog-overlay"></div>'); self.$dialogContent = $('<div class="dialog-content"></div>'); self.$dialogTitle = $('<div class="dialog-content-hd"><h3 class="dialog-content-title">'+ self.settings.titleText +'</h3></div>'); self.$dialogContentFt = $('<div class="dialog-content-ft"></div>'); self.$dialogContentBd = $('<div class="dialog-content-bd"></div>'); self.$closeBtn = $('<div class="dialog-btn-close"><span>close</span></div>'); self.$confirmBtn = $('<button class="dialog-btn dialog-btn-confirm '+ self.settings.buttonClassConfirm +'">'+ self.settings.buttonTextConfirm +'</button>'); self.$cancelBtn = $('<button class="dialog-btn dialog-btn-cancel '+ self.settings.buttonClassCancel +'">'+ self.settings.buttonTextCancel +'</button>'); switch(dialogType) { case 'alert': // æ·»åŠ alert ç±»åž‹å¼¹çª—æ ‡è¯† self.$dialog.addClass('dialog-modal'); // 显示é®ç½©å±‚ if (self.settings.overlayShow) { self.$dialog.append(self.$dialogOverlay); } // æ˜¾ç¤ºæ ‡é¢˜ if (self.settings.titleShow) { self.$dialogContent.append(self.$dialogTitle); } // 显示关é—按钮 if (self.settings.closeBtnShow) { self.$dialogTitle.append(self.$closeBtn); } self.$dialogContentBd.html(self.settings.content); self.$dialogContentFt.append(self.$confirmBtn); self.$dialogContent.append(self.$dialogContentBd).append(self.$dialogContentFt); self.$dialog.append(self.$dialogContent); $('body').append(self.$dialog); if (self.settings.bodyNoScroll) { $('body').addClass('body-no-scroll'); } // 设置弹窗æ示内容最大高度 if (self.settings.contentScroll) { self._setDialogContentHeight(); } break; case 'confirm': // æ·»åŠ confirm ç±»åž‹å¼¹çª—æ ‡è¯† self.$dialog.addClass('dialog-modal'); // 显示é®ç½©å±‚ if (self.settings.overlayShow) { self.$dialog.append(self.$dialogOverlay); } // æ˜¾ç¤ºæ ‡é¢˜ if (self.settings.titleShow) { self.$dialogContent.append(self.$dialogTitle); } // 显示关é—按钮 if (self.settings.closeBtnShow) { self.$dialogTitle.append(self.$closeBtn); } // 按钮: 如果有设置自定义按钮组, 则用自定义按钮组; å¦åˆ™ç”¨é»˜è®¤çš„"确定"与"å–消"按钮 if (self.settings.buttons.length) { var buttonGroupHtml = ''; $.each(self.settings.buttons, function(index, item) { buttonGroupHtml += '<button class="dialog-btn '+ item.class +'">'+ item.name +'</button>'; }); self.$dialogContentFt.append(buttonGroupHtml).addClass(self.settings.buttonStyle); } else { self.$dialogContentFt.append(self.$cancelBtn).append(self.$confirmBtn).addClass(self.settings.buttonStyle); } self.$dialogContentBd.html(self.settings.content); self.$dialogContent.append(self.$dialogContentBd).append(self.$dialogContentFt); self.$dialog.append(self.$dialogContent); $('body').append(self.$dialog); // 设置弹窗æ示内容最大高度 if (self.settings.contentScroll) { self._setDialogContentHeight(); } if (self.settings.bodyNoScroll) { $('body').addClass('body-no-scroll'); } break; case 'toast': // æ·»åŠ toast ç±»åž‹å¼¹çª—æ ‡è¯† self.$dialog.addClass('dialog-toast'); // 显示é®ç½©å±‚ if (self.settings.overlayShow) { self.$dialog.append(self.$dialogOverlay); } // 弹窗内容 HTML, 默认为 content; 如果设置 icon 与 text, 则覆盖 content 的设置 var toastContentHtml = $(self.settings.content); if (self.settings.infoIcon !== '' && self.settings.infoText !== '') { toastContentHtml = $('<img class="info-icon" src="'+ self.settings.infoIcon + '" /><span class="info-text">'+ self.settings.infoText +'</span>'); } else if (self.settings.infoIcon === '' && self.settings.infoText !== '') { toastContentHtml = $('<span class="info-text">'+ self.settings.infoText +'</span>'); } else if (self.settings.infoIcon !== '' && self.settings.infoText === '') { toastContentHtml = $('<img class="info-icon" src="'+ self.settings.infoIcon + '" />'); } self.$dialogContentBd.append(toastContentHtml); self.$dialogContent.append(self.$dialogContentBd); self.$dialog.append(self.$dialogContent); $('body').append(self.$dialog); if (self.settings.bodyNoScroll) { $('body').addClass('body-no-scroll'); } break; case 'notice': // æ·»åŠ toast ç±»åž‹å¼¹çª—æ ‡è¯† self.$dialog.addClass('dialog-notice'); // 底部显示的 toast if (self.settings.position==='bottom') { self.$dialog.addClass('dialog-notice-bottom'); } // 显示é®ç½©å±‚ if (self.settings.overlayShow) { self.$dialog.append(self.$dialogOverlay); } // 弹窗内容 HTML, 默认为 content; 如果设置 icon 与 text, 则覆盖 content 的设置 var noticeContentHtml = $(self.settings.content); if (self.settings.infoIcon !== '' && self.settings.infoText !== '') { noticeContentHtml = $('<img class="info-icon" src="'+ self.settings.infoIcon + '" /><span class="info-text">'+ self.settings.infoText +'</span>'); } else if (self.settings.infoIcon === '' && self.settings.infoText !== '') { noticeContentHtml = $('<span class="info-text">'+ self.settings.infoText +'</span>'); } else if (self.settings.infoIcon !== '' && self.settings.infoText === '') { noticeContentHtml = $('<img class="info-icon" src="'+ self.settings.infoIcon + '" />'); } self.$dialogContentBd.append(noticeContentHtml); self.$dialogContent.append(self.$dialogContentBd); self.$dialog.append(self.$dialogContent); $('body').append(self.$dialog); if (self.settings.bodyNoScroll) { $('body').addClass('body-no-scroll'); } break; default: break; } }, /** * 设置弹窗内容最大高度 * 延迟执行, é¿å…获å–相关尺寸ä¸æ£ç¡® */ _setDialogContentHeight: function() { var self = this; setTimeout(function() { var dialogDefaultContentHeight = self.$dialogContentBd.height(); var dialogContentMaxHeight = self._getDialogContentMaxHeight(); self.$dialogContentBd.css({ 'max-height': dialogContentMaxHeight, }).addClass('content-scroll'); // æ示内容大于最大高度时, æ·»åŠ åº•éƒ¨æŒ‰é’®é¡¶éƒ¨è¾¹æ¡†çº¿æ ‡è¯† class; å之, åˆ é™¤ if (dialogDefaultContentHeight > dialogContentMaxHeight) { self.$dialogContentFt.addClass('dialog-content-ft-border'); } else { self.$dialogContentFt.removeClass('dialog-content-ft-border'); } }, 80); }, /** * 获å–弹窗内容最大高度 * @return height */ _getDialogContentMaxHeight: function() { var self = this; var winHeight = $(window).height(), dialogContentHdHeight = self.$dialogTitle.height(), dialogContentFtHeight = self.$dialogContentFt.height(), dialogContentBdHeight = winHeight - dialogContentHdHeight - dialogContentFtHeight - 60; // 最大高度å–å¶æ•° dialogContentBdHeight = dialogContentBdHeight%2===0 ? dialogContentBdHeight : dialogContentBdHeight - 1; return dialogContentBdHeight; }, /** * é‡ç½®å¼¹çª—, 在窗å£å¤§å°å‘生å˜åŒ–æ—¶è§¦å‘ */ _resetDialog: function() { var self = this; self._setDialogContentHeight(); }, /** * 有最大高度弹窗的æ示内容滑动 */ _contentScrollEvent: function() { var self = this; var isTouchDown = false; // åˆå§‹ä½ç½® var position = { x: 0, y: 0, top: 0, left: 0 }; // 监å¬æ»‘动相关事件 $(document) .on('touchstart mousedown', '.content-scroll', function(ev) { var touch = ev.changedTouches ? ev.changedTouches[0] : ev; isTouchDown = true; position.x = touch.clientX; position.y = touch.clientY; position.top = $(this).scrollTop(); position.left = $(this).scrollLeft(); return false; }) .on('touchmove mousemove', '.content-scroll', function(ev) { var touch = ev.changedTouches ? ev.changedTouches[0] : ev; if (!isTouchDown) { // 未按下 return false; } else { // è¦æ»‘动的è·ç¦» = å·²ç»æ»‘动的è·ç¦» - (当å‰åæ ‡ - 按下åæ ‡) var moveTop = position.top - (touch.clientY - position.y); var moveLeft = position.left - (touch.clientX - position.x); $(this).scrollTop(moveTop).scrollLeft(moveLeft); } }) .on('touchend mouseup', '.content-scroll', function(ev) { ev.preventDefault(); isTouchDown = false; }); }, /** * 自动关é—弹窗 */ _autoClose: function() { var self = this; self.autoCloseTimer = setTimeout(function(){ self.closeDialog(); }, self.settings.autoClose); }, /** * å…³é—弹窗 */ closeDialog: function() { var self = this; self.isHided = true; self.settings.onBeforeClosed(); self.$dialog.addClass('dialog-close').removeClass('dialog-open'); if (self.tapBug) { self._appendTapOverlayer(); } }, /** * åˆ é™¤å¼¹çª— * @public method */ removeDialog: function() { var self = this; self.$dialog.remove(); self.isHided = false; self.settings.onClosed(); // é‡æ–°åˆå§‹åŒ–默认é…ç½® self.settings = $.fn.dialog.defaults; if (self.settings.bodyNoScroll) { $('body').removeClass('body-no-scroll'); } }, /** * 更改 toast å’Œ notice 类型弹窗内容 * @public method * @param {string} content 弹窗内容, å¯ä»¥æ˜¯HTML * @param {string} infoIcon 弹窗æç¤ºå›¾æ ‡ * @param {string} infoText 弹窗æç¤ºæ–‡å— * @param {int} autoClose 自动关é—的延迟时间 * @param {fn} onBeforeClosed å…³é—å‰å›žè°ƒå‡½æ•° * @param {fn} onClosed å…³é—åŽå›žè°ƒå‡½æ•° */ update: function (settings) { var self = this; clearTimeout(self.autoCloseTimer); // 设置默认值,并且指å‘给对象的默认值 self.settings = $.extend({}, $.fn.dialog.defaults, settings); // 通过 content 更改弹窗内容 if (self.settings.content !== '') { self.$dialogContentBd.html(self.settings.content); } // 通过设置 infoIcon 与 infoText 更改弹窗内容, 会覆盖 content 的设置 var $infoIcon = self.$dialogContentBd.find('.info-icon'); var $infoText = self.$dialogContentBd.find('.info-text'); $infoIcon.attr({'src': self.settings.infoIcon}); $infoText.html(self.settings.infoText); // é‡æ–°ä¸ºæ›´æ”¹åŽçš„ DOM å…ƒç´ ç»‘å®šäº‹ä»¶ self._bindEvents(); }, /** * 是å¦æœ‰ç‚¹é€ BUG * æ¡ä»¶: 安å“手机并且版本å·å°äºŽ4.4 * @return Boolean */ _hasTapBug: function() { return mobileUtil.isAndroid && (mobileUtil.version < 4.4); }, /** * æ·»åŠ ç‚¹é€é®ç½©å±‚, è§£å†³ç‚¹é€ BUG */ _appendTapOverlayer: function() { var self = this; self.$tapBugOverlayer = $('.solve-tap-bug'); if (!self.$tapBugOverlayer.length) { self.$tapBugOverlayer = $('<div class="solve-tap-bug" style="margin:0;padding:0;border:0;background:rgba(0,0,0,0);-webkit-tap-highlight-color:rgba(0,0,0,0);width:100%;height:100%;position:fixed;top:0;left:0;"></div>'); $('body').append(self.$tapBugOverlayer); } }, /** * åˆ é™¤ç‚¹é€é®ç½©å±‚, 延迟执行的时间大于移动端的 click 触å‘时间 */ _removeTapOverlayer: function() { var self = this; setTimeout(function() { self.$tapBugOverlayer.remove(); }, 350); } }; return Dialog; })(); /**---------------------------- * ç§æœ‰æ–¹æ³• ----------------------------*/ /** * ç§»åŠ¨ç«¯ç›¸å…³æ•°æ® =>> mobileUtil 对象 * 是å¦æ˜¯å®‰å“ : isAndroid * 是å¦æ˜¯IOS : isIOS * 是å¦æ˜¯ç§»åŠ¨ç«¯: isMobile * è®¾å¤‡å¹³å° : platform [ ios 或 android ] * 事件类型 : tapEvent [ tapEvent 或 click ] * ç³»ç»Ÿç‰ˆæœ¬å· : version [ 如: ios 9.1 或 andriod 6.0 ] * 是å¦æ”¯æŒ touch 事件: isSupportTouch */ var mobileUtil = (function(window) { var UA = window.navigator.userAgent, isAndroid = /android|adr/gi.test(UA), isIOS = /iphone|ipod|ipad/gi.test(UA) && !isAndroid, isMobile = isAndroid || isIOS, platform = isIOS ? 'ios' : (isAndroid ? 'android' : 'default'), isSupportTouch = "ontouchend" in document ? true : false; var reg = isIOS ? (/os [\d._]*/gi):(/android [\d._]*/gi), verinfo = UA.match(reg), version = (verinfo+"").replace(/[^0-9|_.]/ig,"").replace(/_/ig,"."); return { isIOS: isIOS, isAndroid: isAndroid, isMobile: isMobile, platform: platform, version: parseFloat(version), isSupportTouch: isSupportTouch, tapEvent: isMobile && isSupportTouch ? 'tapEvent' : 'click' }; })(window); $.fn.dialog = function(options) { var self = this; return this.each(function(){ var $this = $(this), instance = window.jQuery ? $this.data('dialog') : $.fn.dialog.lookup[$this.data('dialog')]; if (!instance) { var obj = new Dialog(this, options); obj._init(); if (window.jQuery) { $this.data('dialog', obj); } else { $.fn.dialog.lookup[++$.fn.dialog.lookup.i] = obj; $this.data('dialog', $.fn.dialog.lookup.i); instance = $.fn.dialog.lookup[$this.data('dialog')]; } } else { var obj = new Dialog(this, options); obj._init(); } if (typeof options === 'string') { instance[options](); } // æ供外部调用公共方法 self.close = function(){ obj.closeDialog(); }; self.update = function(settings){ obj.update(settings); }; }); }; if (!window.jQuery) { $.fn.dialog.lookup = {i: 0}; } /** * æ’件默认值 */ $.fn.dialog.defaults = { type : 'notice', // 弹窗的类型 [ alert: 确定; confirm: 确定/å–消; toast: 状æ€æ示; notice: æç¤ºä¿¡æ¯ ] style : 'default', // alert 与 confirm å¼¹çª—çš„é£Žæ ¼ [ default: æ ¹æ®è®¿é—®è®¾å¤‡å¹³å°; ios: ios é£Žæ ¼; android: MD design é£Žæ ¼ ] titleShow : true, // 是å¦æ˜¾ç¤ºæ ‡é¢˜ titleText : 'æ示', // æ ‡é¢˜æ–‡å— bodyNoScroll : false, // body内容ä¸å¯ä»¥æ»šåŠ¨ closeBtnShow : false, // 是å¦æ˜¾ç¤ºå…³é—按钮 content : '', // 弹窗æ示内容, 值å¯ä»¥æ˜¯ HTML 内容 contentScroll: true, // alert 与 confirm 弹窗æ示内容是å¦é™åˆ¶æœ€å¤§é«˜åº¦, 使其å¯ä»¥æ»šåŠ¨ dialogClass : '', // 弹窗自定义 class autoClose : 2000, // 弹窗自动关é—的延迟时间(毫秒)。0: ä¸è‡ªåŠ¨å…³é—; 大于0: 自动关é—弹窗的延迟时间 overlayShow : true, // 是å¦æ˜¾ç¤ºé®ç½©å±‚ overlayClose : false, // 是å¦å¯ä»¥ç‚¹å‡»é®ç½©å±‚å…³é—弹窗 buttonStyle : 'side', // æŒ‰é’®æŽ’ç‰ˆæ ·å¼ [ side: 并排; stacked: å †å ] buttonTextConfirm : '确定', // ç¡®å®šæŒ‰é’®æ–‡å— buttonTextCancel : 'å–消', // å–æ¶ˆæŒ‰é’®æ–‡å— buttonClassConfirm: '', // 确定按钮自定义 class buttonClassCancel : '', // å–消按钮自定义 class buttons : [], // confirm 弹窗自定义按钮组, 会覆盖"确定"与"å–消"按钮; å•ä¸ª button 对象å¯è®¾ç½® name [ å称 ]ã€class [ 自定义class ]ã€callback [ 点击执行的函数 ] infoIcon: '', // toast 与 notice 弹窗的æç¤ºå›¾æ ‡, å€¼ä¸ºå›¾æ ‡çš„è·¯å¾„ã€‚ä¸è®¾ç½®=ä¸æ˜¾ç¤º infoText: '', // toast 与 notice 弹窗的æ示文å—, 会覆盖 content 的设置 position: 'center', // notice 弹窗的ä½ç½®, [ center: å±…ä¸; bottom: 底部 ] onClickConfirmBtn: function(){}, // “确定â€æŒ‰é’®çš„回调函数 onClickCancelBtn : function(){}, // “å–消â€æŒ‰é’®çš„回调函数 onClickCloseBtn : function(){}, // “关é—â€æŒ‰é’®çš„回调函数 onBeforeShow : function(){}, // 弹窗显示å‰çš„回调函数 onShow : function(){}, // 弹窗显示åŽçš„回调函数 onBeforeClosed : function(){}, // 弹窗关é—å‰çš„回调函数 onClosed : function(){} // 弹窗关é—åŽçš„回调函数 }; })(window.jQuery || window.Zepto, window, document);