网站
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

235 wiersze
8.9 KiB

  1. var WritingPad = function () {
  2. var current = null;
  3. $(function () {
  4. initHtml();
  5. initTable();
  6. initSignature();
  7. //if ($(".modal")) {
  8. // $(".modal").modal("toggle");
  9. //} else {
  10. // alert("没用手写面板");
  11. //}
  12. $(document).on("click", "#myClose,.close", null, function () {
  13. $('#mymodal').modal('hide');
  14. $("#mymodal").remove();
  15. });
  16. $(document).on("click", "#mySave", null, function () {
  17. var myImg = $('#myImg').empty();
  18. var dataUrl = $('.js-signature').jqSignature('getDataURL');
  19. var img = $('<img>').attr('src', dataUrl);
  20. $(myImg).append($('<p>').text("图片保存在这里"));
  21. $(myImg).append(img);
  22. });
  23. $(document).on("click", "#myEmpty", null, function () {
  24. $('.js-signature').jqSignature('clearCanvas');
  25. });
  26. $(document).on("click", "#myBackColor", null, function () {
  27. $('#colorpanel').css('left', '95px').css('top', '45px').css("display", "block").fadeIn();
  28. //$("canvas").css("background", "#EEEEEE");
  29. $("#btnSave").data("sender", "#myBackColor");
  30. });
  31. $(document).on("click", "#myColor", null, function () {
  32. $('#colorpanel').css('left', '205px').css('top', '45px').css("display", "block").fadeIn();
  33. $("#btnSave").data("sender", "#myColor");
  34. });
  35. $(document).on("mouseover", "#myTable", null, function () {
  36. if ((event.srcElement.tagName == "TD") && (current != event.srcElement)) {
  37. if (current != null) { current.style.backgroundColor = current._background }
  38. event.srcElement._background = event.srcElement.style.backgroundColor;
  39. //$("input[name=DisColor]").css("background-color", event.srcElement.style.backgroundColor);
  40. //var color = event.srcElement.style.backgroundColor;
  41. //var strArr = color.substring(4, color.length - 1).split(',');
  42. //var num = showRGB(strArr);
  43. //$("input[name=HexColor]").val(num);
  44. current = event.srcElement;
  45. }
  46. });
  47. $(document).on("mouseout", "#myTable", null, function () {
  48. if (current != null) current.style.backgroundColor = current._background
  49. });
  50. $(document).on("click", "#myTable", null, function () {
  51. if (event.srcElement.tagName == "TD") {
  52. var color = event.srcElement._background;
  53. if (color) {
  54. $("input[name=DisColor]").css("background-color", color);
  55. var strArr = color.substring(4, color.length - 1).split(',');
  56. var num = showRGB(strArr);
  57. $("input[name=HexColor]").val(num);
  58. }
  59. }
  60. });
  61. $(document).on("click", "#btnSave", null, function () {
  62. $('#colorpanel').css("display", "none");
  63. var typeData = $("#btnSave").data("sender");
  64. var HexColor = $("input[name=HexColor]").val();
  65. var data = $(".js-signature").data();
  66. if (typeData == "#myColor") {
  67. data["plugin_jqSignature"]["settings"]["lineColor"] = HexColor;
  68. $('.js-signature').jqSignature('reLoadData');
  69. }
  70. if (typeData == "#myBackColor") {
  71. data["plugin_jqSignature"]["settings"]["background"] = HexColor;
  72. $('.js-signature').jqSignature('reLoadData');
  73. }
  74. });
  75. $("#mymodal").on('hide.bs.modal', function () {
  76. $("#colorpanel").remove();
  77. $("#mymodal").remove();
  78. $("#myTable").remove();
  79. });
  80. });
  81. function initHtml() {
  82. var html = '<div class="modal" id="mymodal">' +
  83. '<div class="modal-dialog">' +
  84. '<div class="modal-content">' +
  85. '<div class="modal-header">' +
  86. '' +
  87. '<h4 class="modal-title">手写面板</h4>' +
  88. '</div>' +
  89. '<div class="modal-body">' +
  90. '<div class="js-signature" id="mySignature">' +
  91. '</div>' +
  92. '<div>' +
  93. '<button type="button" class="btn btn-default" id="myEmpty">清空面板</button>' +
  94. '<button type="button" class="btn btn-default" id="myBackColor">设置背景颜色</button>' +
  95. //'<div style="position:absolute;relative">' +
  96. '<button type="button" class="btn btn-default" id="myColor">设置字体颜色</button>' +
  97. '<div id="colorpanel" style="position:absolute;z-index:99;display:none"></div>' +
  98. //'</div>'+
  99. '</div>' +
  100. '</div>' +
  101. '<div class="modal-footer">' +
  102. '<button type="button" class="btn btn-default" id="myClose">关闭</button>' +
  103. '<button type="button" class="btn btn-primary" id="mySave" onclick="savaimg();" >保存</button>' +
  104. '<div id="myImg">' +
  105. '<div>' +
  106. '</div>' +
  107. '</div>' +
  108. '</div>' +
  109. '</div>';
  110. $('body').append(html);
  111. }
  112. function initTable() {
  113. var colorTable = "";
  114. var ColorHex = new Array('00', '33', '66', '99', 'CC', 'FF');
  115. var SpColorHex = new Array('FF0000', '00FF00', '0000FF', 'FFFF00', '00FFFF', 'FF00FF');
  116. for (var i = 0; i < 2; i++) {
  117. for (var j = 0; j < 6; j++) {
  118. colorTable = colorTable + '<tr height=12>';
  119. colorTable = colorTable + '<td width=11 style="background-color:#000000"></td>';
  120. if (i == 0) {
  121. colorTable = colorTable + '<td width=11 style="background-color:#' + ColorHex[j] + ColorHex[j] + ColorHex[j] + '"></td>';
  122. }
  123. else {
  124. colorTable = colorTable + '<td width=11 style="background-color:#' + SpColorHex[j] + '"></td>';
  125. }
  126. //colorTable = colorTable + '<td width=11 style="background-color:#000000"></td>';
  127. for (var k = 0; k < 3; k++) {
  128. for (l = 0; l < 6; l++) {
  129. colorTable = colorTable + '<td width=11 style="background-color:#' + ColorHex[k + i * 3] + ColorHex[l] + ColorHex[j] + '"></td>';
  130. }
  131. }
  132. colorTable = colorTable + '</tr>';
  133. }
  134. }
  135. colorTable =
  136. '<table border="1" id="myTable" cellspacing="0" cellpadding="0" style="border-collapse: collapse;cursor:pointer;" bordercolor="000000">'
  137. + colorTable + '</table>' +
  138. '<table width=225 border="0" cellspacing="0" cellpadding="0" style="border:1px #000000 solid;border-collapse: collapse;background-color:#000000">' +
  139. '<tr style="height:30px">' +
  140. '<td colspan=21 bgcolor=#cccccc>' +
  141. '<table cellpadding="0" cellspacing="1" border="0" style="border-collapse: collapse">' +
  142. '<tr>' +
  143. '<td width="3"><input type="text" name="DisColor" size="6" disabled style="border:solid 1px #000000;background-color:#ffff00"></td>' +
  144. '<td width="3"><input type="text" name="HexColor" size="7" style="border:inset 1px;font-family:Arial;" value="#000000"></td>' +
  145. '<td width="3"><button type="button" class="btn btn-primary btn-sm" id="btnSave">确认</button></td>' +
  146. '</tr>' +
  147. '</table>' +
  148. '</td>' +
  149. '</tr>' +
  150. '</table>';
  151. $("#colorpanel").append(colorTable);
  152. }
  153. function initSignature() {
  154. // debugger;
  155. if (window.requestAnimFrame) {
  156. var signature = $("#mySignature");
  157. signature.jqSignature({ width: 500, height: 200, border: '1px solid red', background: '#16A085', lineColor: '#ABCDEF', lineWidth: 2, autoFit: false });
  158. //{ width: 600, height: 200, border: '1px solid red', background: '#16A085', lineColor: '#ABCDEF', lineWidth: 2, autoFit: true }
  159. } else {
  160. alert("请加载jq-signature.js");
  161. return;
  162. }
  163. }
  164. function showRGB(arr) {
  165. hexcode = "#";
  166. for (x = 0; x < 3; x++) {
  167. var n = arr[x];
  168. if (n == "") n = "0";
  169. if (parseInt(n) != n)
  170. return alert("RGB颜色值不是数字!");
  171. if (n > 255)
  172. return alert("RGB颜色数字必须在0-255之间!");
  173. var c = "0123456789ABCDEF", b = "", a = n % 16;
  174. b = c.substr(a, 1); a = (n - a) / 16;
  175. hexcode += c.substr(a, 1) + b
  176. }
  177. return hexcode;
  178. }
  179. function init() {
  180. }
  181. return {
  182. init: function () {
  183. init();
  184. }
  185. };
  186. }