csdn

csdn便利性脚本

  1. // ==UserScript==
  2. // @name csdn
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description csdn便利性脚本
  6. // @author pengqian
  7. // @match *://bbs.csdn.net/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14.  
  15. //#region layer
  16.  
  17. ;!function(window, undefined){
  18. "use strict";
  19.  
  20. var isLayui = window.layui && layui.define, $, win, ready = {
  21. getPath: function(){
  22. return "https://cdn.bootcss.com/layer/3.1.0/";
  23. }(),
  24.  
  25. config: {}, end: {}, minIndex: 0, minLeft: [],
  26. btn: ['确定', '取消'],
  27.  
  28. //五种原始层模式
  29. type: ['dialog', 'page', 'iframe', 'loading', 'tips'],
  30.  
  31. //获取节点的style属性值
  32. getStyle: function(node, name){
  33. var style = node.currentStyle ? node.currentStyle : window.getComputedStyle(node, null);
  34. return style[style.getPropertyValue ? 'getPropertyValue' : 'getAttribute'](name);
  35. },
  36.  
  37. //载入CSS配件
  38. link: function(href, fn, cssname){
  39. //未设置路径,则不主动加载css
  40. if(!layer.path) return;
  41.  
  42. var head = document.getElementsByTagName("head")[0], link = document.createElement('link');
  43. if(typeof fn === 'string') cssname = fn;
  44. var app = (cssname || href).replace(/\.|\//g, '');
  45. var id = 'layuicss-'+ app, timeout = 0;
  46.  
  47. link.rel = 'stylesheet';
  48. link.href = layer.path + href;
  49. link.id = id;
  50.  
  51. if(!document.getElementById(id)){
  52. head.appendChild(link);
  53. }
  54.  
  55. if(typeof fn !== 'function') return;
  56.  
  57. //轮询css是否加载完毕
  58. (function poll() {
  59. if(++timeout > 8 * 1000 / 100){
  60. return window.console && console.error('layer.css: Invalid');
  61. };
  62. parseInt(ready.getStyle(document.getElementById(id), 'width')) === 1989 ? fn() : setTimeout(poll, 100);
  63. }());
  64. }
  65. };
  66.  
  67. //默认内置方法。
  68. var layer = {
  69. v: '3.1.1',
  70. ie: function(){ //ie版本
  71. var agent = navigator.userAgent.toLowerCase();
  72. return (!!window.ActiveXObject || "ActiveXObject" in window) ? (
  73. (agent.match(/msie\s(\d+)/) || [])[1] || '11' //由于ie11并没有msie的标识
  74. ) : false;
  75. }(),
  76. index: (window.layer && window.layer.v) ? 100000 : 0,
  77. path: ready.getPath,
  78. config: function(options, fn){
  79. options = options || {};
  80. layer.cache = ready.config = $.extend({}, ready.config, options);
  81. layer.path = ready.config.path || layer.path;
  82. typeof options.extend === 'string' && (options.extend = [options.extend]);
  83.  
  84. if(ready.config.path) layer.ready();
  85.  
  86. if(!options.extend) return this;
  87.  
  88. isLayui
  89. ? layui.addcss('modules/layer/' + options.extend)
  90. : ready.link('theme/' + options.extend);
  91.  
  92. return this;
  93. },
  94.  
  95. //主体CSS等待事件
  96. ready: function(callback){
  97. var cssname = 'layer', ver = ''
  98. ,path = (isLayui ? 'modules/layer/' : 'theme/') + 'default/layer.css?v='+ layer.v + ver;
  99. isLayui ? layui.addcss(path, callback, cssname) : ready.link(path, callback, cssname);
  100. return this;
  101. },
  102.  
  103. //各种快捷引用
  104. alert: function(content, options, yes){
  105. var type = typeof options === 'function';
  106. if(type) yes = options;
  107. return layer.open($.extend({
  108. content: content,
  109. yes: yes
  110. }, type ? {} : options));
  111. },
  112.  
  113. confirm: function(content, options, yes, cancel){
  114. var type = typeof options === 'function';
  115. if(type){
  116. cancel = yes;
  117. yes = options;
  118. }
  119. return layer.open($.extend({
  120. content: content,
  121. btn: ready.btn,
  122. yes: yes,
  123. btn2: cancel
  124. }, type ? {} : options));
  125. },
  126.  
  127. msg: function(content, options, end){ //最常用提示层
  128. var type = typeof options === 'function', rskin = ready.config.skin;
  129. var skin = (rskin ? rskin + ' ' + rskin + '-msg' : '')||'layui-layer-msg';
  130. var anim = doms.anim.length - 1;
  131. if(type) end = options;
  132. return layer.open($.extend({
  133. content: content,
  134. time: 3000,
  135. shade: false,
  136. skin: skin,
  137. title: false,
  138. closeBtn: false,
  139. btn: false,
  140. resize: false,
  141. end: end
  142. }, (type && !ready.config.skin) ? {
  143. skin: skin + ' layui-layer-hui',
  144. anim: anim
  145. } : function(){
  146. options = options || {};
  147. if(options.icon === -1 || options.icon === undefined && !ready.config.skin){
  148. options.skin = skin + ' ' + (options.skin||'layui-layer-hui');
  149. }
  150. return options;
  151. }()));
  152. },
  153.  
  154. load: function(icon, options){
  155. return layer.open($.extend({
  156. type: 3,
  157. icon: icon || 0,
  158. resize: false,
  159. shade: 0.01
  160. }, options));
  161. },
  162.  
  163. tips: function(content, follow, options){
  164. return layer.open($.extend({
  165. type: 4,
  166. content: [content, follow],
  167. closeBtn: false,
  168. time: 3000,
  169. shade: false,
  170. resize: false,
  171. fixed: false,
  172. maxWidth: 210
  173. }, options));
  174. }
  175. };
  176.  
  177. var Class = function(setings){
  178. var that = this;
  179. that.index = ++layer.index;
  180. that.config = $.extend({}, that.config, ready.config, setings);
  181. document.body ? that.creat() : setTimeout(function(){
  182. that.creat();
  183. }, 30);
  184. };
  185.  
  186. Class.pt = Class.prototype;
  187.  
  188. //缓存常用字符
  189. var doms = ['layui-layer', '.layui-layer-title', '.layui-layer-main', '.layui-layer-dialog', 'layui-layer-iframe', 'layui-layer-content', 'layui-layer-btn', 'layui-layer-close'];
  190. doms.anim = ['layer-anim-00', 'layer-anim-01', 'layer-anim-02', 'layer-anim-03', 'layer-anim-04', 'layer-anim-05', 'layer-anim-06'];
  191.  
  192. //默认配置
  193. Class.pt.config = {
  194. type: 0,
  195. shade: 0.3,
  196. fixed: true,
  197. move: doms[1],
  198. title: '信息',
  199. offset: 'auto',
  200. area: 'auto',
  201. closeBtn: 1,
  202. time: 0, //0表示不自动关闭
  203. zIndex: 19891014,
  204. maxWidth: 360,
  205. anim: 0,
  206. isOutAnim: true,
  207. icon: -1,
  208. moveType: 1,
  209. resize: true,
  210. scrollbar: true, //是否允许浏览器滚动条
  211. tips: 2
  212. };
  213.  
  214. //容器
  215. Class.pt.vessel = function(conType, callback){
  216. var that = this, times = that.index, config = that.config;
  217. var zIndex = config.zIndex + times, titype = typeof config.title === 'object';
  218. var ismax = config.maxmin && (config.type === 1 || config.type === 2);
  219. var titleHTML = (config.title ? '<div class="layui-layer-title" style="'+ (titype ? config.title[1] : '') +'">'
  220. + (titype ? config.title[0] : config.title)
  221. + '</div>' : '');
  222.  
  223. config.zIndex = zIndex;
  224. callback([
  225. //遮罩
  226. config.shade ? ('<div class="layui-layer-shade" id="layui-layer-shade'+ times +'" times="'+ times +'" style="'+ ('z-index:'+ (zIndex-1) +'; ') +'"></div>') : '',
  227.  
  228. //主体
  229. '<div class="'+ doms[0] + (' layui-layer-'+ready.type[config.type]) + (((config.type == 0 || config.type == 2) && !config.shade) ? ' layui-layer-border' : '') + ' ' + (config.skin||'') +'" id="'+ doms[0] + times +'" type="'+ ready.type[config.type] +'" times="'+ times +'" showtime="'+ config.time +'" conType="'+ (conType ? 'object' : 'string') +'" style="z-index: '+ zIndex +'; width:'+ config.area[0] + ';height:' + config.area[1] + (config.fixed ? '' : ';position:absolute;') +'">'
  230. + (conType && config.type != 2 ? '' : titleHTML)
  231. + '<div id="'+ (config.id||'') +'" class="layui-layer-content'+ ((config.type == 0 && config.icon !== -1) ? ' layui-layer-padding' :'') + (config.type == 3 ? ' layui-layer-loading'+config.icon : '') +'">'
  232. + (config.type == 0 && config.icon !== -1 ? '<i class="layui-layer-ico layui-layer-ico'+ config.icon +'"></i>' : '')
  233. + (config.type == 1 && conType ? '' : (config.content||''))
  234. + '</div>'
  235. + '<span class="layui-layer-setwin">'+ function(){
  236. var closebtn = ismax ? '<a class="layui-layer-min" href="javascript:;"><cite></cite></a><a class="layui-layer-ico layui-layer-max" href="javascript:;"></a>' : '';
  237. config.closeBtn && (closebtn += '<a class="layui-layer-ico '+ doms[7] +' '+ doms[7] + (config.title ? config.closeBtn : (config.type == 4 ? '1' : '2')) +'" href="javascript:;"></a>');
  238. return closebtn;
  239. }() + '</span>'
  240. + (config.btn ? function(){
  241. var button = '';
  242. typeof config.btn === 'string' && (config.btn = [config.btn]);
  243. for(var i = 0, len = config.btn.length; i < len; i++){
  244. button += '<a class="'+ doms[6] +''+ i +'">'+ config.btn[i] +'</a>'
  245. }
  246. return '<div class="'+ doms[6] +' layui-layer-btn-'+ (config.btnAlign||'') +'">'+ button +'</div>'
  247. }() : '')
  248. + (config.resize ? '<span class="layui-layer-resize"></span>' : '')
  249. + '</div>'
  250. ], titleHTML, $('<div class="layui-layer-move"></div>'));
  251. return that;
  252. };
  253.  
  254. //创建骨架
  255. Class.pt.creat = function(){
  256. var that = this
  257. ,config = that.config
  258. ,times = that.index, nodeIndex
  259. ,content = config.content
  260. ,conType = typeof content === 'object'
  261. ,body = $('body');
  262.  
  263. if(config.id && $('#'+config.id)[0]) return;
  264.  
  265. if(typeof config.area === 'string'){
  266. config.area = config.area === 'auto' ? ['', ''] : [config.area, ''];
  267. }
  268.  
  269. //anim兼容旧版shift
  270. if(config.shift){
  271. config.anim = config.shift;
  272. }
  273.  
  274. if(layer.ie == 6){
  275. config.fixed = false;
  276. }
  277.  
  278. switch(config.type){
  279. case 0:
  280. config.btn = ('btn' in config) ? config.btn : ready.btn[0];
  281. layer.closeAll('dialog');
  282. break;
  283. case 2:
  284. var content = config.content = conType ? config.content : [config.content||'http://layer.layui.com', 'auto'];
  285. config.content = '<iframe scrolling="'+ (config.content[1]||'auto') +'" allowtransparency="true" id="'+ doms[4] +''+ times +'" name="'+ doms[4] +''+ times +'" onload="this.className=\'\';" class="layui-layer-load" frameborder="0" src="' + config.content[0] + '"></iframe>';
  286. break;
  287. case 3:
  288. delete config.title;
  289. delete config.closeBtn;
  290. config.icon === -1 && (config.icon === 0);
  291. layer.closeAll('loading');
  292. break;
  293. case 4:
  294. conType || (config.content = [config.content, 'body']);
  295. config.follow = config.content[1];
  296. config.content = config.content[0] + '<i class="layui-layer-TipsG"></i>';
  297. delete config.title;
  298. config.tips = typeof config.tips === 'object' ? config.tips : [config.tips, true];
  299. config.tipsMore || layer.closeAll('tips');
  300. break;
  301. }
  302.  
  303. //建立容器
  304. that.vessel(conType, function(html, titleHTML, moveElem){
  305. body.append(html[0]);
  306. conType ? function(){
  307. (config.type == 2 || config.type == 4) ? function(){
  308. $('body').append(html[1]);
  309. }() : function(){
  310. if(!content.parents('.'+doms[0])[0]){
  311. content.data('display', content.css('display')).show().addClass('layui-layer-wrap').wrap(html[1]);
  312. $('#'+ doms[0] + times).find('.'+doms[5]).before(titleHTML);
  313. }
  314. }();
  315. }() : body.append(html[1]);
  316. $('.layui-layer-move')[0] || body.append(ready.moveElem = moveElem);
  317. that.layero = $('#'+ doms[0] + times);
  318. config.scrollbar || doms.html.css('overflow', 'hidden').attr('layer-full', times);
  319. }).auto(times);
  320.  
  321. //遮罩
  322. $('#layui-layer-shade'+ that.index).css({
  323. 'background-color': config.shade[1] || '#000'
  324. ,'opacity': config.shade[0]||config.shade
  325. });
  326.  
  327. config.type == 2 && layer.ie == 6 && that.layero.find('iframe').attr('src', content[0]);
  328.  
  329. //坐标自适应浏览器窗口尺寸
  330. config.type == 4 ? that.tips() : that.offset();
  331. if(config.fixed){
  332. win.on('resize', function(){
  333. that.offset();
  334. (/^\d+%$/.test(config.area[0]) || /^\d+%$/.test(config.area[1])) && that.auto(times);
  335. config.type == 4 && that.tips();
  336. });
  337. }
  338.  
  339. config.time <= 0 || setTimeout(function(){
  340. layer.close(that.index)
  341. }, config.time);
  342. that.move().callback();
  343.  
  344. //为兼容jQuery3.0的css动画影响元素尺寸计算
  345. if(doms.anim[config.anim]){
  346. var animClass = 'layer-anim '+ doms.anim[config.anim];
  347. that.layero.addClass(animClass).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
  348. $(this).removeClass(animClass);
  349. });
  350. };
  351.  
  352. //记录关闭动画
  353. if(config.isOutAnim){
  354. that.layero.data('isOutAnim', true);
  355. }
  356. };
  357.  
  358. //自适应
  359. Class.pt.auto = function(index){
  360. var that = this, config = that.config, layero = $('#'+ doms[0] + index);
  361.  
  362. if(config.area[0] === '' && config.maxWidth > 0){
  363. //为了修复IE7下一个让人难以理解的bug
  364. if(layer.ie && layer.ie < 8 && config.btn){
  365. layero.width(layero.innerWidth());
  366. }
  367. layero.outerWidth() > config.maxWidth && layero.width(config.maxWidth);
  368. }
  369.  
  370. var area = [layero.innerWidth(), layero.innerHeight()]
  371. ,titHeight = layero.find(doms[1]).outerHeight() || 0
  372. ,btnHeight = layero.find('.'+doms[6]).outerHeight() || 0
  373. ,setHeight = function(elem){
  374. elem = layero.find(elem);
  375. elem.height(area[1] - titHeight - btnHeight - 2*(parseFloat(elem.css('padding-top'))|0));
  376. };
  377.  
  378. switch(config.type){
  379. case 2:
  380. setHeight('iframe');
  381. break;
  382. default:
  383. if(config.area[1] === ''){
  384. if(config.maxHeight > 0 && layero.outerHeight() > config.maxHeight){
  385. area[1] = config.maxHeight;
  386. setHeight('.'+doms[5]);
  387. } else if(config.fixed && area[1] >= win.height()){
  388. area[1] = win.height();
  389. setHeight('.'+doms[5]);
  390. }
  391. } else {
  392. setHeight('.'+doms[5]);
  393. }
  394. break;
  395. };
  396.  
  397. return that;
  398. };
  399.  
  400. //计算坐标
  401. Class.pt.offset = function(){
  402. var that = this, config = that.config, layero = that.layero;
  403. var area = [layero.outerWidth(), layero.outerHeight()];
  404. var type = typeof config.offset === 'object';
  405. that.offsetTop = (win.height() - area[1])/2;
  406. that.offsetLeft = (win.width() - area[0])/2;
  407.  
  408. if(type){
  409. that.offsetTop = config.offset[0];
  410. that.offsetLeft = config.offset[1]||that.offsetLeft;
  411. } else if(config.offset !== 'auto'){
  412.  
  413. if(config.offset === 't'){ //上
  414. that.offsetTop = 0;
  415. } else if(config.offset === 'r'){ //右
  416. that.offsetLeft = win.width() - area[0];
  417. } else if(config.offset === 'b'){ //下
  418. that.offsetTop = win.height() - area[1];
  419. } else if(config.offset === 'l'){ //左
  420. that.offsetLeft = 0;
  421. } else if(config.offset === 'lt'){ //左上角
  422. that.offsetTop = 0;
  423. that.offsetLeft = 0;
  424. } else if(config.offset === 'lb'){ //左下角
  425. that.offsetTop = win.height() - area[1];
  426. that.offsetLeft = 0;
  427. } else if(config.offset === 'rt'){ //右上角
  428. that.offsetTop = 0;
  429. that.offsetLeft = win.width() - area[0];
  430. } else if(config.offset === 'rb'){ //右下角
  431. that.offsetTop = win.height() - area[1];
  432. that.offsetLeft = win.width() - area[0];
  433. } else {
  434. that.offsetTop = config.offset;
  435. }
  436.  
  437. }
  438.  
  439. if(!config.fixed){
  440. that.offsetTop = /%$/.test(that.offsetTop) ?
  441. win.height()*parseFloat(that.offsetTop)/100
  442. : parseFloat(that.offsetTop);
  443. that.offsetLeft = /%$/.test(that.offsetLeft) ?
  444. win.width()*parseFloat(that.offsetLeft)/100
  445. : parseFloat(that.offsetLeft);
  446. that.offsetTop += win.scrollTop();
  447. that.offsetLeft += win.scrollLeft();
  448. }
  449.  
  450. if(layero.attr('minLeft')){
  451. that.offsetTop = win.height() - (layero.find(doms[1]).outerHeight() || 0);
  452. that.offsetLeft = layero.css('left');
  453. }
  454.  
  455. layero.css({top: that.offsetTop, left: that.offsetLeft});
  456. };
  457.  
  458. //Tips
  459. Class.pt.tips = function(){
  460. var that = this, config = that.config, layero = that.layero;
  461. var layArea = [layero.outerWidth(), layero.outerHeight()], follow = $(config.follow);
  462. if(!follow[0]) follow = $('body');
  463. var goal = {
  464. width: follow.outerWidth(),
  465. height: follow.outerHeight(),
  466. top: follow.offset().top,
  467. left: follow.offset().left
  468. }, tipsG = layero.find('.layui-layer-TipsG');
  469.  
  470. var guide = config.tips[0];
  471. config.tips[1] || tipsG.remove();
  472.  
  473. goal.autoLeft = function(){
  474. if(goal.left + layArea[0] - win.width() > 0){
  475. goal.tipLeft = goal.left + goal.width - layArea[0];
  476. tipsG.css({right: 12, left: 'auto'});
  477. } else {
  478. goal.tipLeft = goal.left;
  479. };
  480. };
  481.  
  482. //辨别tips的方位
  483. goal.where = [function(){ //上
  484. goal.autoLeft();
  485. goal.tipTop = goal.top - layArea[1] - 10;
  486. tipsG.removeClass('layui-layer-TipsB').addClass('layui-layer-TipsT').css('border-right-color', config.tips[1]);
  487. }, function(){ //右
  488. goal.tipLeft = goal.left + goal.width + 10;
  489. goal.tipTop = goal.top;
  490. tipsG.removeClass('layui-layer-TipsL').addClass('layui-layer-TipsR').css('border-bottom-color', config.tips[1]);
  491. }, function(){ //下
  492. goal.autoLeft();
  493. goal.tipTop = goal.top + goal.height + 10;
  494. tipsG.removeClass('layui-layer-TipsT').addClass('layui-layer-TipsB').css('border-right-color', config.tips[1]);
  495. }, function(){ //左
  496. goal.tipLeft = goal.left - layArea[0] - 10;
  497. goal.tipTop = goal.top;
  498. tipsG.removeClass('layui-layer-TipsR').addClass('layui-layer-TipsL').css('border-bottom-color', config.tips[1]);
  499. }];
  500. goal.where[guide-1]();
  501.  
  502. /* 8*2为小三角形占据的空间 */
  503. if(guide === 1){
  504. goal.top - (win.scrollTop() + layArea[1] + 8*2) < 0 && goal.where[2]();
  505. } else if(guide === 2){
  506. win.width() - (goal.left + goal.width + layArea[0] + 8*2) > 0 || goal.where[3]()
  507. } else if(guide === 3){
  508. (goal.top - win.scrollTop() + goal.height + layArea[1] + 8*2) - win.height() > 0 && goal.where[0]();
  509. } else if(guide === 4){
  510. layArea[0] + 8*2 - goal.left > 0 && goal.where[1]()
  511. }
  512.  
  513. layero.find('.'+doms[5]).css({
  514. 'background-color': config.tips[1],
  515. 'padding-right': (config.closeBtn ? '30px' : '')
  516. });
  517. layero.css({
  518. left: goal.tipLeft - (config.fixed ? win.scrollLeft() : 0),
  519. top: goal.tipTop - (config.fixed ? win.scrollTop() : 0)
  520. });
  521. }
  522.  
  523. //拖拽层
  524. Class.pt.move = function(){
  525. var that = this
  526. ,config = that.config
  527. ,_DOC = $(document)
  528. ,layero = that.layero
  529. ,moveElem = layero.find(config.move)
  530. ,resizeElem = layero.find('.layui-layer-resize')
  531. ,dict = {};
  532.  
  533. if(config.move){
  534. moveElem.css('cursor', 'move');
  535. }
  536.  
  537. moveElem.on('mousedown', function(e){
  538. e.preventDefault();
  539. if(config.move){
  540. dict.moveStart = true;
  541. dict.offset = [
  542. e.clientX - parseFloat(layero.css('left'))
  543. ,e.clientY - parseFloat(layero.css('top'))
  544. ];
  545. ready.moveElem.css('cursor', 'move').show();
  546. }
  547. });
  548.  
  549. resizeElem.on('mousedown', function(e){
  550. e.preventDefault();
  551. dict.resizeStart = true;
  552. dict.offset = [e.clientX, e.clientY];
  553. dict.area = [
  554. layero.outerWidth()
  555. ,layero.outerHeight()
  556. ];
  557. ready.moveElem.css('cursor', 'se-resize').show();
  558. });
  559.  
  560. _DOC.on('mousemove', function(e){
  561.  
  562. //拖拽移动
  563. if(dict.moveStart){
  564. var X = e.clientX - dict.offset[0]
  565. ,Y = e.clientY - dict.offset[1]
  566. ,fixed = layero.css('position') === 'fixed';
  567.  
  568. e.preventDefault();
  569.  
  570. dict.stX = fixed ? 0 : win.scrollLeft();
  571. dict.stY = fixed ? 0 : win.scrollTop();
  572.  
  573. //控制元素不被拖出窗口外
  574. if(!config.moveOut){
  575. var setRig = win.width() - layero.outerWidth() + dict.stX
  576. ,setBot = win.height() - layero.outerHeight() + dict.stY;
  577. X < dict.stX && (X = dict.stX);
  578. X > setRig && (X = setRig);
  579. Y < dict.stY && (Y = dict.stY);
  580. Y > setBot && (Y = setBot);
  581. }
  582.  
  583. layero.css({
  584. left: X
  585. ,top: Y
  586. });
  587. }
  588.  
  589. //Resize
  590. if(config.resize && dict.resizeStart){
  591. var X = e.clientX - dict.offset[0]
  592. ,Y = e.clientY - dict.offset[1];
  593.  
  594. e.preventDefault();
  595.  
  596. layer.style(that.index, {
  597. width: dict.area[0] + X
  598. ,height: dict.area[1] + Y
  599. })
  600. dict.isResize = true;
  601. config.resizing && config.resizing(layero);
  602. }
  603. }).on('mouseup', function(e){
  604. if(dict.moveStart){
  605. delete dict.moveStart;
  606. ready.moveElem.hide();
  607. config.moveEnd && config.moveEnd(layero);
  608. }
  609. if(dict.resizeStart){
  610. delete dict.resizeStart;
  611. ready.moveElem.hide();
  612. }
  613. });
  614.  
  615. return that;
  616. };
  617.  
  618. Class.pt.callback = function(){
  619. var that = this, layero = that.layero, config = that.config;
  620. that.openLayer();
  621. if(config.success){
  622. if(config.type == 2){
  623. layero.find('iframe').on('load', function(){
  624. config.success(layero, that.index);
  625. });
  626. } else {
  627. config.success(layero, that.index);
  628. }
  629. }
  630. layer.ie == 6 && that.IE6(layero);
  631.  
  632. //按钮
  633. layero.find('.'+ doms[6]).children('a').on('click', function(){
  634. var index = $(this).index();
  635. if(index === 0){
  636. if(config.yes){
  637. config.yes(that.index, layero)
  638. } else if(config['btn1']){
  639. config['btn1'](that.index, layero)
  640. } else {
  641. layer.close(that.index);
  642. }
  643. } else {
  644. var close = config['btn'+(index+1)] && config['btn'+(index+1)](that.index, layero);
  645. close === false || layer.close(that.index);
  646. }
  647. });
  648.  
  649. //取消
  650. function cancel(){
  651. var close = config.cancel && config.cancel(that.index, layero);
  652. close === false || layer.close(that.index);
  653. }
  654.  
  655. //右上角关闭回调
  656. layero.find('.'+ doms[7]).on('click', cancel);
  657.  
  658. //点遮罩关闭
  659. if(config.shadeClose){
  660. $('#layui-layer-shade'+ that.index).on('click', function(){
  661. layer.close(that.index);
  662. });
  663. }
  664.  
  665. //最小化
  666. layero.find('.layui-layer-min').on('click', function(){
  667. var min = config.min && config.min(layero);
  668. min === false || layer.min(that.index, config);
  669. });
  670.  
  671. //全屏/还原
  672. layero.find('.layui-layer-max').on('click', function(){
  673. if($(this).hasClass('layui-layer-maxmin')){
  674. layer.restore(that.index);
  675. config.restore && config.restore(layero);
  676. } else {
  677. layer.full(that.index, config);
  678. setTimeout(function(){
  679. config.full && config.full(layero);
  680. }, 100);
  681. }
  682. });
  683.  
  684. config.end && (ready.end[that.index] = config.end);
  685. };
  686.  
  687. //for ie6 恢复select
  688. ready.reselect = function(){
  689. $.each($('select'), function(index , value){
  690. var sthis = $(this);
  691. if(!sthis.parents('.'+doms[0])[0]){
  692. (sthis.attr('layer') == 1 && $('.'+doms[0]).length < 1) && sthis.removeAttr('layer').show();
  693. }
  694. sthis = null;
  695. });
  696. };
  697.  
  698. Class.pt.IE6 = function(layero){
  699. //隐藏select
  700. $('select').each(function(index , value){
  701. var sthis = $(this);
  702. if(!sthis.parents('.'+doms[0])[0]){
  703. sthis.css('display') === 'none' || sthis.attr({'layer' : '1'}).hide();
  704. }
  705. sthis = null;
  706. });
  707. };
  708.  
  709. //需依赖原型的对外方法
  710. Class.pt.openLayer = function(){
  711. var that = this;
  712.  
  713. //置顶当前窗口
  714. layer.zIndex = that.config.zIndex;
  715. layer.setTop = function(layero){
  716. var setZindex = function(){
  717. layer.zIndex++;
  718. layero.css('z-index', layer.zIndex + 1);
  719. };
  720. layer.zIndex = parseInt(layero[0].style.zIndex);
  721. layero.on('mousedown', setZindex);
  722. return layer.zIndex;
  723. };
  724. };
  725.  
  726. ready.record = function(layero){
  727. var area = [
  728. layero.width(),
  729. layero.height(),
  730. layero.position().top,
  731. layero.position().left + parseFloat(layero.css('margin-left'))
  732. ];
  733. layero.find('.layui-layer-max').addClass('layui-layer-maxmin');
  734. layero.attr({area: area});
  735. };
  736.  
  737. ready.rescollbar = function(index){
  738. if(doms.html.attr('layer-full') == index){
  739. if(doms.html[0].style.removeProperty){
  740. doms.html[0].style.removeProperty('overflow');
  741. } else {
  742. doms.html[0].style.removeAttribute('overflow');
  743. }
  744. doms.html.removeAttr('layer-full');
  745. }
  746. };
  747.  
  748. /** 内置成员 */
  749.  
  750. window.layer = layer;
  751.  
  752. //获取子iframe的DOM
  753. layer.getChildFrame = function(selector, index){
  754. index = index || $('.'+doms[4]).attr('times');
  755. return $('#'+ doms[0] + index).find('iframe').contents().find(selector);
  756. };
  757.  
  758. //得到当前iframe层的索引,子iframe时使用
  759. layer.getFrameIndex = function(name){
  760. return $('#'+ name).parents('.'+doms[4]).attr('times');
  761. };
  762.  
  763. //iframe层自适应宽高
  764. layer.iframeAuto = function(index){
  765. if(!index) return;
  766. var heg = layer.getChildFrame('html', index).outerHeight();
  767. var layero = $('#'+ doms[0] + index);
  768. var titHeight = layero.find(doms[1]).outerHeight() || 0;
  769. var btnHeight = layero.find('.'+doms[6]).outerHeight() || 0;
  770. layero.css({height: heg + titHeight + btnHeight});
  771. layero.find('iframe').css({height: heg});
  772. };
  773.  
  774. //重置iframe url
  775. layer.iframeSrc = function(index, url){
  776. $('#'+ doms[0] + index).find('iframe').attr('src', url);
  777. };
  778.  
  779. //设定层的样式
  780. layer.style = function(index, options, limit){
  781. var layero = $('#'+ doms[0] + index)
  782. ,contElem = layero.find('.layui-layer-content')
  783. ,type = layero.attr('type')
  784. ,titHeight = layero.find(doms[1]).outerHeight() || 0
  785. ,btnHeight = layero.find('.'+doms[6]).outerHeight() || 0
  786. ,minLeft = layero.attr('minLeft');
  787.  
  788. if(type === ready.type[3] || type === ready.type[4]){
  789. return;
  790. }
  791.  
  792. if(!limit){
  793. if(parseFloat(options.width) <= 260){
  794. options.width = 260;
  795. };
  796.  
  797. if(parseFloat(options.height) - titHeight - btnHeight <= 64){
  798. options.height = 64 + titHeight + btnHeight;
  799. };
  800. }
  801.  
  802. layero.css(options);
  803. btnHeight = layero.find('.'+doms[6]).outerHeight();
  804.  
  805. if(type === ready.type[2]){
  806. layero.find('iframe').css({
  807. height: parseFloat(options.height) - titHeight - btnHeight
  808. });
  809. } else {
  810. contElem.css({
  811. height: parseFloat(options.height) - titHeight - btnHeight
  812. - parseFloat(contElem.css('padding-top'))
  813. - parseFloat(contElem.css('padding-bottom'))
  814. })
  815. }
  816. };
  817.  
  818. //最小化
  819. layer.min = function(index, options){
  820. var layero = $('#'+ doms[0] + index)
  821. ,titHeight = layero.find(doms[1]).outerHeight() || 0
  822. ,left = layero.attr('minLeft') || (181*ready.minIndex)+'px'
  823. ,position = layero.css('position');
  824.  
  825. ready.record(layero);
  826.  
  827. if(ready.minLeft[0]){
  828. left = ready.minLeft[0];
  829. ready.minLeft.shift();
  830. }
  831.  
  832. layero.attr('position', position);
  833.  
  834. layer.style(index, {
  835. width: 180
  836. ,height: titHeight
  837. ,left: left
  838. ,top: win.height() - titHeight
  839. ,position: 'fixed'
  840. ,overflow: 'hidden'
  841. }, true);
  842.  
  843. layero.find('.layui-layer-min').hide();
  844. layero.attr('type') === 'page' && layero.find(doms[4]).hide();
  845. ready.rescollbar(index);
  846.  
  847. if(!layero.attr('minLeft')){
  848. ready.minIndex++;
  849. }
  850. layero.attr('minLeft', left);
  851. };
  852.  
  853. //还原
  854. layer.restore = function(index){
  855. var layero = $('#'+ doms[0] + index), area = layero.attr('area').split(',');
  856. var type = layero.attr('type');
  857. layer.style(index, {
  858. width: parseFloat(area[0]),
  859. height: parseFloat(area[1]),
  860. top: parseFloat(area[2]),
  861. left: parseFloat(area[3]),
  862. position: layero.attr('position'),
  863. overflow: 'visible'
  864. }, true);
  865. layero.find('.layui-layer-max').removeClass('layui-layer-maxmin');
  866. layero.find('.layui-layer-min').show();
  867. layero.attr('type') === 'page' && layero.find(doms[4]).show();
  868. ready.rescollbar(index);
  869. };
  870.  
  871. //全屏
  872. layer.full = function(index){
  873. var layero = $('#'+ doms[0] + index), timer;
  874. ready.record(layero);
  875. if(!doms.html.attr('layer-full')){
  876. doms.html.css('overflow','hidden').attr('layer-full', index);
  877. }
  878. clearTimeout(timer);
  879. timer = setTimeout(function(){
  880. var isfix = layero.css('position') === 'fixed';
  881. layer.style(index, {
  882. top: isfix ? 0 : win.scrollTop(),
  883. left: isfix ? 0 : win.scrollLeft(),
  884. width: win.width(),
  885. height: win.height()
  886. }, true);
  887. layero.find('.layui-layer-min').hide();
  888. }, 100);
  889. };
  890.  
  891. //改变title
  892. layer.title = function(name, index){
  893. var title = $('#'+ doms[0] + (index||layer.index)).find(doms[1]);
  894. title.html(name);
  895. };
  896.  
  897. //关闭layer总方法
  898. layer.close = function(index){
  899. var layero = $('#'+ doms[0] + index), type = layero.attr('type'), closeAnim = 'layer-anim-close';
  900. if(!layero[0]) return;
  901. var WRAP = 'layui-layer-wrap', remove = function(){
  902. if(type === ready.type[1] && layero.attr('conType') === 'object'){
  903. layero.children(':not(.'+ doms[5] +')').remove();
  904. var wrap = layero.find('.'+WRAP);
  905. for(var i = 0; i < 2; i++){
  906. wrap.unwrap();
  907. }
  908. wrap.css('display', wrap.data('display')).removeClass(WRAP);
  909. } else {
  910. //低版本IE 回收 iframe
  911. if(type === ready.type[2]){
  912. try {
  913. var iframe = $('#'+doms[4]+index)[0];
  914. iframe.contentWindow.document.write('');
  915. iframe.contentWindow.close();
  916. layero.find('.'+doms[5])[0].removeChild(iframe);
  917. } catch(e){}
  918. }
  919. layero[0].innerHTML = '';
  920. layero.remove();
  921. }
  922. typeof ready.end[index] === 'function' && ready.end[index]();
  923. delete ready.end[index];
  924. };
  925.  
  926. if(layero.data('isOutAnim')){
  927. layero.addClass('layer-anim '+ closeAnim);
  928. }
  929.  
  930. $('#layui-layer-moves, #layui-layer-shade' + index).remove();
  931. layer.ie == 6 && ready.reselect();
  932. ready.rescollbar(index);
  933. if(layero.attr('minLeft')){
  934. ready.minIndex--;
  935. ready.minLeft.push(layero.attr('minLeft'));
  936. }
  937.  
  938. if((layer.ie && layer.ie < 10) || !layero.data('isOutAnim')){
  939. remove()
  940. } else {
  941. setTimeout(function(){
  942. remove();
  943. }, 200);
  944. }
  945. };
  946.  
  947. //关闭所有层
  948. layer.closeAll = function(type){
  949. $.each($('.'+doms[0]), function(){
  950. var othis = $(this);
  951. var is = type ? (othis.attr('type') === type) : 1;
  952. is && layer.close(othis.attr('times'));
  953. is = null;
  954. });
  955. };
  956.  
  957. /**
  958.  
  959. 拓展模块,layui开始合并在一起
  960.  
  961. */
  962.  
  963. var cache = layer.cache||{}, skin = function(type){
  964. return (cache.skin ? (' ' + cache.skin + ' ' + cache.skin + '-'+type) : '');
  965. };
  966.  
  967. //仿系统prompt
  968. layer.prompt = function(options, yes){
  969. var style = '';
  970. options = options || {};
  971.  
  972. if(typeof options === 'function') yes = options;
  973.  
  974. if(options.area){
  975. var area = options.area;
  976. style = 'style="width: '+ area[0] +'; height: '+ area[1] + ';"';
  977. delete options.area;
  978. }
  979. var prompt, content = options.formType == 2 ? '<textarea class="layui-layer-input"' + style +'>' + (options.value||'') +'</textarea>' : function(){
  980. return '<input type="'+ (options.formType == 1 ? 'password' : 'text') +'" class="layui-layer-input" value="'+ (options.value||'') +'">';
  981. }();
  982.  
  983. var success = options.success;
  984. delete options.success;
  985.  
  986. return layer.open($.extend({
  987. type: 1
  988. ,btn: ['&#x786E;&#x5B9A;','&#x53D6;&#x6D88;']
  989. ,content: content
  990. ,skin: 'layui-layer-prompt' + skin('prompt')
  991. ,maxWidth: win.width()
  992. ,success: function(layero){
  993. prompt = layero.find('.layui-layer-input');
  994. prompt.focus();
  995. typeof success === 'function' && success(layero);
  996. }
  997. ,resize: false
  998. ,yes: function(index){
  999. var value = prompt.val();
  1000. if(value === ''){
  1001. prompt.focus();
  1002. } else if(value.length > (options.maxlength||500)) {
  1003. layer.tips('&#x6700;&#x591A;&#x8F93;&#x5165;'+ (options.maxlength || 500) +'&#x4E2A;&#x5B57;&#x6570;', prompt, {tips: 1});
  1004. } else {
  1005. yes && yes(value, index, prompt);
  1006. }
  1007. }
  1008. }, options));
  1009. };
  1010.  
  1011. //tab层
  1012. layer.tab = function(options){
  1013. options = options || {};
  1014.  
  1015. var tab = options.tab || {}
  1016. ,THIS = 'layui-this'
  1017. ,success = options.success;
  1018.  
  1019. delete options.success;
  1020.  
  1021. return layer.open($.extend({
  1022. type: 1,
  1023. skin: 'layui-layer-tab' + skin('tab'),
  1024. resize: false,
  1025. title: function(){
  1026. var len = tab.length, ii = 1, str = '';
  1027. if(len > 0){
  1028. str = '<span class="'+ THIS +'">'+ tab[0].title +'</span>';
  1029. for(; ii < len; ii++){
  1030. str += '<span>'+ tab[ii].title +'</span>';
  1031. }
  1032. }
  1033. return str;
  1034. }(),
  1035. content: '<ul class="layui-layer-tabmain">'+ function(){
  1036. var len = tab.length, ii = 1, str = '';
  1037. if(len > 0){
  1038. str = '<li class="layui-layer-tabli '+ THIS +'">'+ (tab[0].content || 'no content') +'</li>';
  1039. for(; ii < len; ii++){
  1040. str += '<li class="layui-layer-tabli">'+ (tab[ii].content || 'no content') +'</li>';
  1041. }
  1042. }
  1043. return str;
  1044. }() +'</ul>',
  1045. success: function(layero){
  1046. var btn = layero.find('.layui-layer-title').children();
  1047. var main = layero.find('.layui-layer-tabmain').children();
  1048. btn.on('mousedown', function(e){
  1049. e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
  1050. var othis = $(this), index = othis.index();
  1051. othis.addClass(THIS).siblings().removeClass(THIS);
  1052. main.eq(index).show().siblings().hide();
  1053. typeof options.change === 'function' && options.change(index);
  1054. });
  1055. typeof success === 'function' && success(layero);
  1056. }
  1057. }, options));
  1058. };
  1059.  
  1060. //相册层
  1061. layer.photos = function(options, loop, key){
  1062. var dict = {};
  1063. options = options || {};
  1064. if(!options.photos) return;
  1065. var type = options.photos.constructor === Object;
  1066. var photos = type ? options.photos : {}, data = photos.data || [];
  1067. var start = photos.start || 0;
  1068. dict.imgIndex = (start|0) + 1;
  1069.  
  1070. options.img = options.img || 'img';
  1071.  
  1072. var success = options.success;
  1073. delete options.success;
  1074.  
  1075. if(!type){ //页面直接获取
  1076. var parent = $(options.photos), pushData = function(){
  1077. data = [];
  1078. parent.find(options.img).each(function(index){
  1079. var othis = $(this);
  1080. othis.attr('layer-index', index);
  1081. data.push({
  1082. alt: othis.attr('alt'),
  1083. pid: othis.attr('layer-pid'),
  1084. src: othis.attr('layer-src') || othis.attr('src'),
  1085. thumb: othis.attr('src')
  1086. });
  1087. })
  1088. };
  1089.  
  1090. pushData();
  1091.  
  1092. if (data.length === 0) return;
  1093.  
  1094. loop || parent.on('click', options.img, function(){
  1095. var othis = $(this), index = othis.attr('layer-index');
  1096. layer.photos($.extend(options, {
  1097. photos: {
  1098. start: index,
  1099. data: data,
  1100. tab: options.tab
  1101. },
  1102. full: options.full
  1103. }), true);
  1104. pushData();
  1105. })
  1106.  
  1107. //不直接弹出
  1108. if(!loop) return;
  1109.  
  1110. } else if (data.length === 0){
  1111. return layer.msg('&#x6CA1;&#x6709;&#x56FE;&#x7247;');
  1112. }
  1113.  
  1114. //上一张
  1115. dict.imgprev = function(key){
  1116. dict.imgIndex--;
  1117. if(dict.imgIndex < 1){
  1118. dict.imgIndex = data.length;
  1119. }
  1120. dict.tabimg(key);
  1121. };
  1122.  
  1123. //下一张
  1124. dict.imgnext = function(key,errorMsg){
  1125. dict.imgIndex++;
  1126. if(dict.imgIndex > data.length){
  1127. dict.imgIndex = 1;
  1128. if (errorMsg) {return};
  1129. }
  1130. dict.tabimg(key)
  1131. };
  1132.  
  1133. //方向键
  1134. dict.keyup = function(event){
  1135. if(!dict.end){
  1136. var code = event.keyCode;
  1137. event.preventDefault();
  1138. if(code === 37){
  1139. dict.imgprev(true);
  1140. } else if(code === 39) {
  1141. dict.imgnext(true);
  1142. } else if(code === 27) {
  1143. layer.close(dict.index);
  1144. }
  1145. }
  1146. }
  1147.  
  1148. //切换
  1149. dict.tabimg = function(key){
  1150. if(data.length <= 1) return;
  1151. photos.start = dict.imgIndex - 1;
  1152. layer.close(dict.index);
  1153. return layer.photos(options, true, key);
  1154. setTimeout(function(){
  1155. layer.photos(options, true, key);
  1156. }, 200);
  1157. }
  1158.  
  1159. //一些动作
  1160. dict.event = function(){
  1161. dict.bigimg.hover(function(){
  1162. dict.imgsee.show();
  1163. }, function(){
  1164. dict.imgsee.hide();
  1165. });
  1166.  
  1167. dict.bigimg.find('.layui-layer-imgprev').on('click', function(event){
  1168. event.preventDefault();
  1169. dict.imgprev();
  1170. });
  1171.  
  1172. dict.bigimg.find('.layui-layer-imgnext').on('click', function(event){
  1173. event.preventDefault();
  1174. dict.imgnext();
  1175. });
  1176.  
  1177. $(document).on('keyup', dict.keyup);
  1178. };
  1179.  
  1180. //图片预加载
  1181. function loadImage(url, callback, error) {
  1182. var img = new Image();
  1183. img.src = url;
  1184. if(img.complete){
  1185. return callback(img);
  1186. }
  1187. img.onload = function(){
  1188. img.onload = null;
  1189. callback(img);
  1190. };
  1191. img.onerror = function(e){
  1192. img.onerror = null;
  1193. error(e);
  1194. };
  1195. };
  1196.  
  1197. dict.loadi = layer.load(1, {
  1198. shade: 'shade' in options ? false : 0.9,
  1199. scrollbar: false
  1200. });
  1201.  
  1202. loadImage(data[start].src, function(img){
  1203. layer.close(dict.loadi);
  1204. dict.index = layer.open($.extend({
  1205. type: 1,
  1206. id: 'layui-layer-photos',
  1207. area: function(){
  1208. var imgarea = [img.width, img.height];
  1209. var winarea = [$(window).width() - 100, $(window).height() - 100];
  1210.  
  1211. //如果 实际图片的宽或者高比 屏幕大(那么进行缩放)
  1212. if(!options.full && (imgarea[0]>winarea[0]||imgarea[1]>winarea[1])){
  1213. var wh = [imgarea[0]/winarea[0],imgarea[1]/winarea[1]];//取宽度缩放比例、高度缩放比例
  1214. if(wh[0] > wh[1]){//取缩放比例最大的进行缩放
  1215. imgarea[0] = imgarea[0]/wh[0];
  1216. imgarea[1] = imgarea[1]/wh[0];
  1217. } else if(wh[0] < wh[1]){
  1218. imgarea[0] = imgarea[0]/wh[1];
  1219. imgarea[1] = imgarea[1]/wh[1];
  1220. }
  1221. }
  1222.  
  1223. return [imgarea[0]+'px', imgarea[1]+'px'];
  1224. }(),
  1225. title: false,
  1226. shade: 0.9,
  1227. shadeClose: true,
  1228. closeBtn: false,
  1229. move: '.layui-layer-phimg img',
  1230. moveType: 1,
  1231. scrollbar: false,
  1232. moveOut: true,
  1233. //anim: Math.random()*5|0,
  1234. isOutAnim: false,
  1235. skin: 'layui-layer-photos' + skin('photos'),
  1236. content: '<div class="layui-layer-phimg">'
  1237. +'<img src="'+ data[start].src +'" alt="'+ (data[start].alt||'') +'" layer-pid="'+ data[start].pid +'">'
  1238. +'<div class="layui-layer-imgsee">'
  1239. +(data.length > 1 ? '<span class="layui-layer-imguide"><a href="javascript:;" class="layui-layer-iconext layui-layer-imgprev"></a><a href="javascript:;" class="layui-layer-iconext layui-layer-imgnext"></a></span>' : '')
  1240. +'<div class="layui-layer-imgbar" style="display:'+ (key ? 'block' : '') +'"><span class="layui-layer-imgtit"><a href="javascript:;">'+ (data[start].alt||'') +'</a><em>'+ dict.imgIndex +'/'+ data.length +'</em></span></div>'
  1241. +'</div>'
  1242. +'</div>',
  1243. success: function(layero, index){
  1244. dict.bigimg = layero.find('.layui-layer-phimg');
  1245. dict.imgsee = layero.find('.layui-layer-imguide,.layui-layer-imgbar');
  1246. dict.event(layero);
  1247. options.tab && options.tab(data[start], layero);
  1248. typeof success === 'function' && success(layero);
  1249. }, end: function(){
  1250. dict.end = true;
  1251. $(document).off('keyup', dict.keyup);
  1252. }
  1253. }, options));
  1254. }, function(){
  1255. layer.close(dict.loadi);
  1256. layer.msg('&#x5F53;&#x524D;&#x56FE;&#x7247;&#x5730;&#x5740;&#x5F02;&#x5E38;<br>&#x662F;&#x5426;&#x7EE7;&#x7EED;&#x67E5;&#x770B;&#x4E0B;&#x4E00;&#x5F20;&#xFF1F;', {
  1257. time: 30000,
  1258. btn: ['&#x4E0B;&#x4E00;&#x5F20;', '&#x4E0D;&#x770B;&#x4E86;'],
  1259. yes: function(){
  1260. data.length > 1 && dict.imgnext(true,true);
  1261. }
  1262. });
  1263. });
  1264. };
  1265.  
  1266. //主入口
  1267. ready.run = function(_$){
  1268. $ = _$;
  1269. win = $(window);
  1270. doms.html = $('html');
  1271. layer.open = function(deliver){
  1272. var o = new Class(deliver);
  1273. return o.index;
  1274. };
  1275. };
  1276.  
  1277. //加载方式
  1278. window.layui && layui.define ? (
  1279. layer.ready()
  1280. ,layui.define('jquery', function(exports){ //layui加载
  1281. layer.path = layui.cache.dir;
  1282. ready.run(layui.$);
  1283.  
  1284. //暴露模块
  1285. window.layer = layer;
  1286. exports('layer', layer);
  1287. })
  1288. ) : (
  1289. (typeof define === 'function' && define.amd) ? define(['jquery'], function(){ //requirejs加载
  1290. ready.run(window.jQuery);
  1291. return layer;
  1292. }) : function(){ //普通script标签加载
  1293. ready.run(window.jQuery);
  1294. layer.ready();
  1295. }()
  1296. );
  1297.  
  1298. }(window);
  1299. //#endregion
  1300.  
  1301. //console.clear();
  1302. console.info("%c启动。。。","color:#4788c7");
  1303. CSDN["version"] = "0.4";
  1304.  
  1305. // var postBody = document.getElementById("post_body");
  1306. // if(postBody == null){
  1307. // var postBodyHtml = '<div class="mod_topic_wrap">'+
  1308. // '<div class="csdn-bbs">'+
  1309. // '<div class="editor1">'+
  1310. // '<div class="comt">'+
  1311. // '<div class="reply">'+
  1312. // '<form accept-charset="UTF-8" class="new_post" id="new_post" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="" /><input name="authenticity_token" type="hidden" value="" /></div><div class="editor">'+
  1313. // '<textarea class="required quoteOnly" cols="40" id="post_body" maxlength="10000" name="post[body]" rows="20"></textarea>'+
  1314. // '<div class="pub"><span class="fr">每天回帖即可获得10分可用分!<a href="/help#common_problem" target="_blank" rel="nofollow" class="pub_tips">小技巧:教您如何更快获得可用分</a><span id="body_count_notice" class="body_count_notice_fixed">你还可以输入10000个字符</span></span>'+
  1315. // '<input id="submit_new_post_form" name="commit" type="submit" value="提交回复" class="btn_b">(Ctrl+Enter)'+
  1316. // '</div>'+
  1317. // '</div>'+
  1318. // '</form>'+
  1319. // '<script id="countTemplate" type="text/x-jquery-tmpl">'+
  1320. // '你还可以输入${count}个字符'+
  1321. // '</script>'+
  1322. // '<ul class="pub_list">'+
  1323. // '<li>请遵守CSDN<a href="/help#user_criterion" target="_blank">用户行为准则</a>,不得违反国家法律法规 ; 转载请注明出自“CSDN(www.csdn.net)”,如是商业用途请联系原作者 ; 请不要讨论政治相关话题。</li>'+
  1324. // '<!--<li>转载请注明出自“CSDN(www.csdn.net)”,如是商业用途请联系原作者。</li>'+
  1325. // '<li>为了维护良好的技术讨论环境,请不要讨论政治相关话题。</li>-->'+
  1326. // '</ul>'+
  1327. // '</div>'+
  1328. // '</div>'+
  1329. // '</div>'+
  1330. // '</div>'+
  1331. // '</div>';
  1332. // var $postBody = $("<div>").html(postBodyHtml);
  1333. // $("body").append($postBody);
  1334. // }
  1335. layer.config({
  1336. path: "https://cdn.bootcss.com/layer/3.1.0/"
  1337. });
  1338. /*
  1339. * 加载阿里矢量图标
  1340. */
  1341. function loadAli(){
  1342. var head = document.getElementsByTagName('head')[0];
  1343. var link = document.createElement('link');
  1344. link.type='text/css';
  1345. link.rel = 'stylesheet';
  1346. link.href = "https://at.alicdn.com/t/font_777112_5mwo44kl4ag.css";
  1347. head.appendChild(link);
  1348. }
  1349.  
  1350. loadAli();
  1351.  
  1352. function arrayRange(start,end ){
  1353. var length = end - start +1;
  1354. var step = start - 1;
  1355. return Array.apply(null,{length:length}).map(function (v,i){step++;return step;});
  1356. }
  1357. function next(maxNumber) {
  1358. return parseInt(Math.random() * (maxNumber - 0 + 1) + 0, 10);
  1359. }
  1360.  
  1361. Array.prototype.select = function(func){
  1362. var arr = [];
  1363. if(typeof(func) == "function"){
  1364. for(var item of this){
  1365. arr.push(func(item));
  1366. }
  1367. }
  1368. return arr;
  1369. }
  1370.  
  1371. //$(document).ready(function(){console.info("document ready.")});
  1372. var face = arrayRange(1,134).select(x => `[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/001/face/${x}.gif][/img]`);
  1373. arrayRange(1,51).forEach(x => face.push(`[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/monkey/${x}.gif][/img]`));
  1374. arrayRange(1,86).forEach(x => face.push(`[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/onion/${x}.gif][/img]`));
  1375. //console.info(face);
  1376. layer.ready(function(){
  1377. // if(postBody == null){
  1378. // $("#markItUpPost_body").hide();
  1379. // }
  1380.  
  1381. var postBody = $("#markItUpPost_body");
  1382. var num = 0;
  1383. function randomSend(){
  1384. console.info(num);
  1385. if(postBody.length > 0 || num >= 10){
  1386. var btn = $('<input type="button" value="随机发送表情" class="btn_b" style="margin-left:15px">').click(function(){
  1387. $("#post_body").val(face[next(face.length)]);
  1388. $(this).parents("form").submit();
  1389. });
  1390. $("#submit_new_post_form").after(btn);
  1391. return;
  1392. }
  1393. num++;
  1394. setTimeout(randomSend,100);
  1395. }
  1396. randomSend();
  1397. var menuItems = $(".forums_tab_l.fl ul li");
  1398. var nFirst;
  1399. menuItems.each((x,y) => {
  1400. if(y.innerText === "待解决"){
  1401. nFirst = $(y);
  1402. return false;
  1403. }
  1404. });
  1405. if(typeof(nFirst) !== "undefined"){
  1406. nFirst.remove();
  1407. $(".forums_tab_l.fl ul").prepend(nFirst);
  1408. }
  1409. $(".bbs_detail_wrap").css({"transition": "all 1s","width":"100%"});
  1410. $(".mod_topic_wrap").each((x,y) => {
  1411. if(typeof($(y).attr("data-topic-id")) === "undefined"){
  1412. $(y).remove();
  1413. return false;
  1414. }
  1415. });
  1416. //楼层宽度占满
  1417. $(".mod_topic_wrap .topic_wrap.clearfix").css({"display":"block"});
  1418. $(".mod_topic_wrap .topic_r.post_info").css({"transition": "all 1s","width":"100%"}).each((x,y) => {
  1419. //引用按钮替换成图标,并移动到左侧
  1420. var quote = $(y).find(".manage_r.fr a:first");
  1421. quote.addClass("iconfont").html("&#xe7f1;").attr("title","引用").css({"font-size":"28px"});
  1422. quote.remove();
  1423. $(y).find(".manage_r.fr span:first").remove();
  1424. var label = $("<label>");
  1425. label.append(quote);
  1426. $(y).find(".manage_l.fl").append(label);
  1427. });
  1428. //头像宽度固定
  1429. $(".mod_topic_wrap .topic_l img.avatar").css({
  1430. height:"auto",
  1431. width:"82px",
  1432. "max-width":"initial",
  1433. "max-height":"initial"
  1434. });
  1435. //编辑器功能栏分割线宽度占满
  1436. $("#markItUpPost_body .tab").css("max-width","100%");
  1437.  
  1438. //#region 广告移除
  1439. $("[id*='ad']").remove();
  1440. $("iframe:not(.bdSug_sd)").parent().remove();
  1441. $(".post_feed_box").parent().remove();
  1442. //#endregion
  1443. var picture = {
  1444. "title": "图片浏览",
  1445. "id": 123,
  1446. "start": 0,
  1447. "data": [
  1448.  
  1449. ]
  1450. };
  1451. $(".post_info .post_body img").css({"cursor":"zoom-in"}).each((x,y) => picture.data.push({
  1452. "alt": "",
  1453. "pid": 666,
  1454. "src": $(y).attr("src"),
  1455. "thumb": $(y).attr("src")
  1456. })).click(function(){
  1457. var index = $(".post_info .post_body img").index(this);
  1458. picture.start = index;
  1459. layer.photos({
  1460. photos: picture,
  1461. anim: 5
  1462. });
  1463. });
  1464. });
  1465. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址