1. jQuery("#webcam").webcam(
  2. {
  3. width : 320,
  4. height : 240,
  5. mode : "save", // save, callback
  6. swffile : "/swf/jscam.swf", // jscam_canvas_only.swf, jscam.swf
  7. onTick : function(remain) {
  8.  
  9. if (0 == remain) {
  10. jQuery("#status").text("Cheese!");
  11. } else {
  12. jQuery("#status")
  13. .text(remain + " seconds remaining...");
  14. }
  15. },
  16.  
  17. onSave : function(data) {
  18. for ( var i = 0; i < 320; i++) {
  19. var tmp = parseInt(col[i]);
  20. img.data[pos + 0] = (tmp >> 16) & 0xff;
  21. img.data[pos + 1] = (tmp >> 8) & 0xff;
  22. img.data[pos + 2] = tmp & 0xff;
  23. img.data[pos + 3] = 0xff;
  24. pos += 4;
  25. }
  26.  
  27. if (pos >= 0x4B000) {
  28. ctx.putImageData(img, 0, 0);
  29. pos = 0;
  30. }
  31.  
  32. jQuery("#status").text("Done!");
  33. /*var url = "redirect" ;
  34. window.location = url;*/
  35. },
  36.  
  37. onCapture : function() {
  38. //webcam.save('/webcam.php');
  39. webcam.save('/webcam.php');
  40. webcam.save();
  41. //Webcam.save ( '/Users/upload/' );
  42. jQuery("#flash").css("display", "block");
  43. jQuery("#flash").fadeOut(100, function() {
  44. jQuery("#flash").css("opacity", 1);
  45. });
  46. },
  47.  
  48. debug : function(type, string) {
  49. jQuery("#status").html(type + ": " + string);
  50. },
  51.  
  52. onLoad : function() {
  53. var cams = webcam.getCameraList();
  54. for ( var i in cams) {
  55. jQuery("#cams").append("<li>" + cams[i] + "</li>");
  56. }
  57. }
  58. });
  59.  
  60. function getPageSize() {
  61. var xScroll, yScroll;
  62. if (window.innerHeight && window.scrollMaxY) {
  63. xScroll = window.innerWidth + window.scrollMaxX;
  64. yScroll = window.innerHeight + window.scrollMaxY;
  65. } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
  66. xScroll = document.body.scrollWidth;
  67. yScroll = document.body.scrollHeight;
  68. } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
  69. xScroll = document.body.offsetWidth;
  70. yScroll = document.body.offsetHeight;
  71. }
  72.  
  73. var windowWidth, windowHeight;
  74.  
  75. if (self.innerHeight) { // all except Explorer
  76. if (document.documentElement.clientWidth) {
  77. windowWidth = document.documentElement.clientWidth;
  78. } else {
  79. windowWidth = self.innerWidth;
  80. }
  81. windowHeight = self.innerHeight;
  82. } else if (document.documentElement
  83. && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
  84. windowWidth = document.documentElement.clientWidth;
  85. windowHeight = document.documentElement.clientHeight;
  86. } else if (document.body) { // other Explorers
  87. windowWidth = document.body.clientWidth;
  88. windowHeight = document.body.clientHeight;
  89. }
  90.  
  91. // for small pages with total height less then height of the viewport
  92. if (yScroll < windowHeight) {
  93. pageHeight = windowHeight;
  94. } else {
  95. pageHeight = yScroll;
  96. }
  97.  
  98. // for small pages with total width less then width of the viewport
  99. if (xScroll < windowWidth) {
  100. pageWidth = xScroll;
  101. } else {
  102. pageWidth = windowWidth;
  103. }
  104. return [ pageWidth, pageHeight ];
  105. }
  106.  
  107. window.addEventListener("load", function() {
  108. jQuery("body").append("<div id=\"flash\"></div>");
  109. var canvas = document.getElementById("canvas");
  110. if (canvas.getContext) {
  111. ctx = document.getElementById("canvas").getContext("2d");
  112. ctx.clearRect(0, 0, 320, 240);
  113. var img = new Image();
  114. img.src = "/static/logo.gif";
  115. img.onload = function() {
  116. ctx.drawImage(img, 129, 89);
  117. }
  118. image = ctx.getImageData(0, 0, 320, 240);
  119. }
  120.  
  121. var pageSize = getPageSize();
  122. jQuery("#flash").css({
  123. height : pageSize[1] + "px"
  124. });
  125. }, false);
  126.  
  127. window.addEventListener("resize", function() {
  128. var pageSize = getPageSize();
  129. jQuery("#flash").css({
  130. height : pageSize[1] + "px"
  131. });
  132. }, false);