noconflict.html 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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:darkgrey;
  30. /*max-width:600px;*/
  31. padding:20px;
  32. }
  33. /*This is the div within which the signature canvas is fitted*/
  34. #signature {
  35. border: 2px dotted black;
  36. background-color:lightgrey;
  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>jSignature inherits colors from parent element. Text = Pen color. Background = Background. (This works even when Flash-based Canvas emulation is used.)</div>
  59. <div id="signature"></div></div>
  60. <div id="tools"></div>
  61. <div><p>Display Area:</p><div id="displayarea"></div></div>
  62. </div>
  63. <div id="scrollgrabber"></div>
  64. </div>
  65. <script src="../libs/jquery.js"></script>
  66. <script type="text/javascript">
  67. jQuery.noConflict()
  68. </script>
  69. <script>
  70. /* @preserve
  71. jQuery pub/sub plugin by Peter Higgins (dante@dojotoolkit.org)
  72. Loosely based on Dojo publish/subscribe API, limited in scope. Rewritten blindly.
  73. Original is (c) Dojo Foundation 2004-2010. Released under either AFL or new BSD, see:
  74. http://dojofoundation.org/license for more information.
  75. */
  76. (function($) {
  77. var topics = {};
  78. $.publish = function(topic, args) {
  79. if (topics[topic]) {
  80. var currentTopic = topics[topic],
  81. args = args || {};
  82. for (var i = 0, j = currentTopic.length; i < j; i++) {
  83. currentTopic[i].call($, args);
  84. }
  85. }
  86. };
  87. $.subscribe = function(topic, callback) {
  88. if (!topics[topic]) {
  89. topics[topic] = [];
  90. }
  91. topics[topic].push(callback);
  92. return {
  93. "topic": topic,
  94. "callback": callback
  95. };
  96. };
  97. $.unsubscribe = function(handle) {
  98. var topic = handle.topic;
  99. if (topics[topic]) {
  100. var currentTopic = topics[topic];
  101. for (var i = 0, j = currentTopic.length; i < j; i++) {
  102. if (currentTopic[i] === handle.callback) {
  103. currentTopic.splice(i, 1);
  104. }
  105. }
  106. }
  107. };
  108. })(jQuery);
  109. </script>
  110. <script src="../libs/jSignature.min.noconflict.js"></script>
  111. <script>
  112. (function($){
  113. $(document).ready(function() {
  114. // This is the part where jSignature is initialized.
  115. var $sigdiv = $("#signature").jSignature({'UndoButton':true})
  116. // All the code below is just code driving the demo.
  117. , $tools = $('#tools')
  118. , $extraarea = $('#displayarea')
  119. , pubsubprefix = 'jSignature.demo.'
  120. var export_plugins = $sigdiv.jSignature('listPlugins','export')
  121. , chops = ['<span><b>Extract signature data as: </b></span><select>','<option value="">(select export format)</option>']
  122. , name
  123. for(var i in export_plugins){
  124. if (export_plugins.hasOwnProperty(i)){
  125. name = export_plugins[i]
  126. chops.push('<option value="' + name + '">' + name + '</option>')
  127. }
  128. }
  129. chops.push('</select><span><b> or: </b></span>')
  130. $(chops.join('')).bind('change', function(e){
  131. if (e.target.value !== ''){
  132. var data = $sigdiv.jSignature('getData', e.target.value)
  133. $.publish(pubsubprefix + 'formatchanged')
  134. if (typeof data === 'string'){
  135. $('textarea', $tools).val(data)
  136. } else if($.isArray(data) && data.length === 2){
  137. $('textarea', $tools).val(data.join(','))
  138. $.publish(pubsubprefix + data[0], data);
  139. } else {
  140. try {
  141. $('textarea', $tools).val(JSON.stringify(data))
  142. } catch (ex) {
  143. $('textarea', $tools).val('Not sure how to stringify this, likely binary, format.')
  144. }
  145. }
  146. }
  147. }).appendTo($tools)
  148. $('<input type="button" value="Reset">').bind('click', function(e){
  149. $sigdiv.jSignature('reset')
  150. }).appendTo($tools)
  151. $('<div><textarea style="width:100%;height:7em;"></textarea></div>').appendTo($tools)
  152. $.subscribe(pubsubprefix + 'formatchanged', function(){
  153. $extraarea.html('')
  154. })
  155. $.subscribe(pubsubprefix + 'image/svg+xml', function(data) {
  156. try{
  157. var i = new Image()
  158. i.src = 'data:' + data[0] + ';base64,' + btoa( data[1] )
  159. $(i).appendTo($extraarea)
  160. } catch (ex) {
  161. }
  162. var message = [
  163. "If you don't see an image immediately above, it means your browser is unable to display in-line (data-url-formatted) SVG."
  164. , "This is NOT an issue with jSignature, as we can export proper SVG document regardless of browser's ability to display it."
  165. , "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."
  166. ]
  167. $( "<div>" + message.join("<br/>") + "</div>" ).appendTo( $extraarea )
  168. });
  169. $.subscribe(pubsubprefix + 'image/svg+xml;base64', function(data) {
  170. var i = new Image()
  171. i.src = 'data:' + data[0] + ',' + data[1]
  172. $(i).appendTo($extraarea)
  173. var message = [
  174. "If you don't see an image immediately above, it means your browser is unable to display in-line (data-url-formatted) SVG."
  175. , "This is NOT an issue with jSignature, as we can export proper SVG document regardless of browser's ability to display it."
  176. , "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."
  177. ]
  178. $( "<div>" + message.join("<br/>") + "</div>" ).appendTo( $extraarea )
  179. });
  180. $.subscribe(pubsubprefix + 'image/png;base64', function(data) {
  181. var i = new Image()
  182. i.src = 'data:' + data[0] + ',' + data[1]
  183. $('<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)
  184. $(i).appendTo($extraarea)
  185. });
  186. $.subscribe(pubsubprefix + 'image/jsignature;base30', function(data) {
  187. $('<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)
  188. });
  189. if (Modernizr.touch){
  190. $('#scrollgrabber').height($('#content').height())
  191. }
  192. })
  193. })(jQuery)
  194. </script>
  195. </body>
  196. </html>