main.js 33 KB

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