unmini.html 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
  6. Remove this if you use the .htaccess -->
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <meta name="viewport" content="initial-scale=1.0, target-densitydpi=device-dpi" /><!-- this is for mobile (Android) Chrome -->
  9. <meta name="viewport" content="initial-scale=1.0, width=device-height"><!-- mobile Safari, FireFox, Opera Mobile -->
  10. <script src="../libs/modernizr.js"></script>
  11. <!--[if lt IE 9]>
  12. <script type="text/javascript" src="../libs/flashcanvas.js"></script>
  13. <![endif]-->
  14. <style type="text/css">
  15. div {
  16. margin-top:1em;
  17. margin-bottom:1em;
  18. }
  19. input {
  20. padding: .5em;
  21. margin: .5em;
  22. }
  23. select {
  24. padding: .5em;
  25. margin: .5em;
  26. }
  27. #signatureparent {
  28. color:darkblue;
  29. background-color:white;
  30. /*max-width:600px;*/
  31. padding:0px;
  32. }
  33. /*This is the div within which the signature canvas is fitted*/
  34. #signature {
  35. border: 0px dotted black;
  36. background-color:white;
  37. }
  38. /* Drawing the 'gripper' for touch-enabled devices */
  39. html.touch #content {
  40. float:left;
  41. width:92%;
  42. }
  43. html.touch #scrollgrabber {
  44. float:right;
  45. width:4%;
  46. margin-right:2%;
  47. background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAFCAAAAACh79lDAAAAAXNSR0IArs4c6QAAABJJREFUCB1jmMmQxjCT4T/DfwAPLgOXlrt3IwAAAABJRU5ErkJggg==)
  48. }
  49. html.borderradius #scrollgrabber {
  50. border-radius: 1em;
  51. }
  52. </style>
  53. </head>
  54. <body>
  55. <div>
  56. <div id="content">
  57. <div id="signatureparent">
  58. <div id="signature"></div></div>
  59. <div id="tools"></div>
  60. <div id="scrollgrabber"></div>
  61. </div>
  62. <script src="../libs/jquery.js"></script>
  63. <script>
  64. /* @preserve
  65. jQuery pub/sub plugin by Peter Higgins (dante@dojotoolkit.org)
  66. Loosely based on Dojo publish/subscribe API, limited in scope. Rewritten blindly.
  67. Original is (c) Dojo Foundation 2004-2010. Released under either AFL or new BSD, see:
  68. http://dojofoundation.org/license for more information.
  69. */
  70. (function($) {
  71. var topics = {};
  72. $.publish = function(topic, args) {
  73. if (topics[topic]) {
  74. var currentTopic = topics[topic],
  75. args = args || {};
  76. for (var i = 0, j = currentTopic.length; i < j; i++) {
  77. currentTopic[i].call($, args);
  78. }
  79. }
  80. };
  81. $.subscribe = function(topic, callback) {
  82. if (!topics[topic]) {
  83. topics[topic] = [];
  84. }
  85. topics[topic].push(callback);
  86. return {
  87. "topic": topic,
  88. "callback": callback
  89. };
  90. };
  91. $.unsubscribe = function(handle) {
  92. var topic = handle.topic;
  93. if (topics[topic]) {
  94. var currentTopic = topics[topic];
  95. for (var i = 0, j = currentTopic.length; i < j; i++) {
  96. if (currentTopic[i] === handle.callback) {
  97. currentTopic.splice(i, 1);
  98. }
  99. }
  100. }
  101. };
  102. })(jQuery);
  103. </script>
  104. <script src="../src/jSignature.js"></script>
  105. <script src="../src/plugins/jSignature.CompressorBase30.js"></script>
  106. <script src="../src/plugins/jSignature.CompressorSVG.js"></script>
  107. <script src="../src/plugins/jSignature.UndoButton.js"></script>
  108. <script src="../src/plugins/signhere/jSignature.SignHere.js"></script>
  109. <script>
  110. $(document).ready(function() {
  111. // This is the part where jSignature is initialized.
  112. var $sigdiv = $("#signature").jSignature({'UndoButton':true})
  113. // All the code below is just code driving the demo.
  114. , $tools = $('#tools')
  115. , $extraarea = $('#displayarea')
  116. , pubsubprefix = 'jSignature.demo.'
  117. /* var export_plugins = $sigdiv.jSignature('listPlugins','export')
  118. , chops = ['<span><b>Extract signature data as: </b></span><select>','<option value="">(select export format)</option>']
  119. , name
  120. for(var i in export_plugins){
  121. if (export_plugins.hasOwnProperty(i)){
  122. name = export_plugins[i]
  123. chops.push('<option value="' + name + '">' + name + '</option>')
  124. }
  125. }
  126. chops.push('</select><span><b> or: </b></span>') */
  127. $(chops.join('')).bind('change', function(e){
  128. if (e.target.value !== ''){
  129. var data = $sigdiv.jSignature('getData', e.target.value)
  130. $.publish(pubsubprefix + 'formatchanged')
  131. if (typeof data === 'string'){
  132. $('textarea', $tools).val(data)
  133. } else if($.isArray(data) && data.length === 2){
  134. $('textarea', $tools).val(data.join(','))
  135. $.publish(pubsubprefix + data[0], data);
  136. } else {
  137. try {
  138. $('textarea', $tools).val(JSON.stringify(data))
  139. } catch (ex) {
  140. $('textarea', $tools).val('Not sure how to stringify this, likely binary, format.')
  141. }
  142. }
  143. }
  144. }).appendTo($tools)
  145. /*
  146. $('<input type="button" value="Reset">').bind('click', function(e){
  147. $sigdiv.jSignature('reset')
  148. }).appendTo($tools) */
  149. //$('<div><textarea style="width:100%;height:7em;"></textarea></div>').appendTo($tools)
  150. $.subscribe(pubsubprefix + 'formatchanged', function(){
  151. $extraarea.html('')
  152. })
  153. $.subscribe(pubsubprefix + 'image/svg+xml', function(data) {
  154. try{
  155. var i = new Image()
  156. i.src = 'data:' + data[0] + ';base64,' + btoa( data[1] )
  157. $(i).appendTo($extraarea)
  158. } catch (ex) {
  159. }
  160. var message = [
  161. "If you don't see an image immediately above, it means your browser is unable to display in-line (data-url-formatted) SVG."
  162. , "This is NOT an issue with jSignature, as we can export proper SVG document regardless of browser's ability to display it."
  163. , "Try this page in a modern browser to see the SVG on the page, or export data as plain SVG, save to disk as text file and view in any SVG-capabale viewer."
  164. ]
  165. $( "<div>" + message.join("<br/>") + "</div>" ).appendTo( $extraarea )
  166. });
  167. $.subscribe(pubsubprefix + 'image/svg+xml;base64', function(data) {
  168. var i = new Image()
  169. i.src = 'data:' + data[0] + ',' + data[1]
  170. $(i).appendTo($extraarea)
  171. var message = [
  172. "If you don't see an image immediately above, it means your browser is unable to display in-line (data-url-formatted) SVG."
  173. , "This is NOT an issue with jSignature, as we can export proper SVG document regardless of browser's ability to display it."
  174. , "Try this page in a modern browser to see the SVG on the page, or export data as plain SVG, save to disk as text file and view in any SVG-capabale viewer."
  175. ]
  176. $( "<div>" + message.join("<br/>") + "</div>" ).appendTo( $extraarea )
  177. });
  178. $.subscribe(pubsubprefix + 'image/png;base64', function(data) {
  179. var i = new Image()
  180. i.src = 'data:' + data[0] + ',' + data[1]
  181. $('<span><b>As you can see, one of the problems of "image" extraction (besides not working on some old Androids, elsewhere) is that it extracts A LOT OF DATA and includes all the decoration that is not part of the signature.</b></span>').appendTo($extraarea)
  182. $(i).appendTo($extraarea)
  183. });
  184. $.subscribe(pubsubprefix + 'image/jsignature;base30', function(data) {
  185. $('<span><b>This is a vector format not natively render-able by browsers. Format is a compressed "movement coordinates arrays" structure tuned for use server-side. The bonus of this format is its tiny storage footprint and ease of deriving rendering instructions in programmatic, iterative manner.</b></span>').appendTo($extraarea)
  186. });
  187. if (Modernizr.touch){
  188. $('#scrollgrabber').height($('#content').height())
  189. }
  190. })
  191. </script>
  192. </body>
  193. </html>