scrawl.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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 = -1; //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. me.brushWidth = options.drawBrushSize;//同步画笔粗细
  40. me.brushColor = options.drawBrushColor;//同步画笔颜色
  41. $G("fileForm").action = editor.options.scrawlUrl + "?action=tmpImg";//初始form提交地址
  42. //$G("fileForm").action = url + (url.indexOf("?") == -1 ? "?" : "&") + "action=tmpImg";
  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 = 0;
  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. //trace 2457
  230. if(browser.opera) return;
  231. domUtils.on($G("J_sacleBoard"), "click", function () {
  232. var picBoard = $G("J_picBoard"),
  233. scaleCon = $G("J_scaleCon"),
  234. img = picBoard.children[0];
  235. if (img) {
  236. if (!scaleCon) {
  237. img.style.cssText = "position: absolute;top:" + (canvas.height - img.height) / 2 + "px;left:" + (canvas.width - img.width) / 2 + "px;";
  238. picBoard.style.cssText += "position:relative;z-index:999";
  239. var scale = new ScaleBoy();
  240. picBoard.appendChild(scale.init());
  241. scale.startScale(img);
  242. } else {
  243. if (scaleCon.style.visibility == "visible") {
  244. scaleCon.style.visibility = "hidden";
  245. picBoard.style.position = "";
  246. picBoard.style.zIndex = "";
  247. } else {
  248. scaleCon.style.visibility = "visible";
  249. picBoard.style.cssText += "position:relative;z-index:999";
  250. }
  251. }
  252. }
  253. });
  254. },
  255. _addClearSelectionListenter:function(){
  256. var doc=document;
  257. domUtils.on(doc,'mousemove',function(e){
  258. if(browser.ie)
  259. doc.selection.clear();
  260. else
  261. window.getSelection().removeAllRanges();
  262. });
  263. },
  264. _clearSelection:function () {
  265. var list = ["J_operateBar", "J_colorBar", "J_brushBar", "J_eraserBar", "J_picBoard"];
  266. for (var i = 0, group; group = list[i++];) {
  267. domUtils.unselectable($G(group));
  268. }
  269. },
  270. _saveOPerate:function (saveNum) {
  271. var me = this;
  272. if (drawStep.length <= saveNum) {
  273. drawStep.push(context.getImageData(0, 0, context.canvas.width, context.canvas.height));
  274. drawStepIndex = drawStep.length;
  275. } else {
  276. drawStep.shift();
  277. drawStep.push(context.getImageData(0, 0, context.canvas.width, context.canvas.height));
  278. drawStepIndex = drawStep.length;
  279. }
  280. me.btn2Highlight("J_previousStep");
  281. me.btn2Highlight("J_clearBoard");
  282. },
  283. _originalColorSelect:function (title) {
  284. var colorList = $G("J_colorList").getElementsByTagName("td");
  285. for (var j = 0, cell; cell = colorList[j++];) {
  286. if (cell.children[0].title.toLowerCase() == title) {
  287. cell.children[0].style.opacity = 1;
  288. }
  289. }
  290. },
  291. _originalBrushSelect:function (text) {
  292. var brushList = $G("J_brushBar").children;
  293. for (var i = 0, ele; ele = brushList[i++];) {
  294. if (ele.tagName.toLowerCase() == "a") {
  295. var size = browser.ie ? ele.innerText : ele.text;
  296. if (size.toLowerCase() == text) {
  297. ele.style.opacity = 1;
  298. }
  299. }
  300. }
  301. },
  302. _addColorSelect:function (target) {
  303. var me = this,
  304. colorList = $G("J_colorList").getElementsByTagName("td"),
  305. eraserList = $G("J_eraserBar").children,
  306. brushList = $G("J_brushBar").children;
  307. for (var i = 0, cell; cell = colorList[i++];) {
  308. cell.children[0].style.opacity = 0.3;
  309. }
  310. for (var k = 0, ele; ele = brushList[k++];) {
  311. if (ele.tagName.toLowerCase() == "a") {
  312. ele.style.opacity = 0.3;
  313. var size = browser.ie ? ele.innerText : ele.text;
  314. if (size.toLowerCase() == this.brushWidth) {
  315. ele.style.opacity = 1;
  316. }
  317. }
  318. }
  319. for (var j = 0, node; node = eraserList[j++];) {
  320. if (node.tagName.toLowerCase() == "a") {
  321. node.style.opacity = 0.3;
  322. }
  323. }
  324. target.style.opacity = 1;
  325. target.blur();
  326. },
  327. _addBESelect:function (target) {
  328. var brushList = $G("J_brushBar").children;
  329. var eraserList = $G("J_eraserBar").children;
  330. for (var i = 0, ele; ele = brushList[i++];) {
  331. if (ele.tagName.toLowerCase() == "a") {
  332. ele.style.opacity = 0.3;
  333. }
  334. }
  335. for (var j = 0, node; node = eraserList[j++];) {
  336. if (node.tagName.toLowerCase() == "a") {
  337. node.style.opacity = 0.3;
  338. }
  339. }
  340. target.style.opacity = 1;
  341. target.blur();
  342. },
  343. getCanvasData:function () {
  344. var picContainer = $G("J_picBoard"),
  345. img = picContainer.children[0];
  346. if (img) {
  347. var x, y;
  348. if (img.style.position == "absolute") {
  349. x = parseInt(img.style.left);
  350. y = parseInt(img.style.top);
  351. } else {
  352. x = (picContainer.offsetWidth - img.width) / 2;
  353. y = (picContainer.offsetHeight - img.height) / 2;
  354. }
  355. context.globalCompositeOperation = "destination-over";
  356. context.drawImage(img, x, y, img.width, img.height);
  357. } else {
  358. context.globalCompositeOperation = "destination-atop";
  359. context.fillStyle = "#fff";//重置画布背景白色
  360. context.fillRect(0, 0, canvas.width, canvas.height);
  361. }
  362. try{
  363. return canvas.toDataURL("image/png").substring(22);
  364. }catch(e){
  365. return "";
  366. }
  367. },
  368. btn2Highlight:function (id) {
  369. var cur = $G(id);
  370. cur.className.indexOf("H") == -1 && (cur.className += "H");
  371. },
  372. btn2disable:function (id) {
  373. var cur = $G(id);
  374. cur.className.indexOf("H") != -1 && (cur.className = cur.className.replace("H", ""));
  375. },
  376. getTarget:function (evt) {
  377. return evt.target || evt.srcElement;
  378. }
  379. };
  380. })();
  381. var ScaleBoy = function () {
  382. this.dom = null;
  383. this.scalingElement = null;
  384. };
  385. (function () {
  386. function _appendStyle() {
  387. var doc = document,
  388. head = doc.getElementsByTagName('head')[0],
  389. style = doc.createElement('style'),
  390. 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;overflow:hidden;opacity:.4;filter:Alpha(opacity=40);}'
  391. + '.scale span{position:absolute;left:0;top:0;width:6px;height:6px;background-color:#006DAE;}'
  392. + '.scale .hand0, .scale .hand7{cursor:nw-resize;}'
  393. + '.scale .hand1, .scale .hand6{left:50%;margin-left:-3px;cursor:n-resize;}'
  394. + '.scale .hand2, .scale .hand4, .scale .hand7{left:100%;margin-left:-6px;}'
  395. + '.scale .hand3, .scale .hand4{top:50%;margin-top:-3px;cursor:w-resize;}'
  396. + '.scale .hand5, .scale .hand6, .scale .hand7{margin-top:-6px;top:100%;}'
  397. + '.scale .hand2, .scale .hand5{cursor:ne-resize;}';
  398. style.type = 'text/css';
  399. try {
  400. style.appendChild(doc.createTextNode(cssText));
  401. } catch (e) {
  402. style.styleSheet.cssText = cssText;
  403. }
  404. head.appendChild(style);
  405. }
  406. function _getDom() {
  407. var doc = document,
  408. hand,
  409. arr = [],
  410. scale = doc.createElement('div');
  411. scale.id = 'J_scaleCon';
  412. scale.className = 'scale';
  413. for (var i = 0; i < 8; i++) {
  414. arr.push("<span class='hand" + i + "'></span>");
  415. }
  416. scale.innerHTML = arr.join("");
  417. return scale;
  418. }
  419. var rect = [
  420. //[left, top, width, height]
  421. [1, 1, -1, -1],
  422. [0, 1, 0, -1],
  423. [0, 1, 1, -1],
  424. [1, 0, -1, 0],
  425. [0, 0, 1, 0],
  426. [1, 0, -1, 1],
  427. [0, 0, 0, 1],
  428. [0, 0, 1, 1]
  429. ];
  430. ScaleBoy.prototype = {
  431. init:function () {
  432. _appendStyle();
  433. var me = this,
  434. scale = me.dom = _getDom();
  435. me.scaleMousemove.fp = me;
  436. domUtils.on(scale, 'mousedown', function (e) {
  437. var target = e.target || e.srcElement;
  438. me.start = {x:e.clientX, y:e.clientY};
  439. if (target.className.indexOf('hand') != -1) {
  440. me.dir = target.className.replace('hand', '');
  441. }
  442. domUtils.on(document.body, 'mousemove', me.scaleMousemove);
  443. e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
  444. });
  445. domUtils.on(document.body, 'mouseup', function (e) {
  446. if (me.start) {
  447. domUtils.un(document.body, 'mousemove', me.scaleMousemove);
  448. if (me.moved) {
  449. me.updateScaledElement({position:{x:scale.style.left, y:scale.style.top}, size:{w:scale.style.width, h:scale.style.height}});
  450. }
  451. delete me.start;
  452. delete me.moved;
  453. delete me.dir;
  454. }
  455. });
  456. return scale;
  457. },
  458. startScale:function (objElement) {
  459. var me = this, Idom = me.dom;
  460. Idom.style.cssText = 'visibility:visible;top:' + objElement.style.top + ';left:' + objElement.style.left + ';width:' + objElement.offsetWidth + 'px;height:' + objElement.offsetHeight + 'px;';
  461. me.scalingElement = objElement;
  462. },
  463. updateScaledElement:function (objStyle) {
  464. var cur = this.scalingElement,
  465. pos = objStyle.position,
  466. size = objStyle.size;
  467. if (pos) {
  468. typeof pos.x != 'undefined' && (cur.style.left = pos.x);
  469. typeof pos.y != 'undefined' && (cur.style.top = pos.y);
  470. }
  471. if (size) {
  472. size.w && (cur.style.width = size.w);
  473. size.h && (cur.style.height = size.h);
  474. }
  475. },
  476. updateStyleByDir:function (dir, offset) {
  477. var me = this,
  478. dom = me.dom, tmp;
  479. rect['def'] = [1, 1, 0, 0];
  480. if (rect[dir][0] != 0) {
  481. tmp = parseInt(dom.style.left) + offset.x;
  482. dom.style.left = me._validScaledProp('left', tmp) + 'px';
  483. }
  484. if (rect[dir][1] != 0) {
  485. tmp = parseInt(dom.style.top) + offset.y;
  486. dom.style.top = me._validScaledProp('top', tmp) + 'px';
  487. }
  488. if (rect[dir][2] != 0) {
  489. tmp = dom.clientWidth + rect[dir][2] * offset.x;
  490. dom.style.width = me._validScaledProp('width', tmp) + 'px';
  491. }
  492. if (rect[dir][3] != 0) {
  493. tmp = dom.clientHeight + rect[dir][3] * offset.y;
  494. dom.style.height = me._validScaledProp('height', tmp) + 'px';
  495. }
  496. if (dir === 'def') {
  497. me.updateScaledElement({position:{x:dom.style.left, y:dom.style.top}});
  498. }
  499. },
  500. scaleMousemove:function (e) {
  501. var me = arguments.callee.fp,
  502. start = me.start,
  503. dir = me.dir || 'def',
  504. offset = {x:e.clientX - start.x, y:e.clientY - start.y};
  505. me.updateStyleByDir(dir, offset);
  506. arguments.callee.fp.start = {x:e.clientX, y:e.clientY};
  507. arguments.callee.fp.moved = 1;
  508. },
  509. _validScaledProp:function (prop, value) {
  510. var ele = this.dom,
  511. wrap = $G("J_picBoard");
  512. value = isNaN(value) ? 0 : value;
  513. switch (prop) {
  514. case 'left':
  515. return value < 0 ? 0 : (value + ele.clientWidth) > wrap.clientWidth ? wrap.clientWidth - ele.clientWidth : value;
  516. case 'top':
  517. return value < 0 ? 0 : (value + ele.clientHeight) > wrap.clientHeight ? wrap.clientHeight - ele.clientHeight : value;
  518. case 'width':
  519. return value <= 0 ? 1 : (value + ele.offsetLeft) > wrap.clientWidth ? wrap.clientWidth - ele.offsetLeft : value;
  520. case 'height':
  521. return value <= 0 ? 1 : (value + ele.offsetTop) > wrap.clientHeight ? wrap.clientHeight - ele.offsetTop : value;
  522. }
  523. }
  524. };
  525. })();
  526. //后台回调
  527. function ue_callback(url, state) {
  528. var doc = document,
  529. picBorard = $G("J_picBoard"),
  530. img = doc.createElement("img");
  531. //图片缩放
  532. function scale(img, max, oWidth, oHeight) {
  533. var width = 0, height = 0, percent, ow = img.width || oWidth, oh = img.height || oHeight;
  534. if (ow > max || oh > max) {
  535. if (ow >= oh) {
  536. if (width = ow - max) {
  537. percent = (width / ow).toFixed(2);
  538. img.height = oh - oh * percent;
  539. img.width = max;
  540. }
  541. } else {
  542. if (height = oh - max) {
  543. percent = (height / oh).toFixed(2);
  544. img.width = ow - ow * percent;
  545. img.height = max;
  546. }
  547. }
  548. }
  549. }
  550. //移除遮罩层
  551. removeMaskLayer();
  552. //状态响应
  553. if (state == "SUCCESS") {
  554. picBorard.innerHTML = "";
  555. img.onload = function () {
  556. scale(this, 300);
  557. picBorard.appendChild(img);
  558. var obj = new scrawl();
  559. obj.btn2Highlight("J_removeImg");
  560. //trace 2457
  561. if(!browser.opera){
  562. obj.btn2Highlight("J_sacleBoard");
  563. }
  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.data_ue_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. }