/[drupal]/contributions/modules/webcams/webcams.js
ViewVC logotype

Contents of /contributions/modules/webcams/webcams.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.7 - (show annotations) (download) (as text)
Sat Apr 19 01:06:24 2008 UTC (19 months, 1 week ago) by moonray
Branch: MAIN
CVS Tags: DRUPAL-6--1-4, HEAD
Branch point for: DRUPAL-6--1
Changes since 1.6: +7 -6 lines
File MIME type: text/javascript
Views integration fix. Also fixed issue with multiple click events being attached when thickbox module is enabled and webcam times out.
1 (function($) {
2 $.webcam = function() {
3 return this;
4 };
5 $.webcam.compareBaseUrls = function(url1, url2) {
6 if (typeof(url1 == 'String') && url1.indexOf('?') !== -1) {
7 url1 = url1.substr(0, url1.indexOf('?'));
8 }
9 if (typeof(url2 == 'String') && url2.indexOf('?') !== -1) {
10 url2 = url2.substr(0, url2.indexOf('?'));
11 }
12 if (url1 == url2) {
13 return true;
14 } else {
15 return false;
16 }
17 };
18 $.webcam.counters = new Array();
19 $.webcam.timers = new Array();
20 $.webcam.errors = false;
21 $.webcam.init = function(id, name, url, durl, width, height, time, timeout, errid, errmsg){
22 $.webcam.timers[id] = setInterval("$.webcam.refresh('" + id + "', '" + name + "', '" + url + "', '" + durl + "', " + width + ", " + height + ", " + timeout + ", '" + errid + "', '" + errmsg + "')", time);
23 $.webcam.counters[id] = 0;
24 $.webcam.refresh(id, name, url, durl, width, height, timeout, errid, errmsg);
25 };
26 $.webcam.refresh = function(id, name, url, durl, width, height, timeout, errid, errmsg){
27 var theDate = new Date();
28 if (timeout > 0 && $.webcam.counters[id]++ > timeout) {
29 clearInterval($.webcam.timers[id]);
30 if ($.webcam.errors == false) {
31 $('#'+errid).prepend('<div class="error"></div>');
32 $.webcam.errors = true;
33 }
34 $('#'+errid+' .error').append(errmsg + '<br />');
35
36 // Add some code for to integrate webcams with thickbox
37 if (typeof tb_show == 'function' && $('#'+id+' a.thickbox').attr('href') !== undefined) {
38 if ($.webcam.compareBaseUrls(url, $('#'+id+' a.thickbox').attr('href')) || $.webcam.compareBaseUrls(durl, $('#'+id+' a.thickbox').attr('href'))) {
39 $('#'+id+' a.thickbox').unbind('click');
40 $('#'+id+' a.thickbox').click(function(){
41 var t = this.title || this.name || null;
42 var a = this.href || this.alt;
43 var g = this.rel || false;
44 tb_show(t,a,g);
45 $('#TB_window').prepend('<div id="TB_error"><div class="error">' + errmsg + '</div></div>');
46 $("#TB_load").remove();
47 this.blur();
48 return false;
49 });
50 }
51 if (document.getElementById("TB_window") !== null) {
52 if ($.webcam.compareBaseUrls(url, $('#TB_Image').attr('src'))) {
53 $('#TB_window').prepend('<div id="TB_error"><div class="error">' + errmsg + '</div></div>');
54 }
55 }
56 }
57 } else {
58 $.webcam.preload(id, url + "?" + parseInt(theDate.getTime() / 1000), durl, width, height);
59 }
60 };
61 $.webcam.preload = function(id, url, durl, width, height){
62 var img = new Image();
63 img.onerror = function(){
64 $('#'+id+' img.webcams-image').attr('src', durl);
65 };
66 img.onload = function(){
67 img.onload = null;
68 if (img.width > width) {
69 img.height = img.height * (width / img.width);
70 img.width = width;
71 if (img.height > height) {
72 img.width = img.width * (height / img.height);
73 img.height = height;
74 }
75 } else if (img.height > height) {
76 img.width = img.width * (height / img.height);
77 img.height = height;
78 if (img.width > width) {
79 img.height = img.height * (slideW / img.width);
80 img.width = width;
81 }
82 }
83 $('#'+id+' img.webcams-image').attr('src', img.src).css('width', img.width).css('height', img.height);
84
85 // Add some code for to integrate webcams with thickbox
86 if (typeof tb_show == 'function' && $('#'+id+' a.thickbox').attr('href') !== undefined) {
87 if ($.webcam.compareBaseUrls(url, $('#'+id+' a.thickbox').attr('href')) || $.webcam.compareBaseUrls(durl, $('#'+id+' a.thickbox').attr('href'))) {
88 $('#'+id+' a.thickbox').attr('href', img.src);
89 }
90 if (document.getElementById("TB_Image") !== null) {
91 if ($.webcam.compareBaseUrls(url, $('#TB_Image').attr('src'))) {
92 $('#TB_Image').attr('src', img.src);
93 }
94 }
95 }
96 };
97 img.src = url;
98 };
99 })(jQuery);

  ViewVC Help
Powered by ViewVC 1.1.2