main.js 33 KB

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