util.js 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. /*
  2. * iframe之间函数调用
  3. *
  4. * main frame中每个frame需要name和id,以便兼容多浏览器
  5. * 如果需要提供给其他frame调用,则需要在body中加入
  6. * <input id="FrameCall" type='hidden' action='' value='' onclick='FrameCall.api()'/>
  7. * 调用例子:Frame.doFunction('main','goUrl','"'+url+'"');该frame调用id为main的兄弟frame的goUrl方法,参数为后面的
  8. * 参数为字符串时需要加引号,否则传过去会被理解成一个未定义变量
  9. */
  10. var FrameCall = (function () {
  11. var idName = "FrameCall"
  12. var idNameAll = "#" + idName
  13. var ie = !-[1] //是否ie
  14. return {
  15. apiOpen: function () {
  16. var html = '<input id="FrameCall" type="hidden" action="1" value="1" onclick="FrameCall.api()" result=""/>'
  17. $(html).prependTo("body")
  18. },
  19. //其他窗口调用该窗口函数,调用另一个frame的方法
  20. api: function () {
  21. var action = $(idNameAll).attr("action")
  22. var value = $(idNameAll).attr("value")
  23. if (action == "get") {
  24. //获取变量
  25. share.data("create_app_path", eval(value))
  26. return
  27. }
  28. var fun = action + "(" + value + ");" //拼装执行语句,字符串转换到代码
  29. try {
  30. $(idNameAll).attr("result", JSON.stringify(eval(fun)))
  31. } catch (e) {}
  32. },
  33. //该窗口调用顶层窗口的子窗口api,调用iframe框架的js函数.封装控制器。
  34. top: function (iframe, action, value) {
  35. if (!window.parent.frames[iframe]) return
  36. //var obj = window.top.frames[iframe].document;
  37. var obj = window.top.frames[iframe].document
  38. // alert(obj + "," + iframe);
  39. if (!obj) return
  40. obj = obj.getElementById(idName)
  41. $(obj).attr("action", action)
  42. $(obj).attr("value", value)
  43. $(obj).click()
  44. return eval("(" + $(obj).attr("result") + ")")
  45. },
  46. //该窗口调用父窗口的api
  47. child: function (iframe, action, value) {
  48. if (!window.frames[iframe]) return
  49. var obj = window.frames[iframe].document
  50. if (!obj) return
  51. obj = obj.getElementById(idName)
  52. $(obj).attr("action", action)
  53. $(obj).attr("value", value)
  54. $(obj).click()
  55. return eval("(" + $(obj).attr("result") + ")")
  56. },
  57. //该窗口调用父窗口的api
  58. father: function (action, value) {
  59. var obj = window.parent.document
  60. obj = obj.getElementById(idName)
  61. $(obj).attr("action", action)
  62. $(obj).attr("value", value)
  63. $(obj).click()
  64. return eval("(" + $(obj).attr("result") + ")")
  65. },
  66. //___自定义通用方法,可在页面定义更多提供给接口使用的api。
  67. goUrl: function (url) {
  68. window.location.href = url
  69. },
  70. goRefresh: function () {
  71. window.location.reload()
  72. },
  73. }
  74. })()
  75. $(document).ready(function () {
  76. // if($("#domain_sc").length == 0){
  77. // $('<script id="domain_sc" src="http://static.vbdsm.com/js/domain.js"></script>').appendTo("head");
  78. // }
  79. FrameCall.apiOpen()
  80. })
  81. var time = function () {
  82. var time = new Date().valueOf()
  83. return time
  84. }
  85. var urlEncode = encodeURIComponent
  86. var urlDecode = decodeURIComponent
  87. var urlEncode2 = function (str) {
  88. return urlEncode(urlEncode(str))
  89. }
  90. var UUID = function () {
  91. return "uuid_" + time() + "_" + Math.ceil(Math.random() * 10000)
  92. }
  93. var round = function (val, point) {
  94. if (!point) point = 2
  95. point = Math.pow(10, parseInt(point))
  96. return Math.round(parseFloat(val) * point) / point
  97. }
  98. //跨框架数据共享
  99. var share = {
  100. data: function (name, value) {
  101. var top = window.top,
  102. cache = top["_CACHE"] || {}
  103. top["_CACHE"] = cache
  104. return value !== undefined ? (cache[name] = value) : cache[name]
  105. },
  106. removeData: function (name) {
  107. var cache = window.top["_CACHE"]
  108. if (cache && cache[name]) delete cache[name]
  109. },
  110. }
  111. jQuery.easing.def = "easeInOutCubic" //easeOutExpo,easeInOutExpo,easeInOutSine
  112. //cookie操作
  113. var Cookie = (function () {
  114. var cookie = {}
  115. var _init = function () {
  116. cookie = {} //初始化cookie
  117. var cookieArray = document.cookie.split("; ")
  118. for (var i = 0; i < cookieArray.length; i++) {
  119. var arr = cookieArray[i].split("=")
  120. cookie[arr[0]] = unescape(arr[1])
  121. }
  122. return cookie
  123. }
  124. var get = function (key) {
  125. //没有key代表获取所有
  126. _init()
  127. if (key == undefined) return cookie
  128. return cookie[key]
  129. }
  130. var set = function (key, value, timeout) {
  131. var str = escape(key) + "=" + escape(value) //不设置时间代表跟随页面生命周期
  132. if (timeout == undefined) {
  133. //时间以小时计
  134. timeout = 365
  135. }
  136. var expDate = new Date()
  137. expDate.setTime(expDate.getTime() + timeout * 3600 * 24 * 1000)
  138. str += ";path=/"
  139. str += "; expires=" + expDate.toGMTString()
  140. document.cookie = str
  141. }
  142. var del = function (key) {
  143. document.cookie = key + "=;expires=" + new Date(0).toGMTString()
  144. }
  145. var clear = function () {
  146. _init()
  147. for (var key in cookie) {
  148. del(key)
  149. }
  150. }
  151. return {
  152. get: get,
  153. set: set,
  154. del: del,
  155. clear: clear,
  156. }
  157. })()
  158. //是否在数组中。
  159. var inArray = function (arr, value) {
  160. for (var i = 0, l = arr.length; i < l; i++) {
  161. if (arr[i] === value) {
  162. return true
  163. }
  164. }
  165. return false
  166. }
  167. var stopPP = function (e) {
  168. //防止事件冒泡
  169. e = e || window.event
  170. if (!e) return
  171. if (e.stopPropagation) {
  172. e.stopPropagation()
  173. }
  174. if (e.preventDefault) {
  175. e.preventDefault()
  176. }
  177. e.cancelBubble = true
  178. e.keyCode = 0
  179. e.returnValue = false
  180. }
  181. //通用提示信息框
  182. var tips = function (msg, code) {
  183. Tips.tips(msg, code)
  184. }
  185. var Tips = (function () {
  186. var in_time = 600
  187. var delay = 800
  188. var opacity = 0.7
  189. var _init = function (msg, code) {
  190. var tipsIDname = "messageTips"
  191. var tipsID = "#" + tipsIDname
  192. if ($(tipsID).length == 0) {
  193. var html = '<div id="' + tipsIDname + '" class="tips_box" style="border-radius:5px"><i></i><span></span>' + '<a class="tips_close">×</a></div>'
  194. $("body").append(html)
  195. $(tipsID)
  196. .show()
  197. .css({ left: ($(window).width() - $(tipsID).innerWidth()) / 2 })
  198. $(window).bind("resize", function () {
  199. if ($(tipsID).css("display") == "none") return
  200. self.stop(true, true)
  201. $(tipsID).css({ left: ($(window).width() - $(tipsID).width()) / 2 })
  202. })
  203. $(tipsID)
  204. .find(".tips_close")
  205. .click(function () {
  206. $(tipsID).animate({ opacity: 0 }, in_time, 0, function () {
  207. $(this).hide()
  208. })
  209. })
  210. }
  211. var self = $(tipsID),
  212. icon,
  213. color
  214. switch (code) {
  215. case 100:
  216. delay = 3000 //加长时间 5s
  217. case true:
  218. case undefined:
  219. case "success":
  220. color = "#5cb85c"
  221. icon = "icon-ok"
  222. break
  223. case "info":
  224. color = "#519AF6"
  225. icon = "icon-info"
  226. break
  227. case "warning":
  228. color = "#ed9c28"
  229. icon = "icon-exclamation"
  230. break
  231. case false:
  232. case "error":
  233. delay = 1000
  234. color = "#d9534f"
  235. icon = "icon-remove"
  236. break
  237. default:
  238. color = ""
  239. icon = ""
  240. break
  241. }
  242. if (color != "") {
  243. self.css({ background: color, color: "#fff" })
  244. self.find("i").removeClass().addClass(icon)
  245. }
  246. if (msg != undefined) self.find("span").html(msg)
  247. $(tipsID)
  248. .show()
  249. .css({ left: ($(window).width() - $(tipsID).innerWidth()) / 2 })
  250. return self
  251. }
  252. var tips = function (msg, code, offset_top) {
  253. if (typeof msg == "object") {
  254. code = msg.code
  255. msg = msg.data
  256. }
  257. var self = _init(msg, code)
  258. if (offset_top == undefined || offset_top == 0) offset_top = ($(window).height() - self.innerHeight()) / 2 - 100
  259. self
  260. .stop(true, true)
  261. .css({ opacity: "0", top: offset_top - self.height() })
  262. .show()
  263. .animate({ opacity: opacity, top: offset_top }, in_time, 0)
  264. setTimeout(function () {
  265. self.animate({ opacity: 0, top: "-=" + (offset_top + self.height()) }, in_time, 0, function () {
  266. $(this).hide()
  267. })
  268. }, delay)
  269. }
  270. var loading = function (msg, code, offset_top) {
  271. if (typeof msg == "object") {
  272. code = msg.code
  273. msg = msg.data
  274. }
  275. if (msg == undefined) msg = "加载中..."
  276. msg += "&nbsp;&nbsp; <img src='/images/loading.gif'/>"
  277. var self = _init(msg, code)
  278. if (offset_top == undefined || offset_top == 0) offset_top = ($(window).height() - self.innerHeight()) / 2 - 100
  279. self
  280. .stop(true, true)
  281. .css({ opacity: "0", top: offset_top - self.height() })
  282. .animate({ opacity: opacity, top: offset_top }, in_time, 0)
  283. }
  284. var close = function (msg, code, offset_top) {
  285. if (typeof msg == "object") {
  286. try {
  287. code = msg.code
  288. msg = msg.data
  289. } catch (e) {
  290. code = 0
  291. msg = ""
  292. }
  293. }
  294. var self = _init(msg, code)
  295. if (offset_top == undefined || offset_top == 0) offset_top = ($(window).height() - self.innerHeight()) / 2 - 100
  296. setTimeout(function () {
  297. self.animate({ opacity: 0, top: "-=" + (offset_top + self.height()) }, in_time, 0, function () {
  298. $(this).hide()
  299. })
  300. }, delay)
  301. }
  302. return {
  303. tips: tips,
  304. loading: loading,
  305. close: close,
  306. }
  307. })()
  308. //获取keys
  309. var objectKeys = function (obj) {
  310. var keys = []
  311. for (var p in obj) {
  312. if (obj.hasOwnProperty(p)) {
  313. keys.push(p)
  314. }
  315. }
  316. return keys
  317. }
  318. //获取values
  319. var objectValues = function (obj) {
  320. var values = []
  321. for (var p in obj) {
  322. keys.push(obj[p])
  323. }
  324. return values
  325. }
  326. var $sizeInt = function ($obj) {
  327. var str = $obj + ""
  328. var theSize = parseInt(str.replace("px", ""))
  329. if (isNaN(theSize)) {
  330. return 0
  331. } else {
  332. return theSize
  333. }
  334. }
  335. //通用遮罩层
  336. var MaskView = (function () {
  337. var opacity = 0.6
  338. var animatetime = 250
  339. var color = "#000"
  340. var maskId = "#windowMaskView"
  341. var maskContent = "#maskViewContent"
  342. var add = function (content, t_opacity, t_color, time) {
  343. if (t_opacity != undefined) opacity == t_opacity
  344. if (t_color != undefined) color == t_color
  345. if (time != undefined) animatetime == time
  346. if ($(maskId).length == 0) {
  347. 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>'
  348. $("body").append(html)
  349. $(maskId).bind("click", close)
  350. $(maskContent).bind("click", function (e) {
  351. e.stopPropagation()
  352. })
  353. $(window).unbind("resize").bind("resize", _resize)
  354. }
  355. $(maskContent).html(content).fadeIn(animatetime)
  356. _resize()
  357. $(maskId).hide().fadeIn(animatetime)
  358. }
  359. var _resize = function () {
  360. var $content = $(maskContent)
  361. $content.css({ width: "auto", height: "auto" }).css({
  362. top: ($(window).height() - $content.height()) / 2,
  363. left: ($(window).width() - $content.width()) / 2,
  364. })
  365. imageSize()
  366. }
  367. var tips = function (msg) {
  368. add("<div style='font-size:50px;color:#fff;opacity:0.6;'>" + msg + "</div>")
  369. }
  370. var image = function (url) {
  371. 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)));'/>")
  372. var $content = $(maskContent)
  373. var $dom = $content.find(".image")
  374. var dragFlag = false,
  375. E
  376. var old_left, old_top
  377. $(document).bind({
  378. mousedown: function (e) {
  379. if (!$(e.target).hasClass("image")) return
  380. dragFlag = true
  381. $dom.css("cursor", "move")
  382. stopPP(e)
  383. E = e
  384. old_top = parseInt($content.css("top").replace("px", ""))
  385. old_left = parseInt($content.css("left").replace("px", ""))
  386. },
  387. mousemove: function (e) {
  388. if (!dragFlag) return
  389. $content.css({
  390. left: old_left + (e.clientX - E.clientX),
  391. top: old_top + (e.clientY - E.clientY),
  392. })
  393. },
  394. mouseup: function () {
  395. dragFlag = false
  396. $dom.css("cursor", "default")
  397. },
  398. keydown: function (e) {
  399. if ($(maskId).length > 0 && e.keyCode == 27) {
  400. MaskView.close()
  401. stopPP(e)
  402. }
  403. },
  404. })
  405. $("#windowMaskView,#maskViewContent img").mousewheel(function (event, delta, deltaX, deltaY) {
  406. var offset = delta > 0 ? 1 : -1
  407. offset = offset * Math.abs(delta / 10)
  408. var o_w = parseInt($dom.width()),
  409. o_h = parseInt($dom.height()),
  410. w = o_w * (1 + offset / 6),
  411. h = o_h * (1 + offset / 6)
  412. if (w <= 5 || h <= 5) return
  413. if (w >= 10000 || h >= 10000) return
  414. // var top = ($(window).height() - h)/2;
  415. // var left = ($(window).width() - w)/2;
  416. var top = parseInt($content.css("top")) - (h - o_h) / 2
  417. var left = parseInt($content.css("left")) - (w - o_w) / 2
  418. $(maskContent + "," + maskContent + " .image")
  419. .stop(true)
  420. .animate({ width: w, height: h, top: top, left: left }, 400)
  421. })
  422. }
  423. var imageSize = function () {
  424. var $dom = $(maskContent).find(".image")
  425. if ($dom.length == 0) return
  426. var image = new Image()
  427. image.src = $dom.attr("src")
  428. var percent = 0.7,
  429. w_width = $(window).width(),
  430. w_height = $(window).height(),
  431. m_width = image.width,
  432. m_height = image.height,
  433. width,
  434. height
  435. if (m_width >= w_width * percent) {
  436. width = w_width * percent
  437. height = (m_height / m_width) * width
  438. } else {
  439. width = m_width
  440. height = m_height
  441. }
  442. $dom.css({ width: width, height: height })
  443. var $content = $(maskContent)
  444. $content.css({ width: "auto", height: "auto" }).css({
  445. top: ($(window).height() - $content.height()) / 2,
  446. left: ($(window).width() - $content.width()) / 2,
  447. })
  448. }
  449. var close = function () {
  450. $(maskId).fadeOut(animatetime)
  451. if ($(maskContent).find(".image").length != 0) {
  452. $(maskContent + "," + maskContent + " .image").animate(
  453. {
  454. width: 0,
  455. height: 0,
  456. top: $(window).height() / 2,
  457. left: $(window).width() / 2,
  458. },
  459. animatetime * 1.3,
  460. 0,
  461. function () {
  462. $(maskContent).hide()
  463. _resize()
  464. }
  465. )
  466. } else {
  467. $(maskContent).fadeOut(animatetime)
  468. }
  469. }
  470. return {
  471. image: image,
  472. resize: _resize,
  473. tips: tips,
  474. add: add,
  475. close: close,
  476. }
  477. })()
  478. //textarea自适应高度
  479. ;(function ($) {
  480. $.fn.autoTextarea = function (options) {
  481. var defaults = {
  482. minHeight: 20,
  483. padding: 0,
  484. }
  485. var opts = $.extend({}, defaults, options)
  486. var ie = !!window.attachEvent && !window.opera
  487. $(this)
  488. .die("paste cut keydown keyup focus blur")
  489. .live("paste cut keydown keyup focus blur", function () {
  490. if (!ie) this.style.height = options.minHeight + "px"
  491. var height = this.scrollHeight - options.padding
  492. if (height <= options.minHeight) {
  493. this.style.height = options.minHeight + "px"
  494. } else {
  495. this.style.height = height + "px"
  496. }
  497. })
  498. }
  499. })(jQuery)
  500. ;(function ($) {
  501. $.fn.extend({
  502. //dom绑定enter事件 用于input
  503. keyEnter: function (callback) {
  504. $(this)
  505. .die("keydown")
  506. .live("keydown", function (e) {
  507. if (e.keyCode == 13 && callback) {
  508. callback()
  509. }
  510. })
  511. },
  512. //dom绑定鼠标滚轮事件
  513. mousewheel: function (fn) {
  514. var mousewheel = jQuery.browser.mozilla ? "DOMMouseScroll" : "mousewheel"
  515. $(this).bind(mousewheel, function (e) {
  516. e = window.event || e
  517. var delta = e.wheelDelta ? e.wheelDelta / 120 : -e.detail / 3
  518. fn.call(this, delta)
  519. return false
  520. })
  521. },
  522. //晃动 $('.wrap').shake(4,4,100);
  523. shake: function (times, offset, delay) {
  524. this.stop().each(function () {
  525. var Obj = $(this)
  526. var marginLeft = parseInt(Obj.css("margin-left"))
  527. var delay = delay > 50 ? delay : 50
  528. Obj.animate({ "margin-left": marginLeft + offset }, delay, function () {
  529. Obj.animate({ "margin-left": marginLeft }, delay, function () {
  530. times = times - 1
  531. if (times > 0) Obj.shake(times, offset, delay)
  532. })
  533. })
  534. })
  535. return this
  536. },
  537. })
  538. })(jQuery)
  539. ;(function ($) {
  540. $.tooltipsy = function (el, options) {
  541. this.options = options
  542. this.$el = $(el)
  543. this.title = this.$el.attr("title") || ""
  544. this.$el.attr("title", "")
  545. this.random = parseInt(Math.random() * 10000)
  546. this.ready = false
  547. this.shown = false
  548. this.width = 0
  549. this.height = 0
  550. this.delaytimer = null
  551. this.$el.data("tooltipsy", this)
  552. this.init()
  553. }
  554. $.tooltipsy.prototype = {
  555. init: function () {
  556. var base = this,
  557. settings,
  558. $el = base.$el,
  559. el = $el[0]
  560. base.settings = settings = $.extend({}, base.defaults, base.options)
  561. settings.delay = +settings.delay
  562. if (typeof settings.content === "function") {
  563. base.readify()
  564. }
  565. if (settings.showEvent === settings.hideEvent && settings.showEvent === "click") {
  566. $el.toggle(
  567. function (e) {
  568. if (settings.showEvent === "click" && el.tagName == "A") {
  569. e.preventDefault()
  570. }
  571. if (settings.delay > 0) {
  572. base.delaytimer = window.setTimeout(function () {
  573. base.show(e)
  574. }, settings.delay)
  575. } else {
  576. base.show(e)
  577. }
  578. },
  579. function (e) {
  580. if (settings.showEvent === "click" && el.tagName == "A") {
  581. e.preventDefault()
  582. }
  583. window.clearTimeout(base.delaytimer)
  584. base.delaytimer = null
  585. base.hide(e)
  586. }
  587. )
  588. } else {
  589. $el
  590. .bind(settings.showEvent, function (e) {
  591. if (settings.showEvent === "click" && el.tagName == "A") {
  592. e.preventDefault()
  593. }
  594. base.delaytimer = window.setTimeout(function () {
  595. base.show(e)
  596. }, settings.delay || 0)
  597. })
  598. .bind(settings.hideEvent, function (e) {
  599. if (settings.showEvent === "click" && el.tagName == "A") {
  600. e.preventDefault()
  601. }
  602. window.clearTimeout(base.delaytimer)
  603. base.delaytimer = null
  604. base.hide(e)
  605. })
  606. }
  607. },
  608. show: function (e) {
  609. if (this.ready === false) {
  610. this.readify()
  611. }
  612. var base = this,
  613. settings = base.settings,
  614. $tipsy = base.$tipsy,
  615. $el = base.$el,
  616. el = $el[0],
  617. offset = base.offset(el)
  618. if (base.shown === false) {
  619. if (
  620. (function (o) {
  621. var s = 0,
  622. k
  623. for (k in o) {
  624. if (o.hasOwnProperty(k)) {
  625. s++
  626. }
  627. }
  628. return s
  629. })(settings.css) > 0
  630. ) {
  631. base.$tip.css(settings.css)
  632. }
  633. base.width = $tipsy.outerWidth()
  634. base.height = $tipsy.outerHeight()
  635. }
  636. if (settings.alignTo === "cursor" && e) {
  637. var tip_position = [e.clientX + settings.offset[0], e.clientY + settings.offset[1]]
  638. if (tip_position[0] + base.width > $(window).width()) {
  639. var tip_css = { top: tip_position[1] + "px", right: tip_position[0] + "px", left: "auto" }
  640. } else {
  641. var tip_css = { top: tip_position[1] + "px", left: tip_position[0] + "px", right: "auto" }
  642. }
  643. } else {
  644. var tip_position = [
  645. (function () {
  646. if (settings.offset[0] < 0) {
  647. return offset.left - Math.abs(settings.offset[0]) - base.width
  648. } else if (settings.offset[0] === 0) {
  649. return offset.left - (base.width - $el.outerWidth()) / 2
  650. } else {
  651. return offset.left + $el.outerWidth() + settings.offset[0]
  652. }
  653. })(),
  654. (function () {
  655. if (settings.offset[1] < 0) {
  656. return offset.top - Math.abs(settings.offset[1]) - base.height
  657. } else if (settings.offset[1] === 0) {
  658. return offset.top - (base.height - base.$el.outerHeight()) / 2
  659. } else {
  660. return offset.top + base.$el.outerHeight() + settings.offset[1]
  661. }
  662. })(),
  663. ]
  664. }
  665. $tipsy.css({ top: tip_position[1] + "px", left: tip_position[0] + "px" })
  666. base.settings.show(e, $tipsy.stop(true, true))
  667. },
  668. hide: function (e) {
  669. var base = this
  670. if (base.ready === false) {
  671. return
  672. }
  673. if (e && e.relatedTarget === base.$tip[0]) {
  674. base.$tip.bind("mouseleave", function (e) {
  675. if (e.relatedTarget === base.$el[0]) {
  676. return
  677. }
  678. base.settings.hide(e, base.$tipsy.stop(true, true))
  679. })
  680. return
  681. }
  682. base.settings.hide(e, base.$tipsy.stop(true, true))
  683. },
  684. readify: function () {
  685. this.ready = true
  686. this.$tipsy = $('<div id="tooltipsy' + this.random + '" style="position:fixed;z-index:2147483647;display:none">').appendTo("body")
  687. this.$tip = $('<div class="' + this.settings.className + '">').appendTo(this.$tipsy)
  688. this.$tip.data("rootel", this.$el)
  689. var e = this.$el
  690. var t = this.$tip
  691. this.$tip.html(this.settings.content != "" ? (typeof this.settings.content == "string" ? this.settings.content : this.settings.content(e, t)) : this.title)
  692. },
  693. offset: function (el) {
  694. return this.$el[0].getBoundingClientRect()
  695. },
  696. destroy: function () {
  697. if (this.$tipsy) {
  698. this.$tipsy.remove()
  699. $.removeData(this.$el, "tooltipsy")
  700. }
  701. },
  702. defaults: {
  703. alignTo: "element",
  704. offset: [0, -1],
  705. content: "",
  706. show: function (e, $el) {
  707. $el.fadeIn(100)
  708. },
  709. hide: function (e, $el) {
  710. $el.fadeOut(100)
  711. },
  712. css: {},
  713. className: "tooltipsy",
  714. delay: 200,
  715. showEvent: "mouseenter",
  716. hideEvent: "mouseleave",
  717. },
  718. }
  719. $.fn.tooltipsy = function (options) {
  720. return this.each(function () {
  721. new $.tooltipsy(this, options)
  722. })
  723. }
  724. })(jQuery)
  725. var date = function (format, timestamp) {
  726. timestamp = parseInt(timestamp)
  727. var a,
  728. jsdate = timestamp ? new Date(timestamp * 1000) : new Date()
  729. var pad = function (n, c) {
  730. if ((n = n + "").length < c) {
  731. return new Array(++c - n.length).join("0") + n
  732. } else {
  733. return n
  734. }
  735. }
  736. var txt_weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
  737. var txt_ordin = { 1: "st", 2: "nd", 3: "rd", 21: "st", 22: "nd", 23: "rd", 31: "st" }
  738. var txt_months = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
  739. var f = {
  740. // Day
  741. d: function () {
  742. return pad(f.j(), 2)
  743. },
  744. D: function () {
  745. return f.l().substr(0, 3)
  746. },
  747. j: function () {
  748. return jsdate.getDate()
  749. },
  750. l: function () {
  751. return txt_weekdays[f.w()]
  752. },
  753. N: function () {
  754. return f.w() + 1
  755. },
  756. S: function () {
  757. return txt_ordin[f.j()] ? txt_ordin[f.j()] : "th"
  758. },
  759. w: function () {
  760. return jsdate.getDay()
  761. },
  762. z: function () {
  763. return ((jsdate - new Date(jsdate.getFullYear() + "/1/1")) / 864e5) >> 0
  764. },
  765. // Week
  766. W: function () {
  767. var a = f.z(),
  768. b = 364 + f.L() - a
  769. var nd2,
  770. nd = (new Date(jsdate.getFullYear() + "/1/1").getDay() || 7) - 1
  771. if (b <= 2 && (jsdate.getDay() || 7) - 1 <= 2 - b) {
  772. return 1
  773. } else {
  774. if (a <= 2 && nd >= 4 && a >= 6 - nd) {
  775. nd2 = new Date(jsdate.getFullYear() - 1 + "/12/31")
  776. return date("W", Math.round(nd2.getTime() / 1000))
  777. } else {
  778. return (1 + (nd <= 3 ? (a + nd) / 7 : (a - (7 - nd)) / 7)) >> 0
  779. }
  780. }
  781. },
  782. // Month
  783. F: function () {
  784. return txt_months[f.n()]
  785. },
  786. m: function () {
  787. return pad(f.n(), 2)
  788. },
  789. M: function () {
  790. return f.F().substr(0, 3)
  791. },
  792. n: function () {
  793. return jsdate.getMonth() + 1
  794. },
  795. t: function () {
  796. var n
  797. if ((n = jsdate.getMonth() + 1) == 2) {
  798. return 28 + f.L()
  799. } else {
  800. if ((n & 1 && n < 8) || (!(n & 1) && n > 7)) {
  801. return 31
  802. } else {
  803. return 30
  804. }
  805. }
  806. },
  807. // Year
  808. L: function () {
  809. var y = f.Y()
  810. return !(y & 3) && (y % 1e2 || !(y % 4e2)) ? 1 : 0
  811. },
  812. Y: function () {
  813. return jsdate.getFullYear()
  814. },
  815. y: function () {
  816. return (jsdate.getFullYear() + "").slice(2)
  817. },
  818. // Time
  819. a: function () {
  820. return jsdate.getHours() > 11 ? "pm" : "am"
  821. },
  822. A: function () {
  823. return f.a().toUpperCase()
  824. },
  825. B: function () {
  826. var off = (jsdate.getTimezoneOffset() + 60) * 60
  827. var theSeconds = jsdate.getHours() * 3600 + jsdate.getMinutes() * 60 + jsdate.getSeconds() + off
  828. var beat = Math.floor(theSeconds / 86.4)
  829. if (beat > 1000) beat -= 1000
  830. if (beat < 0) beat += 1000
  831. if (String(beat).length == 1) beat = "00" + beat
  832. if (String(beat).length == 2) beat = "0" + beat
  833. return beat
  834. },
  835. g: function () {
  836. return jsdate.getHours() % 12 || 12
  837. },
  838. G: function () {
  839. return jsdate.getHours()
  840. },
  841. h: function () {
  842. return pad(f.g(), 2)
  843. },
  844. H: function () {
  845. return pad(jsdate.getHours(), 2)
  846. },
  847. i: function () {
  848. return pad(jsdate.getMinutes(), 2)
  849. },
  850. s: function () {
  851. return pad(jsdate.getSeconds(), 2)
  852. },
  853. O: function () {
  854. var t = pad(Math.abs((jsdate.getTimezoneOffset() / 60) * 100), 4)
  855. if (jsdate.getTimezoneOffset() > 0) t = "-" + t
  856. else t = "+" + t
  857. return t
  858. },
  859. P: function () {
  860. var O = f.O()
  861. return O.substr(0, 3) + ":" + O.substr(3, 2)
  862. },
  863. c: function () {
  864. return f.Y() + "-" + f.m() + "-" + f.d() + "T" + f.h() + ":" + f.i() + ":" + f.s() + f.P()
  865. },
  866. U: function () {
  867. return Math.round(jsdate.getTime() / 1000)
  868. },
  869. }
  870. return format.replace(/[\\]?([a-zA-Z])/g, function (t, s) {
  871. if (t != s) {
  872. ret = s
  873. } else if (f[s]) {
  874. ret = f[s]()
  875. } else {
  876. ret = s
  877. }
  878. return ret
  879. })
  880. }
  881. var Base64 = (function () {
  882. var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
  883. var encode = function (input) {
  884. var output = ""
  885. var chr1, chr2, chr3, enc1, enc2, enc3, enc4
  886. var i = 0
  887. input = _utf8_encode(input)
  888. while (i < input.length) {
  889. chr1 = input.charCodeAt(i++)
  890. chr2 = input.charCodeAt(i++)
  891. chr3 = input.charCodeAt(i++)
  892. enc1 = chr1 >> 2
  893. enc2 = ((chr1 & 3) << 4) | (chr2 >> 4)
  894. enc3 = ((chr2 & 15) << 2) | (chr3 >> 6)
  895. enc4 = chr3 & 63
  896. if (isNaN(chr2)) {
  897. enc3 = enc4 = 64
  898. } else if (isNaN(chr3)) {
  899. enc4 = 64
  900. }
  901. output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4)
  902. }
  903. return output
  904. }
  905. // public method for decoding
  906. var decode = function (input) {
  907. var output = ""
  908. var chr1, chr2, chr3
  909. var enc1, enc2, enc3, enc4
  910. var i = 0
  911. input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "")
  912. while (i < input.length) {
  913. enc1 = _keyStr.indexOf(input.charAt(i++))
  914. enc2 = _keyStr.indexOf(input.charAt(i++))
  915. enc3 = _keyStr.indexOf(input.charAt(i++))
  916. enc4 = _keyStr.indexOf(input.charAt(i++))
  917. chr1 = (enc1 << 2) | (enc2 >> 4)
  918. chr2 = ((enc2 & 15) << 4) | (enc3 >> 2)
  919. chr3 = ((enc3 & 3) << 6) | enc4
  920. output = output + String.fromCharCode(chr1)
  921. if (enc3 != 64) {
  922. output = output + String.fromCharCode(chr2)
  923. }
  924. if (enc4 != 64) {
  925. output = output + String.fromCharCode(chr3)
  926. }
  927. }
  928. output = _utf8_decode(output)
  929. return output
  930. }
  931. // private method for UTF-8 encoding
  932. _utf8_encode = function (string) {
  933. string = string.replace(/\r\n/g, "\n")
  934. var utftext = ""
  935. for (var n = 0; n < string.length; n++) {
  936. var c = string.charCodeAt(n)
  937. if (c < 128) {
  938. utftext += String.fromCharCode(c)
  939. } else if (c > 127 && c < 2048) {
  940. utftext += String.fromCharCode((c >> 6) | 192)
  941. utftext += String.fromCharCode((c & 63) | 128)
  942. } else {
  943. utftext += String.fromCharCode((c >> 12) | 224)
  944. utftext += String.fromCharCode(((c >> 6) & 63) | 128)
  945. utftext += String.fromCharCode((c & 63) | 128)
  946. }
  947. }
  948. return utftext
  949. }
  950. // private method for UTF-8 decoding
  951. _utf8_decode = function (utftext) {
  952. var string = ""
  953. var i = 0
  954. var c = (c1 = c2 = 0)
  955. while (i < utftext.length) {
  956. c = utftext.charCodeAt(i)
  957. if (c < 128) {
  958. string += String.fromCharCode(c)
  959. i++
  960. } else if (c > 191 && c < 224) {
  961. c2 = utftext.charCodeAt(i + 1)
  962. string += String.fromCharCode(((c & 31) << 6) | (c2 & 63))
  963. i += 2
  964. } else {
  965. c2 = utftext.charCodeAt(i + 1)
  966. c3 = utftext.charCodeAt(i + 2)
  967. string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63))
  968. i += 3
  969. }
  970. }
  971. return string
  972. }
  973. return {
  974. encode: encode,
  975. decode: decode,
  976. }
  977. })()
  978. var base64_encode = Base64.encode
  979. var base64_decode = Base64.decode
  980. var getParam = function (name) {
  981. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i")
  982. var r = window.location.search.substr(1).match(reg)
  983. if (r != null) return unescape(r[2])
  984. return null
  985. }
  986. var getFormJson = function (frm) {
  987. var o = {}
  988. var a = $(frm).serializeArray()
  989. $.each(a, function () {
  990. if (o[this.name] !== undefined) {
  991. if (!o[this.name].push) {
  992. o[this.name] = [o[this.name]]
  993. }
  994. o[this.name].push(this.value || "")
  995. } else {
  996. o[this.name] = this.value || ""
  997. }
  998. })
  999. return o
  1000. }
  1001. /**
  1002. * 检查ajax的返回结果
  1003. */
  1004. var checkAjaxResult = function (data) {
  1005. if (data.status == 99) {
  1006. if (!window.alerted) {
  1007. alert("您尚未登录或者登录已超时!")
  1008. window.alerted = true
  1009. }
  1010. window.top.location.href = data.data.loginHost
  1011. return false
  1012. } else if (data.status == 98) {
  1013. alert(data.msg)
  1014. return false
  1015. }
  1016. return true
  1017. }
  1018. /**
  1019. * demo:
  1020. * ajax({beforSend:function(){
  1021. * ajaxCheck('remove');
  1022. * }});
  1023. *
  1024. */
  1025. var ajaxCheck = function (method) {
  1026. if (AUTH && AUTH.options) {
  1027. var auth_aid = getParam("auth_aid"),
  1028. auth_mid = getParam("auth_mid")
  1029. return AUTH.options["" + auth_aid]["" + auth_mid] == 1
  1030. }
  1031. return true
  1032. }
  1033. /**
  1034. * 发送ajax请求
  1035. */
  1036. var ajax = function (options) {
  1037. var opts = $.extend(true, {}, options)
  1038. var d = $.extend(
  1039. true,
  1040. {
  1041. auth_aid: getParam("auth_aid"),
  1042. auth_mid: getParam("auth_mid"),
  1043. auth_cid: getParam("auth_cid"),
  1044. },
  1045. opts.data
  1046. )
  1047. opts.data = d
  1048. opts.success = function (data) {
  1049. if (checkAjaxResult(data)) {
  1050. if (options.success) {
  1051. options.success(data)
  1052. }
  1053. }
  1054. }
  1055. $.ajax(opts)
  1056. }