/jquery.webcam.js

https://github.com/benrxv/jQuery-webcam · JavaScript · 89 lines · 62 code · 18 blank · 9 comment · 10 complexity · 837ebf22d4df5f11eeecd52c2567afcb MD5 · raw file

  1. /**
  2. * @license jQuery webcam plugin v1.0 09/12/2010
  3. * http://www.xarg.org/project/jquery-webcam-plugin/
  4. *
  5. * Copyright (c) 2010, Robert Eisele (robert@xarg.org)
  6. * Dual licensed under the MIT or GPL Version 2 licenses.
  7. **/
  8. (function ($) {
  9. var webcam = {
  10. extern: null, // external select token to support jQuery dialogs
  11. append: true, // append object instead of overwriting
  12. width: 320,
  13. height: 240,
  14. mode: "callback", // callback | save | stream
  15. swffile: "jscam.swf",
  16. quality: 85,
  17. debug: function () {},
  18. onCapture: function () {},
  19. onTick: function () {},
  20. onSave: function () {},
  21. onLoad: function () {}
  22. };
  23. window.webcam = webcam;
  24. $.fn.webcam = function(options) {
  25. if (typeof options === "object") {
  26. for (var ndx in webcam) {
  27. if (options[ndx] !== undefined) {
  28. webcam[ndx] = options[ndx];
  29. }
  30. }
  31. }
  32. var source = '<object id="XwebcamXobjectX" type="application/x-shockwave-flash" data="'+webcam.swffile+'" width="'+webcam.width+'" height="'+webcam.height+'"><param name="movie" value="'+webcam.swffile+'" /><param name="FlashVars" value="mode='+webcam.mode+'&amp;quality='+webcam.quality+'" /><param name="allowScriptAccess" value="always" /></object>';
  33. if (null !== webcam.extern) {
  34. $(webcam.extern)[webcam.append ? "append" : "html"](source);
  35. } else {
  36. this[webcam.append ? "append" : "html"](source);
  37. }
  38. (_register = function(run) {
  39. var cam = document.getElementById('XwebcamXobjectX');
  40. if (cam.capture !== undefined) {
  41. /* Simple callback methods are not allowed :-/ */
  42. webcam.capture = function(x) {
  43. try {
  44. return cam.capture(x);
  45. } catch(e) {}
  46. }
  47. webcam.save = function(x) {
  48. try {
  49. return cam.save(x);
  50. } catch(e) {}
  51. }
  52. webcam.setCamera = function(x) {
  53. try {
  54. return cam.setCamera(x);
  55. } catch(e) {}
  56. }
  57. webcam.getCameraList = function() {
  58. try {
  59. return cam.getCameraList();
  60. } catch(e) {}
  61. }
  62. webcam.onLoad();
  63. } else if (0 == run) {
  64. webcam.debug("error", "Flash movie not yet registered!");
  65. } else {
  66. /* Flash interface not ready yet */
  67. window.setTimeout(_register, 1000 * (4 - run), run - 1);
  68. }
  69. })(3);
  70. }
  71. })(jQuery);