Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

scrawl.js 27KB

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