scrawl.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. /**
  2. * Created with JetBrains PhpStorm.
  3. * User: xuheng
  4. * Date: 12-5-22
  5. * Time: 上午11:38
  6. * To change this template use File | Settings | File Templates.
  7. */
  8. var scrawl = function (options) {
  9. options && this.initOptions(options);
  10. };
  11. (function () {
  12. var canvas = $G("J_brushBoard"),
  13. context = canvas.getContext('2d'),
  14. drawStep = [], //undo redo存储
  15. drawStepIndex = 0; //undo redo指针
  16. scrawl.prototype = {
  17. isScrawl:false, //是否涂鸦
  18. brushWidth:-1, //画笔粗细
  19. brushColor:"", //画笔颜色
  20. initOptions:function (options) {
  21. var me = this;
  22. me.originalState(options);//初始页面状态
  23. me._buildToolbarColor(options.colorList);//动态生成颜色选择集合
  24. me._addBoardListener(options.saveNum);//添加画板处理
  25. me._addOPerateListener(options.saveNum);//添加undo redo clearBoard处理
  26. me._addColorBarListener();//添加颜色选择处理
  27. me._addBrushBarListener();//添加画笔大小处理
  28. me._addEraserBarListener();//添加橡皮大小处理
  29. me._addAddImgListener();//添加增添背景图片处理
  30. me._addRemoveImgListenter();//删除背景图片处理
  31. me._addScalePicListenter();//添加缩放处理
  32. me._addClearSelectionListenter();//添加清楚选中状态处理
  33. me._originalColorSelect(options.drawBrushColor);//初始化颜色选中
  34. me._originalBrushSelect(options.drawBrushSize);//初始化画笔选中
  35. me._clearSelection();//清楚选中状态
  36. },
  37. originalState:function (options) {
  38. var me = this,
  39. url = editor.options.scrawlUrl;
  40. me.brushWidth = options.drawBrushSize;//同步画笔粗细
  41. me.brushColor = options.drawBrushColor;//同步画笔颜色
  42. $G("fileForm").action = url + (url.indexOf("?") == -1 ? "?" : "&") + "action=tmpImg";//初始form提交地址
  43. context.lineWidth = me.brushWidth;//初始画笔大小
  44. context.strokeStyle = me.brushColor;//初始画笔颜色
  45. context.fillStyle = "transparent";//初始画布背景颜色
  46. context.lineCap = "round";//去除锯齿
  47. context.fill();
  48. },
  49. _buildToolbarColor:function (colorList) {
  50. var tmp = null, arr = [];
  51. arr.push("<table id='J_colorList'>");
  52. for (var i = 0, color; color = colorList[i++];) {
  53. if ((i - 1) % 5 == 0) {
  54. if (i != 1) {
  55. arr.push("</tr>");
  56. }
  57. arr.push("<tr>");
  58. }
  59. tmp = '#' + color;
  60. arr.push("<td><a title='" + tmp + "' href='javascript:void(0)' style='background-color:" + tmp + "'></a></td>");
  61. }
  62. arr.push("</tr></table>");
  63. $G("J_colorBar").innerHTML = arr.join("");
  64. },
  65. _addBoardListener:function (saveNum) {
  66. var me = this,
  67. margin = 0,
  68. startX = -1,
  69. startY = -1,
  70. isMouseDown = false,
  71. isMouseMove = false,
  72. isMouseUp = false,
  73. buttonPress = 0, button, flag = '';
  74. margin = parseInt(domUtils.getComputedStyle($G("J_wrap"), "margin-left"));
  75. drawStep.push(context.getImageData(0, 0, context.canvas.width, context.canvas.height));
  76. drawStepIndex += 1;
  77. domUtils.on(canvas, ["mousedown", "mousemove", "mouseup", "mouseout"], function (e) {
  78. button = browser.webkit ? e.which : buttonPress;
  79. switch (e.type) {
  80. case 'mousedown':
  81. buttonPress = 1;
  82. flag = 1;
  83. isMouseDown = true;
  84. isMouseUp = false;
  85. isMouseMove = false;
  86. me.isScrawl = true;
  87. startX = e.clientX - margin;//10为外边距总和
  88. startY = e.clientY - margin;
  89. context.beginPath();
  90. break;
  91. case 'mousemove' :
  92. if (!flag && button == 0) {
  93. return;
  94. }
  95. if (!flag && button) {
  96. startX = e.clientX - margin;//10为外边距总和
  97. startY = e.clientY - margin;
  98. context.beginPath();
  99. flag = 1;
  100. }
  101. if (isMouseUp || !isMouseDown) {
  102. return;
  103. }
  104. var endX = e.clientX - margin,
  105. endY = e.clientY - margin;
  106. context.moveTo(startX, startY);
  107. context.lineTo(endX, endY);
  108. context.stroke();
  109. startX = endX;
  110. startY = endY;
  111. isMouseMove = true;
  112. break;
  113. case 'mouseup':
  114. buttonPress = 0;
  115. if (!isMouseDown)return;
  116. if (!isMouseMove) {
  117. context.arc(startX, startY, context.lineWidth, 0, Math.PI * 2, false);
  118. context.fillStyle = context.strokeStyle;
  119. context.fill();
  120. }
  121. context.closePath();
  122. me._saveOPerate(saveNum);
  123. isMouseDown = false;
  124. isMouseMove = false;
  125. isMouseUp = true;
  126. startX = -1;
  127. startY = -1;
  128. break;
  129. case 'mouseout':
  130. flag = '';
  131. buttonPress = 0;
  132. if (button == 1) return;
  133. context.closePath();
  134. break;
  135. }
  136. });
  137. },
  138. _addOPerateListener:function (saveNum) {
  139. var me = this;
  140. domUtils.on($G("J_previousStep"), "click", function () {
  141. if (drawStepIndex > 1) {
  142. drawStepIndex -= 1;
  143. context.clearRect(0, 0, context.canvas.width, context.canvas.height);
  144. context.putImageData(drawStep[drawStepIndex - 1], 0, 0);
  145. me.btn2Highlight("J_nextStep");
  146. drawStepIndex == 1 && me.btn2disable("J_previousStep");
  147. }
  148. });
  149. domUtils.on($G("J_nextStep"), "click", function () {
  150. if (drawStepIndex > 0 && drawStepIndex < drawStep.length) {
  151. context.clearRect(0, 0, context.canvas.width, context.canvas.height);
  152. context.putImageData(drawStep[drawStepIndex], 0, 0);
  153. drawStepIndex += 1;
  154. me.btn2Highlight("J_previousStep");
  155. drawStepIndex == drawStep.length && me.btn2disable("J_nextStep");
  156. }
  157. });
  158. domUtils.on($G("J_clearBoard"), "click", function () {
  159. context.clearRect(0, 0, context.canvas.width, context.canvas.height);
  160. drawStep = [];
  161. me._saveOPerate(saveNum);
  162. drawStepIndex = 1;
  163. me.isScrawl = false;
  164. me.btn2disable("J_previousStep");
  165. me.btn2disable("J_nextStep");
  166. me.btn2disable("J_clearBoard");
  167. });
  168. },
  169. _addColorBarListener:function () {
  170. var me = this;
  171. domUtils.on($G("J_colorBar"), "click", function (e) {
  172. var target = me.getTarget(e),
  173. color = target.title;
  174. if (!!color) {
  175. me._addColorSelect(target);
  176. me.brushColor = color;
  177. context.globalCompositeOperation = "source-over";
  178. context.lineWidth = me.brushWidth;
  179. context.strokeStyle = color;
  180. }
  181. });
  182. },
  183. _addBrushBarListener:function () {
  184. var me = this;
  185. domUtils.on($G("J_brushBar"), "click", function (e) {
  186. var target = me.getTarget(e),
  187. size = browser.ie ? target.innerText : target.text;
  188. if (!!size) {
  189. me._addBESelect(target);
  190. context.globalCompositeOperation = "source-over";
  191. context.lineWidth = parseInt(size);
  192. context.strokeStyle = me.brushColor;
  193. me.brushWidth = context.lineWidth;
  194. }
  195. });
  196. },
  197. _addEraserBarListener:function () {
  198. var me = this;
  199. domUtils.on($G("J_eraserBar"), "click", function (e) {
  200. var target = me.getTarget(e),
  201. size = browser.ie ? target.innerText : target.text;
  202. if (!!size) {
  203. me._addBESelect(target);
  204. context.lineWidth = parseInt(size);
  205. context.globalCompositeOperation = "destination-out";
  206. context.strokeStyle = "#FFF";
  207. }
  208. });
  209. },
  210. _addAddImgListener:function () {
  211. var doc = document,
  212. file = $G("J_imgTxt");
  213. domUtils.on(file, "change", function () {
  214. var frm = file.parentNode;
  215. addMaskLayer(lang.backgroundUploading);
  216. frm.submit();
  217. frm.reset();
  218. });
  219. },
  220. _addRemoveImgListenter:function () {
  221. var me = this;
  222. domUtils.on($G("J_removeImg"), "click", function () {
  223. $G("J_picBoard").innerHTML = "";
  224. me.btn2disable("J_removeImg");
  225. me.btn2disable("J_sacleBoard");
  226. });
  227. },
  228. _addScalePicListenter:function () {
  229. domUtils.on($G("J_sacleBoard"), "click", function () {
  230. var picBoard = $G("J_picBoard"),
  231. scaleCon = $G("J_scaleCon"),
  232. img = picBoard.children[0];
  233. if (img) {
  234. if (!scaleCon) {
  235. picBoard.style.cssText = "position:relative;z-index:999;"+picBoard.style.cssText;
  236. img.style.cssText = "position: absolute;top:" + (canvas.height - img.height) / 2 + "px;left:" + (canvas.width - img.width) / 2 + "px;";
  237. var scale = new ScaleBoy();
  238. picBoard.appendChild(scale.init());
  239. scale.startScale(img);
  240. } else {
  241. if (scaleCon.style.visibility == "visible") {
  242. scaleCon.style.visibility = "hidden";
  243. picBoard.style.position = "";
  244. picBoard.style.zIndex = "";
  245. } else {
  246. scaleCon.style.visibility = "visible";
  247. picBoard.style.cssText += "position:relative;z-index:999";
  248. }
  249. }
  250. }
  251. });
  252. },
  253. _addClearSelectionListenter:function () {
  254. var doc = document;
  255. domUtils.on(doc, 'mousemove', function (e) {
  256. if (browser.ie)
  257. doc.selection.clear();
  258. else
  259. window.getSelection().removeAllRanges();
  260. });
  261. },
  262. _clearSelection:function () {
  263. var list = ["J_operateBar", "J_colorBar", "J_brushBar", "J_eraserBar", "J_picBoard"];
  264. for (var i = 0, group; group = list[i++];) {
  265. domUtils.unSelectable($G(group));
  266. }
  267. },
  268. _saveOPerate:function (saveNum) {
  269. var me = this;
  270. if (drawStep.length <= saveNum) {
  271. if(drawStepIndex<drawStep.length){
  272. me.btn2disable("J_nextStep");
  273. drawStep.splice(drawStepIndex);
  274. }
  275. drawStep.push(context.getImageData(0, 0, context.canvas.width, context.canvas.height));
  276. drawStepIndex = drawStep.length;
  277. } else {
  278. drawStep.shift();
  279. drawStep.push(context.getImageData(0, 0, context.canvas.width, context.canvas.height));
  280. drawStepIndex = drawStep.length;
  281. }
  282. me.btn2Highlight("J_previousStep");
  283. me.btn2Highlight("J_clearBoard");
  284. },
  285. _originalColorSelect:function (title) {
  286. var colorList = $G("J_colorList").getElementsByTagName("td");
  287. for (var j = 0, cell; cell = colorList[j++];) {
  288. if (cell.children[0].title.toLowerCase() == title) {
  289. cell.children[0].style.opacity = 1;
  290. }
  291. }
  292. },
  293. _originalBrushSelect:function (text) {
  294. var brushList = $G("J_brushBar").children;
  295. for (var i = 0, ele; ele = brushList[i++];) {
  296. if (ele.tagName.toLowerCase() == "a") {
  297. var size = browser.ie ? ele.innerText : ele.text;
  298. if (size.toLowerCase() == text) {
  299. ele.style.opacity = 1;
  300. }
  301. }
  302. }
  303. },
  304. _addColorSelect:function (target) {
  305. var me = this,
  306. colorList = $G("J_colorList").getElementsByTagName("td"),
  307. eraserList = $G("J_eraserBar").children,
  308. brushList = $G("J_brushBar").children;
  309. for (var i = 0, cell; cell = colorList[i++];) {
  310. cell.children[0].style.opacity = 0.3;
  311. }
  312. for (var k = 0, ele; ele = brushList[k++];) {
  313. if (ele.tagName.toLowerCase() == "a") {
  314. ele.style.opacity = 0.3;
  315. var size = browser.ie ? ele.innerText : ele.text;
  316. if (size.toLowerCase() == this.brushWidth) {
  317. ele.style.opacity = 1;
  318. }
  319. }
  320. }
  321. for (var j = 0, node; node = eraserList[j++];) {
  322. if (node.tagName.toLowerCase() == "a") {
  323. node.style.opacity = 0.3;
  324. }
  325. }
  326. target.style.opacity = 1;
  327. target.blur();
  328. },
  329. _addBESelect:function (target) {
  330. var brushList = $G("J_brushBar").children;
  331. var eraserList = $G("J_eraserBar").children;
  332. for (var i = 0, ele; ele = brushList[i++];) {
  333. if (ele.tagName.toLowerCase() == "a") {
  334. ele.style.opacity = 0.3;
  335. }
  336. }
  337. for (var j = 0, node; node = eraserList[j++];) {
  338. if (node.tagName.toLowerCase() == "a") {
  339. node.style.opacity = 0.3;
  340. }
  341. }
  342. target.style.opacity = 1;
  343. target.blur();
  344. },
  345. getCanvasData:function () {
  346. var picContainer = $G("J_picBoard"),
  347. img = picContainer.children[0];
  348. if (img) {
  349. var x, y;
  350. if (img.style.position == "absolute") {
  351. x = parseInt(img.style.left);
  352. y = parseInt(img.style.top);
  353. } else {
  354. x = (picContainer.offsetWidth - img.width) / 2;
  355. y = (picContainer.offsetHeight - img.height) / 2;
  356. }
  357. context.globalCompositeOperation = "destination-over";
  358. context.drawImage(img, x, y, img.width, img.height);
  359. } else {
  360. context.globalCompositeOperation = "destination-atop";
  361. context.fillStyle = "#fff";//重置画布背景白色
  362. context.fillRect(0, 0, canvas.width, canvas.height);
  363. }
  364. try {
  365. return canvas.toDataURL("image/png").substring(22);
  366. } catch (e) {
  367. return "";
  368. }
  369. },
  370. btn2Highlight:function (id) {
  371. var cur = $G(id);
  372. cur.className.indexOf("H") == -1 && (cur.className += "H");
  373. },
  374. btn2disable:function (id) {
  375. var cur = $G(id);
  376. cur.className.indexOf("H") != -1 && (cur.className = cur.className.replace("H", ""));
  377. },
  378. getTarget:function (evt) {
  379. return evt.target || evt.srcElement;
  380. }
  381. };
  382. })();
  383. var ScaleBoy = function () {
  384. this.dom = null;
  385. this.scalingElement = null;
  386. };
  387. (function () {
  388. function _appendStyle() {
  389. var doc = document,
  390. head = doc.getElementsByTagName('head')[0],
  391. style = doc.createElement('style'),
  392. cssText = '.scale{visibility:hidden;cursor:move;position:absolute;left:0;top:0;width:100px;height:50px;background-color:#fff;font-size:0;line-height:0;opacity:.4;filter:Alpha(opacity=40);}'
  393. + '.scale span{position:absolute;left:0;top:0;width:6px;height:6px;background-color:#006DAE;}'
  394. + '.scale .hand0, .scale .hand7{cursor:nw-resize;}'
  395. + '.scale .hand1, .scale .hand6{left:50%;margin-left:-3px;cursor:n-resize;}'
  396. + '.scale .hand2, .scale .hand4, .scale .hand7{left:100%;margin-left:-6px;}'
  397. + '.scale .hand3, .scale .hand4{top:50%;margin-top:-3px;cursor:w-resize;}'
  398. + '.scale .hand5, .scale .hand6, .scale .hand7{margin-top:-6px;top:100%;}'
  399. + '.scale .hand2, .scale .hand5{cursor:ne-resize;}';
  400. style.type = 'text/css';
  401. try {
  402. style.appendChild(doc.createTextNode(cssText));
  403. } catch (e) {
  404. style.styleSheet.cssText = cssText;
  405. }
  406. head.appendChild(style);
  407. }
  408. function _getDom() {
  409. var doc = document,
  410. hand,
  411. arr = [],
  412. scale = doc.createElement('div');
  413. scale.id = 'J_scaleCon';
  414. scale.className = 'scale';
  415. for (var i = 0; i < 8; i++) {
  416. arr.push("<span class='hand" + i + "'></span>");
  417. }
  418. scale.innerHTML = arr.join("");
  419. return scale;
  420. }
  421. var rect = [
  422. //[left, top, width, height]
  423. [1, 1, -1, -1],
  424. [0, 1, 0, -1],
  425. [0, 1, 1, -1],
  426. [1, 0, -1, 0],
  427. [0, 0, 1, 0],
  428. [1, 0, -1, 1],
  429. [0, 0, 0, 1],
  430. [0, 0, 1, 1]
  431. ];
  432. ScaleBoy.prototype = {
  433. init:function () {
  434. _appendStyle();
  435. var me = this,
  436. scale = me.dom = _getDom();
  437. me.scaleMousemove.fp = me;
  438. domUtils.on(scale, 'mousedown', function (e) {
  439. var target = e.target || e.srcElement;
  440. me.start = {x:e.clientX, y:e.clientY};
  441. if (target.className.indexOf('hand') != -1) {
  442. me.dir = target.className.replace('hand', '');
  443. }
  444. domUtils.on(document.body, 'mousemove', me.scaleMousemove);
  445. e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
  446. });
  447. domUtils.on(document.body, 'mouseup', function (e) {
  448. if (me.start) {
  449. domUtils.un(document.body, 'mousemove', me.scaleMousemove);
  450. if (me.moved) {
  451. me.updateScaledElement({position:{x:scale.style.left, y:scale.style.top}, size:{w:scale.style.width, h:scale.style.height}});
  452. }
  453. delete me.start;
  454. delete me.moved;
  455. delete me.dir;
  456. }
  457. });
  458. return scale;
  459. },
  460. startScale:function (objElement) {
  461. var me = this, Idom = me.dom;
  462. Idom.style.cssText = 'visibility:visible;top:' + objElement.style.top + ';left:' + objElement.style.left + ';width:' + objElement.offsetWidth + 'px;height:' + objElement.offsetHeight + 'px;';
  463. me.scalingElement = objElement;
  464. },
  465. updateScaledElement:function (objStyle) {
  466. var cur = this.scalingElement,
  467. pos = objStyle.position,
  468. size = objStyle.size;
  469. if (pos) {
  470. typeof pos.x != 'undefined' && (cur.style.left = pos.x);
  471. typeof pos.y != 'undefined' && (cur.style.top = pos.y);
  472. }
  473. if (size) {
  474. size.w && (cur.style.width = size.w);
  475. size.h && (cur.style.height = size.h);
  476. }
  477. },
  478. updateStyleByDir:function (dir, offset) {
  479. var me = this,
  480. dom = me.dom, tmp;
  481. rect['def'] = [1, 1, 0, 0];
  482. if (rect[dir][0] != 0) {
  483. tmp = parseInt(dom.style.left) + offset.x;
  484. dom.style.left = me._validScaledProp('left', tmp) + 'px';
  485. }
  486. if (rect[dir][1] != 0) {
  487. tmp = parseInt(dom.style.top) + offset.y;
  488. dom.style.top = me._validScaledProp('top', tmp) + 'px';
  489. }
  490. if (rect[dir][2] != 0) {
  491. tmp = dom.clientWidth + rect[dir][2] * offset.x;
  492. dom.style.width = me._validScaledProp('width', tmp) + 'px';
  493. }
  494. if (rect[dir][3] != 0) {
  495. tmp = dom.clientHeight + rect[dir][3] * offset.y;
  496. dom.style.height = me._validScaledProp('height', tmp) + 'px';
  497. }
  498. if (dir === 'def') {
  499. me.updateScaledElement({position:{x:dom.style.left, y:dom.style.top}});
  500. }
  501. },
  502. scaleMousemove:function (e) {
  503. var me = arguments.callee.fp,
  504. start = me.start,
  505. dir = me.dir || 'def',
  506. offset = {x:e.clientX - start.x, y:e.clientY - start.y};
  507. me.updateStyleByDir(dir, offset);
  508. arguments.callee.fp.start = {x:e.clientX, y:e.clientY};
  509. arguments.callee.fp.moved = 1;
  510. },
  511. _validScaledProp:function (prop, value) {
  512. var ele = this.dom,
  513. wrap = $G("J_picBoard");
  514. value = isNaN(value) ? 0 : value;
  515. switch (prop) {
  516. case 'left':
  517. return value < 0 ? 0 : (value + ele.clientWidth) > wrap.clientWidth ? wrap.clientWidth - ele.clientWidth : value;
  518. case 'top':
  519. return value < 0 ? 0 : (value + ele.clientHeight) > wrap.clientHeight ? wrap.clientHeight - ele.clientHeight : value;
  520. case 'width':
  521. return value <= 0 ? 1 : (value + ele.offsetLeft) > wrap.clientWidth ? wrap.clientWidth - ele.offsetLeft : value;
  522. case 'height':
  523. return value <= 0 ? 1 : (value + ele.offsetTop) > wrap.clientHeight ? wrap.clientHeight - ele.offsetTop : value;
  524. }
  525. }
  526. };
  527. })();
  528. //后台回调
  529. function ue_callback(url, state) {
  530. var doc = document,
  531. picBorard = $G("J_picBoard"),
  532. img = doc.createElement("img");
  533. //图片缩放
  534. function scale(img, max, oWidth, oHeight) {
  535. var width = 0, height = 0, percent, ow = img.width || oWidth, oh = img.height || oHeight;
  536. if (ow > max || oh > max) {
  537. if (ow >= oh) {
  538. if (width = ow - max) {
  539. percent = (width / ow).toFixed(2);
  540. img.height = oh - oh * percent;
  541. img.width = max;
  542. }
  543. } else {
  544. if (height = oh - max) {
  545. percent = (height / oh).toFixed(2);
  546. img.width = ow - ow * percent;
  547. img.height = max;
  548. }
  549. }
  550. }
  551. }
  552. //移除遮罩层
  553. removeMaskLayer();
  554. //状态响应
  555. if (state == "SUCCESS") {
  556. picBorard.innerHTML = "";
  557. img.onload = function () {
  558. scale(this, 300);
  559. picBorard.appendChild(img);
  560. var obj = new scrawl();
  561. obj.btn2Highlight("J_removeImg");
  562. //trace 2457
  563. obj.btn2Highlight("J_sacleBoard");
  564. };
  565. img.src = editor.options.scrawlPath + url;
  566. } else {
  567. alert(state);
  568. }
  569. }
  570. //去掉遮罩层
  571. function removeMaskLayer() {
  572. var maskLayer = $G("J_maskLayer");
  573. maskLayer.className = "maskLayerNull";
  574. maskLayer.innerHTML = "";
  575. dialog.buttons[0].setDisabled(false);
  576. }
  577. //添加遮罩层
  578. function addMaskLayer(html) {
  579. var maskLayer = $G("J_maskLayer");
  580. dialog.buttons[0].setDisabled(true);
  581. maskLayer.className = "maskLayer";
  582. maskLayer.innerHTML = html;
  583. }
  584. //执行确认按钮方法
  585. function exec(scrawlObj) {
  586. if (scrawlObj.isScrawl) {
  587. addMaskLayer(lang.scrawlUpLoading);
  588. var base64 = scrawlObj.getCanvasData();
  589. if (!!base64) {
  590. ajax.request(editor.options.scrawlUrl, {
  591. timeout:100000,
  592. content:base64,
  593. onsuccess:function (xhr) {
  594. if (!scrawlObj.isCancelScrawl) {
  595. var responseObj;
  596. responseObj = eval("(" + xhr.responseText + ")");
  597. if (responseObj.state == "SUCCESS") {
  598. var imgObj = {},
  599. url = editor.options.scrawlPath + responseObj.url;
  600. imgObj.src = url;
  601. imgObj._src = url;
  602. editor.execCommand("insertImage", imgObj);
  603. dialog.close();
  604. } else {
  605. alert(responseObj.state);
  606. }
  607. }
  608. },
  609. onerror:function () {
  610. alert(lang.imageError);
  611. dialog.close();
  612. }
  613. });
  614. }
  615. } else {
  616. addMaskLayer(lang.noScarwl + "&nbsp;&nbsp;&nbsp;<input type='button' value='" + lang.continueBtn + "' onclick='removeMaskLayer()'/>");
  617. }
  618. }