main.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788
  1. //这里的代码是最早写的,很乱,以后整合优化
  2. var editors = [];
  3. var tables = [];
  4. var select = '';
  5. var submitButton = '';
  6. $(document).ready(function()
  7. {
  8. //init();
  9. });
  10. function init()
  11. {
  12. select = '';
  13. edit();
  14. del();
  15. checkbox();
  16. image();
  17. change();
  18. autocomplete();
  19. template();
  20. submit();
  21. loadShow();
  22. initEditor();
  23. initPic();
  24. initDate();
  25. //更新页面一些功能,上边的一些功能等找时间再优化吧
  26. dever_update.init();
  27. hljs.initHighlightingOnLoad();
  28. table();
  29. }
  30. function initMenu()
  31. {
  32. if(typeof(config.layout) != "undefined")
  33. {
  34. $('.list-unstyled li').each(function(j)
  35. {
  36. $(this).unbind('click').bind('click', function()
  37. {
  38. if ($(this).index() == i) {
  39. //return;
  40. }
  41. $('.list-unstyled .active').each(function()
  42. {
  43. $(this).attr('class', '');
  44. $(this).find('a').attr('class', '');
  45. })
  46. $(this).attr('class', 'active');
  47. var a = $(this).find('a');
  48. a.attr('class', 'subdrop');
  49. //alert($(this).attr('class'));
  50. })
  51. });
  52. /*
  53. $('.project-list').each(function(i)
  54. {
  55. $(this).unbind('click').bind('click', function()
  56. {
  57. if ($(this).index() == i) {
  58. return;
  59. }
  60. $('.project-list').each(function()
  61. {
  62. $(this).find('i').parent().attr('class', '');
  63. $(this).find('ul').attr('class', 'list-unstyled upload-menu');
  64. })
  65. $(this).find('i').parent().attr('class', 'active');
  66. $(this).find('ul').attr('class', 'list-unstyled upload-menu in');
  67. })
  68. });
  69. */
  70. }
  71. }
  72. function setOption(e, id)
  73. {
  74. var s = $("select[name="+id+"]");
  75. var v = s.val();
  76. if (!select) {
  77. select = s.clone();
  78. }
  79. s.find('option[parent]').remove();
  80. //查找出需要显示的option并复制
  81. var options = select.find("option[parent="+e.val()+"]").clone();
  82. //将需要显示的option添加到select中
  83. s.append(options);
  84. //因为option.remove()不会刷新控件,需要将新的option切换上去
  85. //这里排除了options.size() == 0的情况
  86. var state = 2;
  87. s.find('option').each(function()
  88. {
  89. var val = $(this).val();
  90. if (v == val) {
  91. state = 1;
  92. }
  93. });
  94. if (state == 1) {
  95. s.val(v);
  96. } else {
  97. s.val(0);
  98. }
  99. }
  100. function table()
  101. {
  102. if ($('.table-responsive').length) {
  103. $('.table-responsive[data-pattern]').each(function()
  104. {
  105. $(this).responsiveTable('update');
  106. });
  107. }
  108. }
  109. function pjax(param)
  110. {
  111. param.timeout = 8000;
  112. $.pjax(param);
  113. }
  114. function initDate()
  115. {
  116. $.datetimepicker.setLocale('ch');
  117. if($(".manage_time").length)
  118. {
  119. $(".manage_time").each(function()
  120. {
  121. $(this).datetimepicker(
  122. {
  123. //inline:true,
  124. timepicker:false,
  125. format:'Y-m-d',
  126. lang:'ch'
  127. });
  128. });
  129. }
  130. if($(".manage_date").length)
  131. {
  132. $(".manage_date").each(function()
  133. {
  134. $(this).datetimepicker(
  135. {
  136. //datepicker:false,
  137. format:'Y-m-d H:i:s',
  138. lang:'ch'
  139. });
  140. });
  141. }
  142. }
  143. function initPic()
  144. {
  145. $('a[rel]').fancybox();
  146. }
  147. function initEditor()
  148. {
  149. if($('.editor').length)
  150. {
  151. $('.editor').each(function()
  152. {
  153. var parent = $(this).parent().parent();
  154. //alert(parent.attr('id'));
  155. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  156. {
  157. return;
  158. }
  159. loadEditor($(this));
  160. //loadKEditor($(this));
  161. })
  162. }
  163. }
  164. function loadKEditor(e)
  165. {
  166. if(!e.length)
  167. {
  168. return;
  169. }
  170. var id = e.attr('id');
  171. var key = e.attr('key');
  172. if(typeof(editors[id]) == "object")
  173. {
  174. editors[id] = undefined;
  175. }
  176. if(typeof(editors[id]) == "undefined")
  177. {
  178. var key = e.attr('key');
  179. var param = {
  180. allowImageUpload: true, //上传图片框本地上传的功能,false为隐藏,默认为true
  181. allowImageRemote : false, //上传图片框网络图片的功能,false为隐藏,默认为true
  182. allowFileManager : false, //浏览图片空间
  183. filterMode : false, //HTML特殊代码过滤
  184. themeType : 'simple',
  185. filePostName : 'file',
  186. uploadJson : config.upload + '.kindeditor?key=' + key,
  187. fileManagerJson : config.upload + '.kindeditorFile?key=' + key
  188. /*,
  189. items : [
  190. 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
  191. 'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
  192. 'insertunorderedlist', '|', 'emoticons', 'image', 'link', 'lineheight']
  193. */
  194. }
  195. KindEditor.ready(function(K) {
  196. editors[id] = K.create('#' + id, param);
  197. });
  198. }
  199. }
  200. function loadEditor(e)
  201. {
  202. //return loadKEditor(e);
  203. if(!e.length)
  204. {
  205. return;
  206. }
  207. var id = e.attr('id');
  208. var key = e.attr('key');
  209. var toolbar = [
  210. 'title'
  211. ,'bold'
  212. ,'italic'
  213. ,'underline'
  214. ,'strikethrough'
  215. ,'fontScale'
  216. ,'color'
  217. ,'ol'
  218. ,'ul'
  219. ,'blockquote'
  220. ,'code'
  221. ,'table'
  222. ,'link'
  223. ,'image'
  224. ,'hr'
  225. ,'indent'
  226. ,'outdent'
  227. ,'alignment'
  228. //,'emoji'
  229. , '|'
  230. ,'html'
  231. ];
  232. if(typeof(editors[id]) == "object")
  233. {
  234. editors[id].destroy();
  235. editors[id] = undefined;
  236. }
  237. if(typeof(editors[id]) == "undefined")
  238. {
  239. editors[id] = new Simditor(
  240. {
  241. textarea: e,
  242. upload:
  243. {
  244. url: config.upload + '.simditor',
  245. params: {key:key},
  246. fileKey: 'file',
  247. connectionCount: 10,
  248. leaveConfirm: 'Uploading is in progress, are you sure to leave this page?'
  249. },
  250. toolbar : toolbar,
  251. emoji:
  252. {
  253. imagePath: config.lib + 'simditor/plugins/emoji/images/emoji/'
  254. }
  255. });
  256. }
  257. }
  258. //更新页面的提交按钮
  259. function submit()
  260. {
  261. if($(".save-data").length)
  262. {
  263. if (submitButton) {
  264. $(".save-data").each(function()
  265. {
  266. $(this).html(submitButton);
  267. })
  268. }
  269. $(".save-data").unbind('click').bind('click', function()
  270. {
  271. submitButton = $(this).html();
  272. $(this).html('loading...');
  273. $(this).unbind('click');
  274. submit_action();
  275. })
  276. }
  277. }
  278. //直接提交更新页的数据
  279. function submit_action()
  280. {
  281. $(".form1").submit();
  282. }
  283. //设置某一个input的值
  284. function set_update(id, value)
  285. {
  286. if($(id).length)
  287. {
  288. $(id).val(value);
  289. }
  290. }
  291. /**
  292. * 批量复制数据
  293. */
  294. function copy_data(e)
  295. {
  296. var html = '<div>';
  297. html += '<div><span>请输入要复制的数量:</span><input type="text" class="form-control form_margin" id="temp_copy_num" /></div>';
  298. html += '</div>';
  299. $('#dever_modal_body').html(html);
  300. $('#dever_modal_title').html('复制数据');
  301. $("#dever_modal_yes").unbind('click').bind('click', function()
  302. {
  303. set_update('#copy_num', $("#temp_copy_num").val());
  304. set_update('#update_where_id', 0);
  305. submit_action();
  306. });
  307. }
  308. //头部菜单
  309. function topMenu(e)
  310. {
  311. var p = e.parent().parent().parent().find('span');
  312. p.html(e.html());
  313. //更新当前的精细权限
  314. var url = config.host + 'top.update_action?json=1';
  315. var id = e.attr('data-id');
  316. $.post(url, {id:id}, function(t)
  317. {
  318. var href = location.href;
  319. if(location.href.indexOf('where_id') != -1)
  320. {
  321. var temp = location.href.split('where_id');
  322. href = temp[0] + 'where_id=' + t;
  323. }
  324. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  325. {
  326. pjax({url: href, container: config.layout})
  327. }
  328. else
  329. {
  330. location.href = href;
  331. }
  332. })
  333. }
  334. //更新页面的批量载入选择
  335. function loadShow()
  336. {
  337. if($(".show_input").length)
  338. {
  339. $(".show_input input").each(function()
  340. {
  341. if($(this).attr('checked'))
  342. {
  343. inputShow($(this), $(this).attr('show_id'));
  344. }
  345. })
  346. $(".show_input select").each(function()
  347. {
  348. if($(this).attr('selected'))
  349. {
  350. inputShow($(this), $(this).attr('show_id'));
  351. }
  352. })
  353. }
  354. }
  355. function inputShow(e,n)
  356. {
  357. var item = e.parent().find('input');
  358. $(".show_" + n).hide();
  359. var array = ['input', 'textarea'];
  360. for(var a in array)
  361. {
  362. if ($(".show_" + n).find(array[a]).length) {
  363. var c = $(".show_" + n).find(array[a]).attr('class');
  364. if (c.indexOf('validate[required]') > -1) {
  365. $(".show_" + n).find(array[a]).removeClass('validate[required]').addClass('validates');
  366. }
  367. }
  368. }
  369. item.each(function()
  370. {
  371. if($(this).get(0).checked == true)
  372. {
  373. inputShowOne($(this),n);
  374. }
  375. });
  376. }
  377. function inputShowOne(e,n)
  378. {
  379. var value = e.val();
  380. //$(".show_" + n).hide();
  381. //$(".show_" + n + '_' + value).attr('style','color:red').show();
  382. $(".show_" + n + '_' + value).show();
  383. var array = ['input', 'textarea'];
  384. for(var a in array)
  385. {
  386. if($(".show_" + n + '_' + value).length && $(".show_" + n + '_' + value).attr('class').indexOf('show_no') == -1)
  387. {
  388. $(".show_" + n + '_' + value).find(array[a]).each(function()
  389. {
  390. var parent = $(this).parent();
  391. if($(this).attr('class') != 'editor' && $(this).attr('class').indexOf('validates') > -1 && parent.find('label').length && parent.find('label').html().indexOf('选填') == -1)
  392. {
  393. $(this).addClass('validate[required]');
  394. }
  395. })
  396. }
  397. }
  398. }
  399. //批量更新
  400. function list_mul(e)
  401. {
  402. var type = parseInt($("#mul_type").val());
  403. if(type != 1 && type != 2)
  404. {
  405. alert('您还没有选择数据更新方式');
  406. return;
  407. }
  408. if(confirm('确定进行此项操作吗?'))
  409. {
  410. //e.html('更新中').unbind('click');
  411. $('#method').val('mul');
  412. $('#function').val('msg');
  413. $('#form1').attr('target', 'f1').submit();
  414. }
  415. }
  416. //搜索
  417. function list_search(e)
  418. {
  419. $('#method').val('search');
  420. $('#function').val('');
  421. $('#form1').attr('target', '').submit();
  422. }
  423. //更新数据
  424. function update(e, id, project, table, notice)
  425. {
  426. var call = function()
  427. {
  428. var col = e.attr('name').replace('up_col_', '');
  429. var value = e.val();
  430. var url = config.host + 'database.update_action?json=1';
  431. $.post(url, {where_id:id,col:col,value:value,project:project,table:table}, function(t)
  432. {
  433. notify('操作已成功!您的操作已修改当前选项!');
  434. preview();
  435. })
  436. }
  437. if(notice && confirm(notice))
  438. {
  439. call();
  440. }
  441. else
  442. {
  443. call();
  444. }
  445. }
  446. function notify(msg)
  447. {
  448. var notice = new PNotify({
  449. title: '提示信息',
  450. text: msg,
  451. buttons: {
  452. closer: false,
  453. sticker: false
  454. }
  455. });
  456. notice.get().click(function() {
  457. notice.remove();
  458. });
  459. }
  460. //模板选择
  461. function template()
  462. {
  463. if(config.template)
  464. {
  465. $('body').attr('class', 'theme-' + config.template);
  466. }
  467. if($(".selector").length)
  468. {
  469. $(".selector").each(function()
  470. {
  471. if($(this).data('check') == 'checked')
  472. {
  473. selector($(this));
  474. }
  475. })
  476. }
  477. }
  478. //选择器
  479. function selector(e)
  480. {
  481. var value = e.data('value');
  482. var name = e.data('name');
  483. $('#'+name+'_value').val(value);
  484. $('.'+name+'_selector').children().css({'border':'1px solid #ccc'});
  485. e.children().css({'border':'1px solid black'});
  486. if(name == 'update_template')
  487. {
  488. $('body').attr('class', 'theme-' + value);
  489. }
  490. }
  491. //根据e的值,来载入其他数据
  492. function loading(e, data)
  493. {
  494. var value = e.val();
  495. if(e.attr('id') && e.attr('id').indexOf('_temp') != -1)
  496. {
  497. var id = e.attr('id').replace('_temp', '');
  498. if($('#' + id).length)
  499. {
  500. var value = $('#' + id).val();
  501. }
  502. }
  503. if(data.element)
  504. {
  505. if(data.url)
  506. {
  507. data.value = value;
  508. $.getJSON(data.url, data, function(t)
  509. {
  510. $('#update_'+data.element+'_value').val(t.data);
  511. });
  512. }
  513. else
  514. {
  515. $('#update_'+data.element+'_value').val(value);
  516. }
  517. }
  518. else if(data.url)
  519. {
  520. data.value = value;
  521. data.where_id = $('#update_where_id').val();
  522. data.table = $('#table').val();
  523. data.project = $('#project').val();
  524. $.getJSON(data.url, data, function(s)
  525. {
  526. t = s.data;
  527. if(t.indexOf('onblur') != -1)
  528. {
  529. eval(t);
  530. }
  531. else
  532. {
  533. var parent = e.parent().parent();
  534. if(t.indexOf('status') == -1)
  535. {
  536. if(data.type == 1)
  537. {
  538. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  539. {
  540. $(this).remove();
  541. });
  542. }
  543. else
  544. {
  545. $('.checking_-1,.checking_3,.checking_4').each(function()
  546. {
  547. $(this).remove();
  548. });
  549. }
  550. parent.after(t);
  551. checkbox();
  552. }
  553. }
  554. });
  555. }
  556. }
  557. //根据e的值,来载入其他数据,先检测是否选中
  558. function checking(name, e, data)
  559. {
  560. var value = [];
  561. $('.' + name).each(function()
  562. {
  563. if($(this).get(0).checked == true)
  564. {
  565. value.push($(this).val());
  566. }
  567. });
  568. if(data.url)
  569. {
  570. data.value = value.join(',');
  571. data.where_id = $('#update_where_id').val();
  572. data.table = $('#table').val();
  573. data.project = $('#project').val();
  574. if(data.check)
  575. {
  576. data.check_value = false;
  577. $(data.check).each(function()
  578. {
  579. if($(this).get(0).checked == true)
  580. {
  581. data.check_value = $(this).val();
  582. }
  583. });
  584. }
  585. $.getJSON(data.url, data, function(s)
  586. {
  587. t = s.data;
  588. var parent = e.parent().parent().parent();
  589. if(t.indexOf('status') == -1)
  590. {
  591. if(data.type == 1)
  592. {
  593. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  594. {
  595. $(this).remove();
  596. });
  597. }
  598. else
  599. {
  600. $('.checking_-1,.checking_3,.checking_4').each(function()
  601. {
  602. $(this).remove();
  603. });
  604. }
  605. parent.after(t);
  606. checkbox();
  607. }
  608. });
  609. }
  610. }
  611. function autocomplete()
  612. {
  613. if($("input[complete]").length)
  614. {
  615. $("input[complete]").each(function()
  616. {
  617. var cache = {};
  618. var self = $(this);
  619. self.autocomplete(
  620. {
  621. minLength: 2,
  622. source: function( request, response )
  623. {
  624. var term = request.term;
  625. if ( term in cache ) {
  626. response( cache[ term ] );
  627. return;
  628. }
  629. $.getJSON(self.attr('complete') + '&callback=?', request, function( data, status, xhr ) {
  630. console.info(data);
  631. cache[ term ] = data;
  632. var state = true;
  633. for(var i in data)
  634. {
  635. if(data[i].id <=0)
  636. {
  637. state = false;
  638. }
  639. }
  640. if(state)
  641. {
  642. response( data );
  643. }
  644. });
  645. },
  646. select: function( event, ui )
  647. {
  648. //log( "Selected: " + ui.item.value + " aka " + ui.item.id );
  649. var value = self.attr('complete_callback');
  650. var id = self.attr('id').replace('_temp', '');
  651. $("#" + id).val(ui.item[value]);
  652. }
  653. });
  654. })
  655. }
  656. }
  657. //后台通用的提示
  658. function msg(value)
  659. {
  660. if(!value.data)
  661. {
  662. value.data = value.msg;
  663. }
  664. if(value == 1)
  665. {
  666. location.reload();
  667. return;
  668. }
  669. submit();
  670. var url = '';
  671. if(value.data != 'reload' && value.status == 2)
  672. {
  673. showAlert(value.msg, false, '错误提示');
  674. //alert(value.data);
  675. //location.reload();
  676. return;
  677. }
  678. else if(value.data == 'reload')
  679. {
  680. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  681. {
  682. pjax({url: location.href, container: config.layout})
  683. }
  684. else
  685. {
  686. location.reload();
  687. }
  688. return;
  689. }
  690. else
  691. {
  692. if(value.data.indexOf('http://') != -1)
  693. {
  694. url = value.data;
  695. }
  696. else if($("#url").length)
  697. {
  698. url = $("#url").val();
  699. }
  700. else
  701. {
  702. notify(value.data)
  703. return;
  704. }
  705. if(url)
  706. {
  707. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  708. {
  709. pjax({url: url, container: config.layout});
  710. }
  711. else
  712. {
  713. location.href = url;
  714. }
  715. }
  716. else
  717. {
  718. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  719. {
  720. pjax({url: location.href, container: config.layout});
  721. }
  722. else
  723. {
  724. location.reload();
  725. }
  726. }
  727. }
  728. return;
  729. }
  730. /**
  731. * 处理多选问题,处理全选按钮
  732. */
  733. function checkbox()
  734. {
  735. if($(".autoload").length)
  736. {
  737. $(".autoload").each(function()
  738. {
  739. if($(this).get(0).checked == true)
  740. {
  741. $(this).removeClass('autoload');
  742. $(this).load();
  743. }
  744. });
  745. }
  746. if($(".autoload_text").length)
  747. {
  748. $(".autoload_text").each(function()
  749. {
  750. if($(this).val())
  751. {
  752. $(this).removeClass('autoload_text');
  753. $(this).load();
  754. }
  755. });
  756. }
  757. var name = 'checkbox-checkall';
  758. var checkbox = $("." + name);
  759. if(checkbox.length)
  760. {
  761. checkbox.click(function()
  762. {
  763. var self = $(this);
  764. $("." + name + "-" + self.val()).each(function()
  765. {
  766. $(this).get(0).checked = self.get(0).checked;
  767. var next = $(this).next();
  768. if($(this).get(0).checked == true)
  769. {
  770. if(next.length)
  771. {
  772. //next.attr('disabled', false);
  773. }
  774. if($("#mul_type").length)
  775. {
  776. $("#mul_type").val(1);
  777. }
  778. }
  779. else
  780. {
  781. if(next.length)
  782. {
  783. //next.attr('disabled', true);
  784. }
  785. if($("#mul_type").length)
  786. {
  787. $("#mul_type").val(0);
  788. }
  789. }
  790. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  791. inputShow($(this), 'col');
  792. }
  793. })
  794. });
  795. checkbox.each(function()
  796. {
  797. var self = $(this);
  798. $("." + name + "-" + self.val()).each(function()
  799. {
  800. $(this).click(function()
  801. {
  802. var next = $(this).next();
  803. if($(this).get(0).checked == true)
  804. {
  805. self.get(0).checked = true;
  806. if(self.attr('type') == 'radio')
  807. {
  808. //如果父选项是radio类型,做下限制
  809. //alert(1);
  810. }
  811. if($("#mul_type").length)
  812. {
  813. $("#mul_type").val(1);
  814. }
  815. if(next.length)
  816. {
  817. //next.attr('disabled', false);
  818. }
  819. }
  820. else
  821. {
  822. //子选项取消时,处理一下父级选项
  823. var num = 0;
  824. $("." + name + "-" + self.val()).each(function()
  825. {
  826. if($(this).get(0).checked == true)
  827. {
  828. num = 1;
  829. }
  830. });
  831. if(num == 0)
  832. {
  833. self.get(0).checked = false;
  834. if($("#mul_type").length)
  835. {
  836. $("#mul_type").val(0);
  837. }
  838. }
  839. if(next.length)
  840. {
  841. //next.attr('disabled', true);
  842. }
  843. }
  844. })
  845. if($(this).get(0).checked == true)
  846. {
  847. self.get(0).checked = true;
  848. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  849. inputShow($(this), 'col');
  850. }
  851. }
  852. });
  853. })
  854. }
  855. }
  856. /**
  857. * 处理双击编辑
  858. */
  859. function edit()
  860. {
  861. if($(".edit").length)
  862. {
  863. $(".edit").each(function()
  864. {
  865. $(this).bind('dblclick', function()
  866. {
  867. var col = $(this).attr('data-col');
  868. var project = $(this).attr('data-project');
  869. var table = $(this).attr('data-table');
  870. var url = $(this).attr('data-url');
  871. var id = $(this).attr('data-id');
  872. var html = $(this).attr('data-content');
  873. var type = $(this).attr('data-type');
  874. if($(this).find(".edit-content").length)
  875. {
  876. html = $(this).find(".edit-content").html();
  877. html = html.replace('<!--', '<');
  878. html = html.replace('-->', '>');
  879. }
  880. if(html.indexOf('input') == -1)
  881. {
  882. if(type && type == 'textarea')
  883. {
  884. $(this).html('<textarea type="text" name="edit" id="edit" rows="10" cols="60">'+html+'</textarea>');
  885. }
  886. else
  887. {
  888. $(this).html('<input type="text" name="edit" id="edit" value="'+html+'">');
  889. }
  890. var self = $(this);
  891. self.find("#edit").blur(function()
  892. {
  893. var value = self.find("#edit").val();
  894. if(!value)
  895. {
  896. alert('不能为空');
  897. return;
  898. }
  899. if($(this).find(".edit-content").length)
  900. {
  901. $(this).find(".edit-content").html(value);
  902. }
  903. else
  904. {
  905. self.attr('data-content', value);
  906. }
  907. self.html(value);
  908. $.post(url, {project:project,table:table,value:value,where_id:id,col:col}, function(t)
  909. {
  910. notify('修改成功');
  911. preview();
  912. /*
  913. if(type && type == 'textarea')
  914. {
  915. self.html(t);
  916. }
  917. */
  918. })
  919. })
  920. }
  921. });
  922. })
  923. }
  924. }
  925. function preview()
  926. {
  927. if($("#preview").length)
  928. {
  929. var time = Date.parse(new Date());
  930. var src = $('#preview').attr('src').split('#');
  931. $('#preview').attr('src', src[0] + '&' + time + '#' + src[1]);
  932. }
  933. }
  934. function del()
  935. {
  936. if($(".oper_delete").length)
  937. {
  938. $(".oper_delete").each(function()
  939. {
  940. var href = $(this).attr('href');
  941. $(this).attr('href', '#');
  942. $(this).unbind('click');
  943. $(this).bind('click', function()
  944. {
  945. del_act(href);
  946. });
  947. })
  948. }
  949. }
  950. /**
  951. * 处理删除
  952. */
  953. function del_act(href)
  954. {
  955. if(confirm('确定进行此项操作吗?'))
  956. {
  957. $.getJSON(href + '&json=1&callback=?', {}, function(t)
  958. {
  959. msg(t);
  960. })
  961. }
  962. }
  963. /**
  964. * 处理特殊加载的按钮
  965. */
  966. function load(href)
  967. {
  968. if(confirm('确定进行此项操作吗?'))
  969. {
  970. if(href.indexOf('&') == -1)
  971. {
  972. href += '?json=1&callback=?';
  973. }
  974. else
  975. {
  976. href += '&json=1&callback=?';
  977. }
  978. $.getJSON(href, {}, function(t)
  979. {
  980. msg(t);
  981. //location.reload();
  982. })
  983. }
  984. /*
  985. showAlert('确定进行此项操作吗?', function()
  986. {
  987. $("#dever_modal_no").click();
  988. $.getJSON(href + '&json=1', {}, function(t)
  989. {
  990. msg(t);
  991. })
  992. });
  993. */
  994. }
  995. /**
  996. * 处理特殊加载的按钮
  997. */
  998. function jump(href)
  999. {
  1000. location.href = href;
  1001. }
  1002. /**
  1003. * 处理change
  1004. */
  1005. function change()
  1006. {
  1007. if($(".change").length)
  1008. {
  1009. $(".change").each(function()
  1010. {
  1011. var key = $(this).attr('data-child');
  1012. /*
  1013. $('.' + key).each(function()
  1014. {
  1015. if($(this).find('select option:selected').val())
  1016. {
  1017. $(this).show();
  1018. $('#set_cate_id_child').get(0).value = $(this).attr('parent');
  1019. }
  1020. });
  1021. */
  1022. $(this).change(function()
  1023. {
  1024. $('.' + key).hide();
  1025. var v = $('.' + key + '_' + $(this).val());
  1026. var s = v.find('select');
  1027. s.change(function()
  1028. {
  1029. $('.' + key + '_value').val($(this).val());
  1030. })
  1031. if(v.length)
  1032. {
  1033. $('.' + key + '_value').val(s.val());
  1034. v.show();
  1035. }
  1036. else
  1037. {
  1038. $('.' + key + '_value').val(-1);
  1039. }
  1040. });
  1041. if($(this).val() > 0)
  1042. {
  1043. $(this).change();
  1044. }
  1045. });
  1046. }
  1047. }
  1048. /**
  1049. * 处理图库系统
  1050. */
  1051. function image()
  1052. {
  1053. if($(".dever-note").length)
  1054. {
  1055. $(".dever-note").each(function()
  1056. {
  1057. var key = $(this).attr('key');
  1058. $(this).inlineattachment(
  1059. {
  1060. uploadUrl: config.upload + '.drag?key='+ key
  1061. });
  1062. });
  1063. }
  1064. if($(".image_upload").length)
  1065. {
  1066. $(".image_upload").each(function(i)
  1067. {
  1068. var parent = $(this).parent().parent();
  1069. //alert(parent.attr('id'));
  1070. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1071. {
  1072. return;
  1073. }
  1074. loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1075. })
  1076. }
  1077. }
  1078. /**
  1079. * 修改密码
  1080. */
  1081. function pass(e)
  1082. {
  1083. var html = '<style>.password_edit div{margin:10px;}.password_edit input{width:200px;}</style><div class="password_edit">';
  1084. html += '<div><span>旧密码:</span><input type="password" class="form-control form_margin" id="edit_old_password" /></div>';
  1085. html += '<div><span>新密码:</span><input type="password" class="form-control form_margin" id="edit_new_password" /></div>';
  1086. html += '</div>';
  1087. $('#dever_modal_body').html(html);
  1088. $('#dever_modal_title').html('修改密码');
  1089. $("#dever_modal_yes").unbind('click').bind('click', function()
  1090. {
  1091. var old_password = $("#edit_old_password").val();
  1092. var new_password = $("#edit_new_password").val();
  1093. if(!old_password || !new_password)
  1094. {
  1095. alert('请输入密码');
  1096. return;
  1097. }
  1098. if(old_password == new_password)
  1099. {
  1100. alert('旧密码和新密码相同');
  1101. return;
  1102. }
  1103. $.post(config.host + 'auth.password', {old:old_password,new:new_password}, function(t)
  1104. {
  1105. alert(t);
  1106. $("#dever_modal_no").click();
  1107. })
  1108. })
  1109. }
  1110. var MSG = [];
  1111. /**
  1112. * 打开弹窗
  1113. */
  1114. //function showMsg(title, e, id, func)
  1115. function showMsg(title, e, id, func)
  1116. {
  1117. if(id.indexOf('http://') == -1)
  1118. {
  1119. if($(id).length)
  1120. {
  1121. var html = $(id).html();
  1122. if($(id).html())
  1123. {
  1124. var html = $(id).html();
  1125. MSG[id] = html;
  1126. $(id).html('');
  1127. }
  1128. else
  1129. {
  1130. var html = MSG[id];
  1131. }
  1132. }
  1133. else
  1134. {
  1135. var html = id;
  1136. }
  1137. $('#dever_modal_body').html(html);
  1138. $('#dever_modal_title').html(title);
  1139. if(func)
  1140. {
  1141. $("#dever_modal_yes").unbind('click').bind('click', func);
  1142. }
  1143. }
  1144. else
  1145. {
  1146. if(e)
  1147. {
  1148. data = e.attr('msg-send');
  1149. }
  1150. $.getJSON(id+'?json=1',{data:data},function(t)
  1151. {
  1152. t = t.data;
  1153. $('#dever_modal_body').html(t);
  1154. $('#dever_modal_title').html(title);
  1155. if(func)
  1156. {
  1157. $("#dever_modal_yes").unbind('click').bind('click', func);
  1158. }
  1159. });
  1160. }
  1161. }
  1162. function updateMsg(id)
  1163. {
  1164. $("#"+id).submit();
  1165. }
  1166. function showAlert(msg, func, title)
  1167. {
  1168. if (!title) {
  1169. title = $("#dever-name").html() + '提醒您';
  1170. }
  1171. //$("#dever_modal_no").click();
  1172. $("#dever_modal").modal();
  1173. $('#dever_modal_body').html(msg);
  1174. $('#dever_modal_title').html(title);
  1175. if(func)
  1176. {
  1177. $("#dever_modal_yes").unbind('click').bind('click', func);
  1178. }
  1179. else
  1180. {
  1181. $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
  1182. }
  1183. }
  1184. /*
  1185. var test =
  1186. {
  1187. refreshPage: false,
  1188. addAjaxFlag: true,
  1189. //添加收藏
  1190. add: function(cfg)
  1191. {
  1192. }
  1193. }
  1194. */
  1195. function showToggle(e)
  1196. {
  1197. var id = e.attr('toggle');
  1198. var child = e.attr('toggle_child');
  1199. var parent = e.parent();
  1200. parent.parent().find('li').removeClass('active');
  1201. parent.addClass('active');
  1202. $(child).fadeOut(100);
  1203. $(id).fadeIn(500);
  1204. loadEditor($(id).find('.editor'));
  1205. }
  1206. function select_mul(level, id, url, name, value, valid, w, num)
  1207. {
  1208. if(level == 0)
  1209. {
  1210. $(id).find('select').remove();
  1211. $(id).find('span').remove();
  1212. return;
  1213. }
  1214. var parent = value.split(',');
  1215. var cur = parent[0];
  1216. parent.remove(cur);
  1217. value = parent.join(',');
  1218. var html = '';
  1219. var old = level;
  1220. if(level != -1)
  1221. {
  1222. if($(id + '_' + level).length)
  1223. {
  1224. level = $(id + '_' + level).val();
  1225. }
  1226. if(level == 0)
  1227. {
  1228. $(id + '_' + old).nextAll('select').remove();
  1229. $(id + '_' + old).next('span').nextAll('span').remove();
  1230. if($('#' + name + '_level_value').length)
  1231. {
  1232. var total = $(id).find('select').length;
  1233. $('#' + name + '_level_value').val(total);
  1234. }
  1235. if(old == -2 && $('#' + name + '_value_value').length)
  1236. {
  1237. $('#' + name + '_value_value').val(level);
  1238. }
  1239. return;
  1240. }
  1241. if(old == -2)
  1242. {
  1243. $(id + '_' + old).nextAll('select').remove();
  1244. $(id + '_' + old).next('span').nextAll('span').remove();
  1245. }
  1246. if($('#' + name + '_value_value').length)
  1247. {
  1248. $('#' + name + '_value_value').val(level);
  1249. }
  1250. }
  1251. var total = $(id).find('select').length;
  1252. if(num > 0 && total >= num)
  1253. {
  1254. return;
  1255. }
  1256. var get = url.replace('{level}', level);
  1257. if(level == -1)
  1258. {
  1259. level = -2;
  1260. }
  1261. if(!$(id + '_' + level).length)
  1262. {
  1263. $.getJSON(get + '&json=1', function(t)
  1264. {
  1265. var check = '';
  1266. if(!t.status)
  1267. {
  1268. html = '<select style="'+w+'display:inline;margin-top:10px;" class="update_value form-control '+valid+' dever-mul-'+name+'_'+level+'" name="'+name+'[]" onchange="select_mul('+level+', \''+id+'\', \''+url+'\', \''+name+'\', \''+value+'\', \''+valid+'\', \''+w+'\', '+num+');">';
  1269. for(a in t.data)
  1270. {
  1271. if(t.data[a].value)
  1272. {
  1273. check = '';
  1274. if(cur == t.data[a].value)
  1275. {
  1276. check = ' selected';
  1277. }
  1278. html += '<option value="'+t.data[a].value+'" '+check+'>'+t.data[a].name+'</option>';
  1279. }
  1280. }
  1281. html += '</select><span>&nbsp;&nbsp;</span>';
  1282. $(id).append(html);
  1283. $(id + '_' + level).change();
  1284. }
  1285. else
  1286. {
  1287. $(id + '_' + old).nextAll('select').remove();
  1288. $(id + '_' + old).next('span').nextAll('span').remove();
  1289. }
  1290. if($('#' + name + '_level_value').length)
  1291. {
  1292. var total = $(id).find('select').length;
  1293. $('#' + name + '_level_value').val(total);
  1294. }
  1295. if($('#' + name + '_up_value').length)
  1296. {
  1297. $('#' + name + '_up_value').val($(id + '_-2').val());
  1298. }
  1299. });
  1300. }
  1301. }
  1302. //处理更新页面的一些功能,写到一起吧
  1303. var dever_update =
  1304. {
  1305. addIndex : 2,
  1306. index : [],
  1307. auto : false,
  1308. save_key : '',
  1309. init : function()
  1310. {
  1311. var self = this;
  1312. // 增加整个更新的表单
  1313. if($(".dever_update_add").length)
  1314. {
  1315. $('.dever_update_add').unbind('click').bind('click', function()
  1316. {
  1317. self.add($(this));
  1318. })
  1319. }
  1320. /* 以后再增加 同时更新另外一个表
  1321. if($(".form-add-content").length)
  1322. {
  1323. var url = config.host + 'auth.password';
  1324. var url = 'http://localhost/dever/manage/?database.update?project=weixin&table=message&menu=weixin&menu_id=39&ajax=1';
  1325. $.get(url, function(t)
  1326. {
  1327. $(".form-add-content").html(t);
  1328. init();
  1329. })
  1330. }
  1331. */
  1332. //增加某一部分表单
  1333. if($(".dever_form_add").length)
  1334. {
  1335. $('.dever_form_add').each(function()
  1336. {
  1337. var key = $.attr('toggle_key');
  1338. if(typeof(self.index[key]) == "undefined")
  1339. {
  1340. self.index[key] = 0;
  1341. }
  1342. $(this).unbind('click').bind('click', function()
  1343. {
  1344. self.append($(this));
  1345. })
  1346. })
  1347. self.del();
  1348. }
  1349. // 开启自动保存
  1350. if($("#struct").length)
  1351. {
  1352. var save = $("#struct").attr('save');
  1353. if(save == 'yes')
  1354. {
  1355. //检测
  1356. self.save_key = location.href + 'test';
  1357. self.check();
  1358. }
  1359. }
  1360. if($('.dever-note').length)
  1361. {
  1362. $('.dever-note').each(function()
  1363. {
  1364. var mditor = new Mditor($(this),{
  1365. fixedHeight:true
  1366. });
  1367. mditor.openPreview();
  1368. })
  1369. }
  1370. },
  1371. save : function()
  1372. {
  1373. //var data = $("#data-1").html();
  1374. var data = [];
  1375. $(".update_value").each(function(i)
  1376. {
  1377. if($(this).attr("update_type") == 'checked')
  1378. {
  1379. data[i] = $(this).get(0).checked;
  1380. }
  1381. else if($(this).attr("update_type") == 'html')
  1382. {
  1383. data[i] = $(this).html();
  1384. }
  1385. else if($(this).attr("update_type") == 'src')
  1386. {
  1387. data[i] = $(this).attr('src');
  1388. }
  1389. else
  1390. {
  1391. data[i] = $(this).val();
  1392. }
  1393. });
  1394. store.set(this.save_key, data.join('|||'));
  1395. //console.info(data);
  1396. },
  1397. recover : function()
  1398. {
  1399. if(confirm('确定恢复上次保存的数据吗?'))
  1400. {
  1401. var data = store.get(this.save_key).split('|||');
  1402. if(data)
  1403. {
  1404. var value = $(".update_value");
  1405. for(var k in data)
  1406. {
  1407. var e = value.eq(k);
  1408. if(e.attr('update_type') == 'checked')
  1409. {
  1410. if(data[k] == 'true')
  1411. {
  1412. e.get(0).checked = true;
  1413. }
  1414. else
  1415. {
  1416. e.get(0).checked = false;
  1417. }
  1418. }
  1419. else if(e.attr('update_type') == 'html')
  1420. {
  1421. e.html(data[k]);
  1422. }
  1423. else if(e.attr('update_type') == 'src')
  1424. {
  1425. e.attr('src', data[k]);
  1426. }
  1427. else
  1428. {
  1429. if(e.attr('id'))
  1430. {
  1431. var id = e.attr('id');
  1432. if(typeof(editors[id]) != "undefined")
  1433. {
  1434. editors[id].setContent(data[k]);
  1435. }
  1436. }
  1437. e.val(data[k]);
  1438. }
  1439. }
  1440. store.set(this.save_key, '');
  1441. this.check();
  1442. }
  1443. }
  1444. },
  1445. check : function()
  1446. {
  1447. var data = store.get(this.save_key);
  1448. var self = this;
  1449. if(data)
  1450. {
  1451. $(".dever_save").unbind('click').bind('click', function()
  1452. {
  1453. self.recover();
  1454. }).show();
  1455. }
  1456. else
  1457. {
  1458. $(".dever_save").hide();
  1459. self.auto = setInterval(function(){self.save()}, 3000);
  1460. }
  1461. },
  1462. del : function()
  1463. {
  1464. var self = this;
  1465. if($(".dever_form_delete").length)
  1466. {
  1467. $('.dever_form_delete').each(function()
  1468. {
  1469. $(this).unbind('click').bind('click', function()
  1470. {
  1471. var parent = $(this).parent();
  1472. var id = parent.attr('id');
  1473. var index = parseInt($('#tab-' + id).attr('toggle_id'));
  1474. var key = $('#tab-' + id).attr('toggle_key');
  1475. if(index <= 1 && self.index[key] <= index)
  1476. {
  1477. }
  1478. else if(index <= 1 && self.index[key] > index)
  1479. {
  1480. index = index+1;
  1481. $("#tab-"+key+"-child-" + index).click();
  1482. }
  1483. else
  1484. {
  1485. index = index-1;
  1486. $("#tab-"+key+"-child-" + index).click();
  1487. };
  1488. $('#tab-' + id).parent().remove();
  1489. parent.remove();
  1490. self.index[key]--;
  1491. })
  1492. })
  1493. }
  1494. },
  1495. append : function(e)
  1496. {
  1497. var self = this;
  1498. var key = e.attr('toggle_key');
  1499. var child = '.dever_'+key+'_child';
  1500. if(typeof(self.index[key]) == "undefined")
  1501. {
  1502. self.index[key] = 0;
  1503. }
  1504. if(self.index[key] <= 0)
  1505. {
  1506. self.index[key] = $(child).length;
  1507. }
  1508. if(self.index[key] > 30)
  1509. {
  1510. alert('最多只能增加30条');
  1511. return;
  1512. }
  1513. var p = e.parent();
  1514. var id = key + '-child-' + self.index[key];
  1515. var name = '第' + (self.index[key]) + '条';
  1516. p.before('<li><a href="javascript:;" id="tab-'+id+'" toggle_key="'+key+'" toggle_id="'+self.index[key]+'" toggle_child="'+child+'" toggle="#'+id+'" onclick="showToggle($(this))">'+name+'</a></li>');
  1517. var e = e.parent().parent();
  1518. var n = e.next();
  1519. var p = e.parent();
  1520. var content = n.html();
  1521. content = content.replaceAll('_c_', '_c_' + (self.index[key]-1) + '_i_');
  1522. content = '<div id="'+id+'" style="display:none;" class="'+n.attr('class')+' dever_form_add_child">' + content + '</div>';
  1523. p.append(content);
  1524. $('#update_' + key +'_c_' + (self.index[key]-1) + '_i_' + 'order_value').val(parseInt($('#update_' + key +'_c_' + (self.index[key]-2) + '_i_' + 'order_value').val())+1);
  1525. self.del();
  1526. //$("html,body").animate({scrollTop:$('.dever_form_add_child').eq(this.appendIndex).offset().top},500);
  1527. self.index[key]++;
  1528. image();
  1529. loadShow();
  1530. autocomplete();
  1531. change();
  1532. },
  1533. add : function(e)
  1534. {
  1535. var self = this;
  1536. var p = e.parent();
  1537. var id = 'data-' + this.addIndex;
  1538. var name = '新增数据-' + (this.addIndex-1);
  1539. p.before('<li><a href="#'+id+'" data-toggle="tab">'+name+'</a></li>');
  1540. var content = $("#myTabContent").find('.tab-pane').eq(0).html();
  1541. content = content.replaceAll('update_', 'update_' + this.addIndex + '__');
  1542. content = '<div class="tab-pane fade" id="'+id+'">' + content + '</div>';
  1543. $("#myTabContent").append(content);
  1544. $('#update_' + this.addIndex + '__where_id').val('-1');
  1545. this.addIndex++;
  1546. }
  1547. }
  1548. String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
  1549. if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
  1550. return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
  1551. } else {
  1552. return this.replace(reallyDo, replaceWith);
  1553. }
  1554. }
  1555. Array.prototype.remove = function(val) {
  1556. var index = -1;
  1557. for(var i = 0; i < this.length; i++)
  1558. {
  1559. if(this[i] == val)
  1560. {
  1561. index = i;
  1562. }
  1563. }
  1564. if (index > -1) {
  1565. this.splice(index, 1);
  1566. }
  1567. };
  1568. $.fn.pasteEvents = function( delay ) {
  1569. if (delay == undefined) delay = 20;
  1570. return $(this).each(function() {
  1571. var $el = $(this);
  1572. $el.on("paste", function() {
  1573. $el.trigger("prepaste");
  1574. setTimeout(function() { $el.trigger("postpaste"); }, delay);
  1575. });
  1576. });
  1577. };
  1578. $("textarea").on("postpaste", function()
  1579. {
  1580. if($(this).val().indexOf('<') != -1)
  1581. {
  1582. $(this).val(toMarkdown($(this).val()));
  1583. }
  1584. }).pasteEvents();