| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105 |
- /*
- * iframe之间函数调用
- *
- * main frame中每个frame需要name和id,以便兼容多浏览器
- * 如果需要提供给其他frame调用,则需要在body中加入
- * <input id="FrameCall" type='hidden' action='' value='' onclick='FrameCall.api()'/>
- * 调用例子:Frame.doFunction('main','goUrl','"'+url+'"');该frame调用id为main的兄弟frame的goUrl方法,参数为后面的
- * 参数为字符串时需要加引号,否则传过去会被理解成一个未定义变量
- */
- var FrameCall = (function () {
- var idName = "FrameCall"
- var idNameAll = "#" + idName
- var ie = !-[1] //是否ie
- return {
- apiOpen: function () {
- var html = '<input id="FrameCall" type="hidden" action="1" value="1" onclick="FrameCall.api()" result=""/>'
- $(html).prependTo("body")
- },
- //其他窗口调用该窗口函数,调用另一个frame的方法
- api: function () {
- var action = $(idNameAll).attr("action")
- var value = $(idNameAll).attr("value")
- if (action == "get") {
- //获取变量
- share.data("create_app_path", eval(value))
- return
- }
- var fun = action + "(" + value + ");" //拼装执行语句,字符串转换到代码
- try {
- $(idNameAll).attr("result", JSON.stringify(eval(fun)))
- } catch (e) {}
- },
- //该窗口调用顶层窗口的子窗口api,调用iframe框架的js函数.封装控制器。
- top: function (iframe, action, value) {
- if (!window.parent.frames[iframe]) return
- //var obj = window.top.frames[iframe].document;
- var obj = window.top.frames[iframe].document
- // alert(obj + "," + iframe);
- if (!obj) return
- obj = obj.getElementById(idName)
- $(obj).attr("action", action)
- $(obj).attr("value", value)
- $(obj).click()
- return eval("(" + $(obj).attr("result") + ")")
- },
- //该窗口调用父窗口的api
- child: function (iframe, action, value) {
- if (!window.frames[iframe]) return
- var obj = window.frames[iframe].document
- if (!obj) return
- obj = obj.getElementById(idName)
- $(obj).attr("action", action)
- $(obj).attr("value", value)
- $(obj).click()
- return eval("(" + $(obj).attr("result") + ")")
- },
- //该窗口调用父窗口的api
- father: function (action, value) {
- var obj = window.parent.document
- obj = obj.getElementById(idName)
- $(obj).attr("action", action)
- $(obj).attr("value", value)
- $(obj).click()
- return eval("(" + $(obj).attr("result") + ")")
- },
- //___自定义通用方法,可在页面定义更多提供给接口使用的api。
- goUrl: function (url) {
- window.location.href = url
- },
- goRefresh: function () {
- window.location.reload()
- },
- }
- })()
- $(document).ready(function () {
- // if($("#domain_sc").length == 0){
- // $('<script id="domain_sc" src="http://static.vbdsm.com/js/domain.js"></script>').appendTo("head");
- // }
- FrameCall.apiOpen()
- })
- var time = function () {
- var time = new Date().valueOf()
- return time
- }
- var urlEncode = encodeURIComponent
- var urlDecode = decodeURIComponent
- var urlEncode2 = function (str) {
- return urlEncode(urlEncode(str))
- }
- var UUID = function () {
- return "uuid_" + time() + "_" + Math.ceil(Math.random() * 10000)
- }
- var round = function (val, point) {
- if (!point) point = 2
- point = Math.pow(10, parseInt(point))
- return Math.round(parseFloat(val) * point) / point
- }
- //跨框架数据共享
- var share = {
- data: function (name, value) {
- var top = window.top,
- cache = top["_CACHE"] || {}
- top["_CACHE"] = cache
- return value !== undefined ? (cache[name] = value) : cache[name]
- },
- removeData: function (name) {
- var cache = window.top["_CACHE"]
- if (cache && cache[name]) delete cache[name]
- },
- }
- jQuery.easing.def = "easeInOutCubic" //easeOutExpo,easeInOutExpo,easeInOutSine
- //cookie操作
- var Cookie = (function () {
- var cookie = {}
- var _init = function () {
- cookie = {} //初始化cookie
- var cookieArray = document.cookie.split("; ")
- for (var i = 0; i < cookieArray.length; i++) {
- var arr = cookieArray[i].split("=")
- cookie[arr[0]] = unescape(arr[1])
- }
- return cookie
- }
- var get = function (key) {
- //没有key代表获取所有
- _init()
- if (key == undefined) return cookie
- return cookie[key]
- }
- var set = function (key, value, timeout) {
- var str = escape(key) + "=" + escape(value) //不设置时间代表跟随页面生命周期
- if (timeout == undefined) {
- //时间以小时计
- timeout = 365
- }
- var expDate = new Date()
- expDate.setTime(expDate.getTime() + timeout * 3600 * 24 * 1000)
- str += ";path=/"
- str += "; expires=" + expDate.toGMTString()
- document.cookie = str
- }
- var del = function (key) {
- document.cookie = key + "=;expires=" + new Date(0).toGMTString()
- }
- var clear = function () {
- _init()
- for (var key in cookie) {
- del(key)
- }
- }
- return {
- get: get,
- set: set,
- del: del,
- clear: clear,
- }
- })()
- //是否在数组中。
- var inArray = function (arr, value) {
- for (var i = 0, l = arr.length; i < l; i++) {
- if (arr[i] === value) {
- return true
- }
- }
- return false
- }
- var stopPP = function (e) {
- //防止事件冒泡
- e = e || window.event
- if (!e) return
- if (e.stopPropagation) {
- e.stopPropagation()
- }
- if (e.preventDefault) {
- e.preventDefault()
- }
- e.cancelBubble = true
- e.keyCode = 0
- e.returnValue = false
- }
- //通用提示信息框
- var tips = function (msg, code) {
- Tips.tips(msg, code)
- }
- var Tips = (function () {
- var in_time = 600
- var delay = 800
- var opacity = 0.7
- var _init = function (msg, code) {
- var tipsIDname = "messageTips"
- var tipsID = "#" + tipsIDname
- if ($(tipsID).length == 0) {
- var html = '<div id="' + tipsIDname + '" class="tips_box" style="border-radius:5px"><i></i><span></span>' + '<a class="tips_close">×</a></div>'
- $("body").append(html)
- $(tipsID)
- .show()
- .css({ left: ($(window).width() - $(tipsID).innerWidth()) / 2 })
- $(window).bind("resize", function () {
- if ($(tipsID).css("display") == "none") return
- self.stop(true, true)
- $(tipsID).css({ left: ($(window).width() - $(tipsID).width()) / 2 })
- })
- $(tipsID)
- .find(".tips_close")
- .click(function () {
- $(tipsID).animate({ opacity: 0 }, in_time, 0, function () {
- $(this).hide()
- })
- })
- }
- var self = $(tipsID),
- icon,
- color
- switch (code) {
- case 100:
- delay = 3000 //加长时间 5s
- case true:
- case undefined:
- case "success":
- color = "#5cb85c"
- icon = "icon-ok"
- break
- case "info":
- color = "#519AF6"
- icon = "icon-info"
- break
- case "warning":
- color = "#ed9c28"
- icon = "icon-exclamation"
- break
- case false:
- case "error":
- delay = 1000
- color = "#d9534f"
- icon = "icon-remove"
- break
- default:
- color = ""
- icon = ""
- break
- }
- if (color != "") {
- self.css({ background: color, color: "#fff" })
- self.find("i").removeClass().addClass(icon)
- }
- if (msg != undefined) self.find("span").html(msg)
- $(tipsID)
- .show()
- .css({ left: ($(window).width() - $(tipsID).innerWidth()) / 2 })
- return self
- }
- var tips = function (msg, code, offset_top) {
- if (typeof msg == "object") {
- code = msg.code
- msg = msg.data
- }
- var self = _init(msg, code)
- if (offset_top == undefined || offset_top == 0) offset_top = ($(window).height() - self.innerHeight()) / 2 - 100
- self
- .stop(true, true)
- .css({ opacity: "0", top: offset_top - self.height() })
- .show()
- .animate({ opacity: opacity, top: offset_top }, in_time, 0)
- setTimeout(function () {
- self.animate({ opacity: 0, top: "-=" + (offset_top + self.height()) }, in_time, 0, function () {
- $(this).hide()
- })
- }, delay)
- }
- var loading = function (msg, code, offset_top) {
- if (typeof msg == "object") {
- code = msg.code
- msg = msg.data
- }
- if (msg == undefined) msg = "加载中..."
- msg += " <img src='/images/loading.gif'/>"
- var self = _init(msg, code)
- if (offset_top == undefined || offset_top == 0) offset_top = ($(window).height() - self.innerHeight()) / 2 - 100
- self
- .stop(true, true)
- .css({ opacity: "0", top: offset_top - self.height() })
- .animate({ opacity: opacity, top: offset_top }, in_time, 0)
- }
- var close = function (msg, code, offset_top) {
- if (typeof msg == "object") {
- try {
- code = msg.code
- msg = msg.data
- } catch (e) {
- code = 0
- msg = ""
- }
- }
- var self = _init(msg, code)
- if (offset_top == undefined || offset_top == 0) offset_top = ($(window).height() - self.innerHeight()) / 2 - 100
- setTimeout(function () {
- self.animate({ opacity: 0, top: "-=" + (offset_top + self.height()) }, in_time, 0, function () {
- $(this).hide()
- })
- }, delay)
- }
- return {
- tips: tips,
- loading: loading,
- close: close,
- }
- })()
- //获取keys
- var objectKeys = function (obj) {
- var keys = []
- for (var p in obj) {
- if (obj.hasOwnProperty(p)) {
- keys.push(p)
- }
- }
- return keys
- }
- //获取values
- var objectValues = function (obj) {
- var values = []
- for (var p in obj) {
- keys.push(obj[p])
- }
- return values
- }
- var $sizeInt = function ($obj) {
- var str = $obj + ""
- var theSize = parseInt(str.replace("px", ""))
- if (isNaN(theSize)) {
- return 0
- } else {
- return theSize
- }
- }
- //通用遮罩层
- var MaskView = (function () {
- var opacity = 0.6
- var animatetime = 250
- var color = "#000"
- var maskId = "#windowMaskView"
- var maskContent = "#maskViewContent"
- var add = function (content, t_opacity, t_color, time) {
- if (t_opacity != undefined) opacity == t_opacity
- if (t_color != undefined) color == t_color
- if (time != undefined) animatetime == time
- if ($(maskId).length == 0) {
- var html = '<div id="windowMaskView" style="position:fixed;top:0;left:0;right:0;bottom:0;background:' + color + ";opacity:" + opacity + ';z-index:9998;"></div><div id="maskViewContent" style="position:absolute;z-index:9999"></div>'
- $("body").append(html)
- $(maskId).bind("click", close)
- $(maskContent).bind("click", function (e) {
- e.stopPropagation()
- })
- $(window).unbind("resize").bind("resize", _resize)
- }
- $(maskContent).html(content).fadeIn(animatetime)
- _resize()
- $(maskId).hide().fadeIn(animatetime)
- }
- var _resize = function () {
- var $content = $(maskContent)
- $content.css({ width: "auto", height: "auto" }).css({
- top: ($(window).height() - $content.height()) / 2,
- left: ($(window).width() - $content.width()) / 2,
- })
- imageSize()
- }
- var tips = function (msg) {
- add("<div style='font-size:50px;color:#fff;opacity:0.6;'>" + msg + "</div>")
- }
- var image = function (url) {
- add("<img src='" + url + "' class='image' onload='MaskView.resize();' style='-webkit-box-reflect: below 1px -webkit-gradient(linear,left top,left bottom,from(transparent),color-stop(80%,transparent),color-stop(70%,rgba(255,255,255,0)),to(rgba(255,255,255,0.3)));'/>")
- var $content = $(maskContent)
- var $dom = $content.find(".image")
- var dragFlag = false,
- E
- var old_left, old_top
- $(document).bind({
- mousedown: function (e) {
- if (!$(e.target).hasClass("image")) return
- dragFlag = true
- $dom.css("cursor", "move")
- stopPP(e)
- E = e
- old_top = parseInt($content.css("top").replace("px", ""))
- old_left = parseInt($content.css("left").replace("px", ""))
- },
- mousemove: function (e) {
- if (!dragFlag) return
- $content.css({
- left: old_left + (e.clientX - E.clientX),
- top: old_top + (e.clientY - E.clientY),
- })
- },
- mouseup: function () {
- dragFlag = false
- $dom.css("cursor", "default")
- },
- keydown: function (e) {
- if ($(maskId).length > 0 && e.keyCode == 27) {
- MaskView.close()
- stopPP(e)
- }
- },
- })
- $("#windowMaskView,#maskViewContent img").mousewheel(function (event, delta, deltaX, deltaY) {
- var offset = delta > 0 ? 1 : -1
- offset = offset * Math.abs(delta / 10)
- var o_w = parseInt($dom.width()),
- o_h = parseInt($dom.height()),
- w = o_w * (1 + offset / 6),
- h = o_h * (1 + offset / 6)
- if (w <= 5 || h <= 5) return
- if (w >= 10000 || h >= 10000) return
- // var top = ($(window).height() - h)/2;
- // var left = ($(window).width() - w)/2;
- var top = parseInt($content.css("top")) - (h - o_h) / 2
- var left = parseInt($content.css("left")) - (w - o_w) / 2
- $(maskContent + "," + maskContent + " .image")
- .stop(true)
- .animate({ width: w, height: h, top: top, left: left }, 400)
- })
- }
- var imageSize = function () {
- var $dom = $(maskContent).find(".image")
- if ($dom.length == 0) return
- var image = new Image()
- image.src = $dom.attr("src")
- var percent = 0.7,
- w_width = $(window).width(),
- w_height = $(window).height(),
- m_width = image.width,
- m_height = image.height,
- width,
- height
- if (m_width >= w_width * percent) {
- width = w_width * percent
- height = (m_height / m_width) * width
- } else {
- width = m_width
- height = m_height
- }
- $dom.css({ width: width, height: height })
- var $content = $(maskContent)
- $content.css({ width: "auto", height: "auto" }).css({
- top: ($(window).height() - $content.height()) / 2,
- left: ($(window).width() - $content.width()) / 2,
- })
- }
- var close = function () {
- $(maskId).fadeOut(animatetime)
- if ($(maskContent).find(".image").length != 0) {
- $(maskContent + "," + maskContent + " .image").animate(
- {
- width: 0,
- height: 0,
- top: $(window).height() / 2,
- left: $(window).width() / 2,
- },
- animatetime * 1.3,
- 0,
- function () {
- $(maskContent).hide()
- _resize()
- }
- )
- } else {
- $(maskContent).fadeOut(animatetime)
- }
- }
- return {
- image: image,
- resize: _resize,
- tips: tips,
- add: add,
- close: close,
- }
- })()
- //textarea自适应高度
- ;(function ($) {
- $.fn.autoTextarea = function (options) {
- var defaults = {
- minHeight: 20,
- padding: 0,
- }
- var opts = $.extend({}, defaults, options)
- var ie = !!window.attachEvent && !window.opera
- $(this)
- .die("paste cut keydown keyup focus blur")
- .live("paste cut keydown keyup focus blur", function () {
- if (!ie) this.style.height = options.minHeight + "px"
- var height = this.scrollHeight - options.padding
- if (height <= options.minHeight) {
- this.style.height = options.minHeight + "px"
- } else {
- this.style.height = height + "px"
- }
- })
- }
- })(jQuery)
- ;(function ($) {
- $.fn.extend({
- //dom绑定enter事件 用于input
- keyEnter: function (callback) {
- $(this)
- .die("keydown")
- .live("keydown", function (e) {
- if (e.keyCode == 13 && callback) {
- callback()
- }
- })
- },
- //dom绑定鼠标滚轮事件
- mousewheel: function (fn) {
- var mousewheel = jQuery.browser.mozilla ? "DOMMouseScroll" : "mousewheel"
- $(this).bind(mousewheel, function (e) {
- e = window.event || e
- var delta = e.wheelDelta ? e.wheelDelta / 120 : -e.detail / 3
- fn.call(this, delta)
- return false
- })
- },
- //晃动 $('.wrap').shake(4,4,100);
- shake: function (times, offset, delay) {
- this.stop().each(function () {
- var Obj = $(this)
- var marginLeft = parseInt(Obj.css("margin-left"))
- var delay = delay > 50 ? delay : 50
- Obj.animate({ "margin-left": marginLeft + offset }, delay, function () {
- Obj.animate({ "margin-left": marginLeft }, delay, function () {
- times = times - 1
- if (times > 0) Obj.shake(times, offset, delay)
- })
- })
- })
- return this
- },
- })
- })(jQuery)
- ;(function ($) {
- $.tooltipsy = function (el, options) {
- this.options = options
- this.$el = $(el)
- this.title = this.$el.attr("title") || ""
- this.$el.attr("title", "")
- this.random = parseInt(Math.random() * 10000)
- this.ready = false
- this.shown = false
- this.width = 0
- this.height = 0
- this.delaytimer = null
- this.$el.data("tooltipsy", this)
- this.init()
- }
- $.tooltipsy.prototype = {
- init: function () {
- var base = this,
- settings,
- $el = base.$el,
- el = $el[0]
- base.settings = settings = $.extend({}, base.defaults, base.options)
- settings.delay = +settings.delay
- if (typeof settings.content === "function") {
- base.readify()
- }
- if (settings.showEvent === settings.hideEvent && settings.showEvent === "click") {
- $el.toggle(
- function (e) {
- if (settings.showEvent === "click" && el.tagName == "A") {
- e.preventDefault()
- }
- if (settings.delay > 0) {
- base.delaytimer = window.setTimeout(function () {
- base.show(e)
- }, settings.delay)
- } else {
- base.show(e)
- }
- },
- function (e) {
- if (settings.showEvent === "click" && el.tagName == "A") {
- e.preventDefault()
- }
- window.clearTimeout(base.delaytimer)
- base.delaytimer = null
- base.hide(e)
- }
- )
- } else {
- $el
- .bind(settings.showEvent, function (e) {
- if (settings.showEvent === "click" && el.tagName == "A") {
- e.preventDefault()
- }
- base.delaytimer = window.setTimeout(function () {
- base.show(e)
- }, settings.delay || 0)
- })
- .bind(settings.hideEvent, function (e) {
- if (settings.showEvent === "click" && el.tagName == "A") {
- e.preventDefault()
- }
- window.clearTimeout(base.delaytimer)
- base.delaytimer = null
- base.hide(e)
- })
- }
- },
- show: function (e) {
- if (this.ready === false) {
- this.readify()
- }
- var base = this,
- settings = base.settings,
- $tipsy = base.$tipsy,
- $el = base.$el,
- el = $el[0],
- offset = base.offset(el)
- if (base.shown === false) {
- if (
- (function (o) {
- var s = 0,
- k
- for (k in o) {
- if (o.hasOwnProperty(k)) {
- s++
- }
- }
- return s
- })(settings.css) > 0
- ) {
- base.$tip.css(settings.css)
- }
- base.width = $tipsy.outerWidth()
- base.height = $tipsy.outerHeight()
- }
- if (settings.alignTo === "cursor" && e) {
- var tip_position = [e.clientX + settings.offset[0], e.clientY + settings.offset[1]]
- if (tip_position[0] + base.width > $(window).width()) {
- var tip_css = { top: tip_position[1] + "px", right: tip_position[0] + "px", left: "auto" }
- } else {
- var tip_css = { top: tip_position[1] + "px", left: tip_position[0] + "px", right: "auto" }
- }
- } else {
- var tip_position = [
- (function () {
- if (settings.offset[0] < 0) {
- return offset.left - Math.abs(settings.offset[0]) - base.width
- } else if (settings.offset[0] === 0) {
- return offset.left - (base.width - $el.outerWidth()) / 2
- } else {
- return offset.left + $el.outerWidth() + settings.offset[0]
- }
- })(),
- (function () {
- if (settings.offset[1] < 0) {
- return offset.top - Math.abs(settings.offset[1]) - base.height
- } else if (settings.offset[1] === 0) {
- return offset.top - (base.height - base.$el.outerHeight()) / 2
- } else {
- return offset.top + base.$el.outerHeight() + settings.offset[1]
- }
- })(),
- ]
- }
- $tipsy.css({ top: tip_position[1] + "px", left: tip_position[0] + "px" })
- base.settings.show(e, $tipsy.stop(true, true))
- },
- hide: function (e) {
- var base = this
- if (base.ready === false) {
- return
- }
- if (e && e.relatedTarget === base.$tip[0]) {
- base.$tip.bind("mouseleave", function (e) {
- if (e.relatedTarget === base.$el[0]) {
- return
- }
- base.settings.hide(e, base.$tipsy.stop(true, true))
- })
- return
- }
- base.settings.hide(e, base.$tipsy.stop(true, true))
- },
- readify: function () {
- this.ready = true
- this.$tipsy = $('<div id="tooltipsy' + this.random + '" style="position:fixed;z-index:2147483647;display:none">').appendTo("body")
- this.$tip = $('<div class="' + this.settings.className + '">').appendTo(this.$tipsy)
- this.$tip.data("rootel", this.$el)
- var e = this.$el
- var t = this.$tip
- this.$tip.html(this.settings.content != "" ? (typeof this.settings.content == "string" ? this.settings.content : this.settings.content(e, t)) : this.title)
- },
- offset: function (el) {
- return this.$el[0].getBoundingClientRect()
- },
- destroy: function () {
- if (this.$tipsy) {
- this.$tipsy.remove()
- $.removeData(this.$el, "tooltipsy")
- }
- },
- defaults: {
- alignTo: "element",
- offset: [0, -1],
- content: "",
- show: function (e, $el) {
- $el.fadeIn(100)
- },
- hide: function (e, $el) {
- $el.fadeOut(100)
- },
- css: {},
- className: "tooltipsy",
- delay: 200,
- showEvent: "mouseenter",
- hideEvent: "mouseleave",
- },
- }
- $.fn.tooltipsy = function (options) {
- return this.each(function () {
- new $.tooltipsy(this, options)
- })
- }
- })(jQuery)
- var date = function (format, timestamp) {
- timestamp = parseInt(timestamp)
- var a,
- jsdate = timestamp ? new Date(timestamp * 1000) : new Date()
- var pad = function (n, c) {
- if ((n = n + "").length < c) {
- return new Array(++c - n.length).join("0") + n
- } else {
- return n
- }
- }
- var txt_weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
- var txt_ordin = { 1: "st", 2: "nd", 3: "rd", 21: "st", 22: "nd", 23: "rd", 31: "st" }
- var txt_months = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
- var f = {
- // Day
- d: function () {
- return pad(f.j(), 2)
- },
- D: function () {
- return f.l().substr(0, 3)
- },
- j: function () {
- return jsdate.getDate()
- },
- l: function () {
- return txt_weekdays[f.w()]
- },
- N: function () {
- return f.w() + 1
- },
- S: function () {
- return txt_ordin[f.j()] ? txt_ordin[f.j()] : "th"
- },
- w: function () {
- return jsdate.getDay()
- },
- z: function () {
- return ((jsdate - new Date(jsdate.getFullYear() + "/1/1")) / 864e5) >> 0
- },
- // Week
- W: function () {
- var a = f.z(),
- b = 364 + f.L() - a
- var nd2,
- nd = (new Date(jsdate.getFullYear() + "/1/1").getDay() || 7) - 1
- if (b <= 2 && (jsdate.getDay() || 7) - 1 <= 2 - b) {
- return 1
- } else {
- if (a <= 2 && nd >= 4 && a >= 6 - nd) {
- nd2 = new Date(jsdate.getFullYear() - 1 + "/12/31")
- return date("W", Math.round(nd2.getTime() / 1000))
- } else {
- return (1 + (nd <= 3 ? (a + nd) / 7 : (a - (7 - nd)) / 7)) >> 0
- }
- }
- },
- // Month
- F: function () {
- return txt_months[f.n()]
- },
- m: function () {
- return pad(f.n(), 2)
- },
- M: function () {
- return f.F().substr(0, 3)
- },
- n: function () {
- return jsdate.getMonth() + 1
- },
- t: function () {
- var n
- if ((n = jsdate.getMonth() + 1) == 2) {
- return 28 + f.L()
- } else {
- if ((n & 1 && n < 8) || (!(n & 1) && n > 7)) {
- return 31
- } else {
- return 30
- }
- }
- },
- // Year
- L: function () {
- var y = f.Y()
- return !(y & 3) && (y % 1e2 || !(y % 4e2)) ? 1 : 0
- },
- Y: function () {
- return jsdate.getFullYear()
- },
- y: function () {
- return (jsdate.getFullYear() + "").slice(2)
- },
- // Time
- a: function () {
- return jsdate.getHours() > 11 ? "pm" : "am"
- },
- A: function () {
- return f.a().toUpperCase()
- },
- B: function () {
- var off = (jsdate.getTimezoneOffset() + 60) * 60
- var theSeconds = jsdate.getHours() * 3600 + jsdate.getMinutes() * 60 + jsdate.getSeconds() + off
- var beat = Math.floor(theSeconds / 86.4)
- if (beat > 1000) beat -= 1000
- if (beat < 0) beat += 1000
- if (String(beat).length == 1) beat = "00" + beat
- if (String(beat).length == 2) beat = "0" + beat
- return beat
- },
- g: function () {
- return jsdate.getHours() % 12 || 12
- },
- G: function () {
- return jsdate.getHours()
- },
- h: function () {
- return pad(f.g(), 2)
- },
- H: function () {
- return pad(jsdate.getHours(), 2)
- },
- i: function () {
- return pad(jsdate.getMinutes(), 2)
- },
- s: function () {
- return pad(jsdate.getSeconds(), 2)
- },
- O: function () {
- var t = pad(Math.abs((jsdate.getTimezoneOffset() / 60) * 100), 4)
- if (jsdate.getTimezoneOffset() > 0) t = "-" + t
- else t = "+" + t
- return t
- },
- P: function () {
- var O = f.O()
- return O.substr(0, 3) + ":" + O.substr(3, 2)
- },
- c: function () {
- return f.Y() + "-" + f.m() + "-" + f.d() + "T" + f.h() + ":" + f.i() + ":" + f.s() + f.P()
- },
- U: function () {
- return Math.round(jsdate.getTime() / 1000)
- },
- }
- return format.replace(/[\\]?([a-zA-Z])/g, function (t, s) {
- if (t != s) {
- ret = s
- } else if (f[s]) {
- ret = f[s]()
- } else {
- ret = s
- }
- return ret
- })
- }
- var Base64 = (function () {
- var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
- var encode = function (input) {
- var output = ""
- var chr1, chr2, chr3, enc1, enc2, enc3, enc4
- var i = 0
- input = _utf8_encode(input)
- while (i < input.length) {
- chr1 = input.charCodeAt(i++)
- chr2 = input.charCodeAt(i++)
- chr3 = input.charCodeAt(i++)
- enc1 = chr1 >> 2
- enc2 = ((chr1 & 3) << 4) | (chr2 >> 4)
- enc3 = ((chr2 & 15) << 2) | (chr3 >> 6)
- enc4 = chr3 & 63
- if (isNaN(chr2)) {
- enc3 = enc4 = 64
- } else if (isNaN(chr3)) {
- enc4 = 64
- }
- output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4)
- }
- return output
- }
- // public method for decoding
- var decode = function (input) {
- var output = ""
- var chr1, chr2, chr3
- var enc1, enc2, enc3, enc4
- var i = 0
- input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "")
- while (i < input.length) {
- enc1 = _keyStr.indexOf(input.charAt(i++))
- enc2 = _keyStr.indexOf(input.charAt(i++))
- enc3 = _keyStr.indexOf(input.charAt(i++))
- enc4 = _keyStr.indexOf(input.charAt(i++))
- chr1 = (enc1 << 2) | (enc2 >> 4)
- chr2 = ((enc2 & 15) << 4) | (enc3 >> 2)
- chr3 = ((enc3 & 3) << 6) | enc4
- output = output + String.fromCharCode(chr1)
- if (enc3 != 64) {
- output = output + String.fromCharCode(chr2)
- }
- if (enc4 != 64) {
- output = output + String.fromCharCode(chr3)
- }
- }
- output = _utf8_decode(output)
- return output
- }
- // private method for UTF-8 encoding
- _utf8_encode = function (string) {
- string = string.replace(/\r\n/g, "\n")
- var utftext = ""
- for (var n = 0; n < string.length; n++) {
- var c = string.charCodeAt(n)
- if (c < 128) {
- utftext += String.fromCharCode(c)
- } else if (c > 127 && c < 2048) {
- utftext += String.fromCharCode((c >> 6) | 192)
- utftext += String.fromCharCode((c & 63) | 128)
- } else {
- utftext += String.fromCharCode((c >> 12) | 224)
- utftext += String.fromCharCode(((c >> 6) & 63) | 128)
- utftext += String.fromCharCode((c & 63) | 128)
- }
- }
- return utftext
- }
- // private method for UTF-8 decoding
- _utf8_decode = function (utftext) {
- var string = ""
- var i = 0
- var c = (c1 = c2 = 0)
- while (i < utftext.length) {
- c = utftext.charCodeAt(i)
- if (c < 128) {
- string += String.fromCharCode(c)
- i++
- } else if (c > 191 && c < 224) {
- c2 = utftext.charCodeAt(i + 1)
- string += String.fromCharCode(((c & 31) << 6) | (c2 & 63))
- i += 2
- } else {
- c2 = utftext.charCodeAt(i + 1)
- c3 = utftext.charCodeAt(i + 2)
- string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63))
- i += 3
- }
- }
- return string
- }
- return {
- encode: encode,
- decode: decode,
- }
- })()
- var base64_encode = Base64.encode
- var base64_decode = Base64.decode
- var getParam = function (name) {
- var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i")
- var r = window.location.search.substr(1).match(reg)
- if (r != null) return unescape(r[2])
- return null
- }
- var getFormJson = function (frm) {
- var o = {}
- var a = $(frm).serializeArray()
- $.each(a, function () {
- if (o[this.name] !== undefined) {
- if (!o[this.name].push) {
- o[this.name] = [o[this.name]]
- }
- o[this.name].push(this.value || "")
- } else {
- o[this.name] = this.value || ""
- }
- })
- return o
- }
- /**
- * 检查ajax的返回结果
- */
- var checkAjaxResult = function (data) {
- if (data.status == 99) {
- if (!window.alerted) {
- alert("您尚未登录或者登录已超时!")
- window.alerted = true
- }
- window.top.location.href = data.data.loginHost
- return false
- } else if (data.status == 98) {
- alert(data.msg)
- return false
- }
- return true
- }
- /**
- * demo:
- * ajax({beforSend:function(){
- * ajaxCheck('remove');
- * }});
- *
- */
- var ajaxCheck = function (method) {
- if (AUTH && AUTH.options) {
- var auth_aid = getParam("auth_aid"),
- auth_mid = getParam("auth_mid")
- return AUTH.options["" + auth_aid]["" + auth_mid] == 1
- }
- return true
- }
- /**
- * 发送ajax请求
- */
- var ajax = function (options) {
- var opts = $.extend(true, {}, options)
- var d = $.extend(
- true,
- {
- auth_aid: getParam("auth_aid"),
- auth_mid: getParam("auth_mid"),
- auth_cid: getParam("auth_cid"),
- },
- opts.data
- )
- opts.data = d
- opts.success = function (data) {
- if (checkAjaxResult(data)) {
- if (options.success) {
- options.success(data)
- }
- }
- }
- $.ajax(opts)
- }
|