Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

375 lines
12 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. Ext.ns('Ext.ux');
  16. Ext.ux.Lightbox = (function(){
  17. var els = {},
  18. images = [],
  19. activeImage,
  20. initialized = false,
  21. selectors = [];
  22. return {
  23. overlayOpacity: 0.85,
  24. animate: true,
  25. resizeSpeed: 8,
  26. borderSize: 10,
  27. labelImage: "Image",
  28. labelOf: "of",
  29. init: function() {
  30. this.resizeDuration = this.animate ? ((11 - this.resizeSpeed) * 0.15) : 0;
  31. this.overlayDuration = this.animate ? 0.2 : 0;
  32. if(!initialized) {
  33. Ext.apply(this, Ext.util.Observable.prototype);
  34. Ext.util.Observable.constructor.call(this);
  35. this.addEvents('open', 'close');
  36. this.initMarkup();
  37. this.initEvents();
  38. initialized = true;
  39. }
  40. },
  41. initMarkup: function() {
  42. els.shim = Ext.DomHelper.append(document.body, {
  43. tag: 'iframe',
  44. id: 'ux-lightbox-shim'
  45. }, true);
  46. els.overlay = Ext.DomHelper.append(document.body, {
  47. id: 'ux-lightbox-overlay'
  48. }, true);
  49. var lightboxTpl = new Ext.Template(this.getTemplate());
  50. els.lightbox = lightboxTpl.append(document.body, {}, true);
  51. var ids =
  52. ['outerImageContainer', 'imageContainer', 'image', 'hoverNav', 'navPrev', 'navNext', 'loading', 'loadingLink',
  53. 'outerDataContainer', 'dataContainer', 'data', 'details', 'caption', 'imageNumber', 'bottomNav', 'navClose'];
  54. Ext.each(ids, function(id){
  55. els[id] = Ext.get('ux-lightbox-' + id);
  56. });
  57. Ext.each([els.overlay, els.lightbox, els.shim], function(el){
  58. el.setVisibilityMode(Ext.Element.DISPLAY)
  59. el.hide();
  60. });
  61. var size = (this.animate ? 250 : 1) + 'px';
  62. els.outerImageContainer.setStyle({
  63. width: size,
  64. height: size
  65. });
  66. },
  67. getTemplate : function() {
  68. return [
  69. '<div id="ux-lightbox">',
  70. '<div id="ux-lightbox-outerImageContainer">',
  71. '<div id="ux-lightbox-imageContainer">',
  72. '<img id="ux-lightbox-image">',
  73. '<div id="ux-lightbox-hoverNav">',
  74. '<a href="#" id="ux-lightbox-navPrev"></a>',
  75. '<a href="#" id="ux-lightbox-navNext"></a>',
  76. '</div>',
  77. '<div id="ux-lightbox-loading">',
  78. '<a id="ux-lightbox-loadingLink"></a>',
  79. '</div>',
  80. '</div>',
  81. '</div>',
  82. '<div id="ux-lightbox-outerDataContainer">',
  83. '<div id="ux-lightbox-dataContainer">',
  84. '<div id="ux-lightbox-data">',
  85. '<div id="ux-lightbox-details">',
  86. '<span id="ux-lightbox-caption"></span>',
  87. '<span id="ux-lightbox-imageNumber"></span>',
  88. '</div>',
  89. '<div id="ux-lightbox-bottomNav">',
  90. '<a href="#" id="ux-lightbox-navClose"></a>',
  91. '</div>',
  92. '</div>',
  93. '</div>',
  94. '</div>',
  95. '</div>'
  96. ];
  97. },
  98. initEvents: function() {
  99. var close = function(ev) {
  100. ev.preventDefault();
  101. this.close();
  102. };
  103. els.overlay.on('click', close, this);
  104. els.loadingLink.on('click', close, this);
  105. els.navClose.on('click', close, this);
  106. els.lightbox.on('click', function(ev) {
  107. if(ev.getTarget().id == 'ux-lightbox') {
  108. this.close();
  109. }
  110. }, this);
  111. els.navPrev.on('click', function(ev) {
  112. ev.preventDefault();
  113. this.setImage(activeImage - 1);
  114. }, this);
  115. els.navNext.on('click', function(ev) {
  116. ev.preventDefault();
  117. this.setImage(activeImage + 1);
  118. }, this);
  119. },
  120. register: function(sel, group) {
  121. if(selectors.indexOf(sel) === -1) {
  122. selectors.push(sel);
  123. Ext.fly(document).on('click', function(ev){
  124. var target = ev.getTarget(sel);
  125. if (target) {
  126. ev.preventDefault();
  127. this.open(target, sel, group);
  128. }
  129. }, this);
  130. }
  131. },
  132. open: function(image, sel, group) {
  133. group = group || false;
  134. this.setViewSize();
  135. els.overlay.fadeIn({
  136. duration: this.overlayDuration,
  137. endOpacity: this.overlayOpacity,
  138. callback: function() {
  139. images = [];
  140. var index = 0;
  141. if(!group) {
  142. images.push([image.href, image.title]);
  143. }
  144. else {
  145. var setItems = Ext.query(sel);
  146. Ext.each(setItems, function(item) {
  147. if(item.href) {
  148. images.push([item.href, item.title]);
  149. }
  150. });
  151. while (images[index][0] != image.href) {
  152. index++;
  153. }
  154. }
  155. // calculate top and left offset for the lightbox
  156. var pageScroll = Ext.fly(document).getScroll();
  157. var lightboxTop = pageScroll.top + (Ext.lib.Dom.getViewportHeight() / 10);
  158. var lightboxLeft = pageScroll.left;
  159. els.lightbox.setStyle({
  160. top: lightboxTop + 'px',
  161. left: lightboxLeft + 'px'
  162. }).show();
  163. this.setImage(index);
  164. this.fireEvent('open', images[index]);
  165. },
  166. scope: this
  167. });
  168. },
  169. setViewSize: function(){
  170. var viewSize = this.getViewSize();
  171. els.overlay.setStyle({
  172. width: viewSize[0] + 'px',
  173. height: viewSize[1] + 'px'
  174. });
  175. els.shim.setStyle({
  176. width: viewSize[0] + 'px',
  177. height: viewSize[1] + 'px'
  178. }).show();
  179. },
  180. setImage: function(index){
  181. activeImage = index;
  182. this.disableKeyNav();
  183. if (this.animate) {
  184. els.loading.show();
  185. }
  186. els.image.hide();
  187. els.hoverNav.hide();
  188. els.navPrev.hide();
  189. els.navNext.hide();
  190. els.dataContainer.setOpacity(0.0001);
  191. els.imageNumber.hide();
  192. var preload = new Image();
  193. preload.onload = (function(){
  194. els.image.dom.src = images[activeImage][0];
  195. this.resizeImage(preload.width, preload.height);
  196. }).createDelegate(this);
  197. preload.src = images[activeImage][0];
  198. },
  199. resizeImage: function(w, h){
  200. var wCur = els.outerImageContainer.getWidth();
  201. var hCur = els.outerImageContainer.getHeight();
  202. var wNew = (w + this.borderSize * 2);
  203. var hNew = (h + this.borderSize * 2);
  204. var wDiff = wCur - wNew;
  205. var hDiff = hCur - hNew;
  206. var afterResize = function(){
  207. els.hoverNav.setWidth(els.imageContainer.getWidth() + 'px');
  208. els.navPrev.setHeight(h + 'px');
  209. els.navNext.setHeight(h + 'px');
  210. els.outerDataContainer.setWidth(wNew + 'px');
  211. this.showImage();
  212. };
  213. if (hDiff != 0 || wDiff != 0) {
  214. els.outerImageContainer.shift({
  215. height: hNew,
  216. width: wNew,
  217. duration: this.resizeDuration,
  218. scope: this,
  219. callback: afterResize,
  220. delay: 50
  221. });
  222. }
  223. else {
  224. afterResize.call(this);
  225. }
  226. },
  227. showImage: function(){
  228. els.loading.hide();
  229. els.image.fadeIn({
  230. duration: this.resizeDuration,
  231. scope: this,
  232. callback: function(){
  233. this.updateDetails();
  234. }
  235. });
  236. this.preloadImages();
  237. },
  238. updateDetails: function(){
  239. var detailsWidth = els.data.getWidth(true) - els.navClose.getWidth() - 10;
  240. els.details.setWidth((detailsWidth > 0 ? detailsWidth : 0) + 'px');
  241. els.caption.update(images[activeImage][1]);
  242. els.caption.show();
  243. if (images.length > 1) {
  244. els.imageNumber.update(this.labelImage + ' ' + (activeImage + 1) + ' ' + this.labelOf + ' ' + images.length);
  245. els.imageNumber.show();
  246. }
  247. els.dataContainer.fadeIn({
  248. duration: this.resizeDuration/2,
  249. scope: this,
  250. callback: function() {
  251. var viewSize = this.getViewSize();
  252. els.overlay.setHeight(viewSize[1] + 'px');
  253. this.updateNav();
  254. }
  255. });
  256. },
  257. updateNav: function(){
  258. this.enableKeyNav();
  259. els.hoverNav.show();
  260. // if not first image in set, display prev image button
  261. if (activeImage > 0)
  262. els.navPrev.show();
  263. // if not last image in set, display next image button
  264. if (activeImage < (images.length - 1))
  265. els.navNext.show();
  266. },
  267. enableKeyNav: function() {
  268. Ext.fly(document).on('keydown', this.keyNavAction, this);
  269. },
  270. disableKeyNav: function() {
  271. Ext.fly(document).un('keydown', this.keyNavAction, this);
  272. },
  273. keyNavAction: function(ev) {
  274. var keyCode = ev.getKey();
  275. if (
  276. keyCode == 88 || // x
  277. keyCode == 67 || // c
  278. keyCode == 27
  279. ) {
  280. this.close();
  281. }
  282. else if (keyCode == 80 || keyCode == 37){ // display previous image
  283. if (activeImage != 0){
  284. this.setImage(activeImage - 1);
  285. }
  286. }
  287. else if (keyCode == 78 || keyCode == 39){ // display next image
  288. if (activeImage != (images.length - 1)){
  289. this.setImage(activeImage + 1);
  290. }
  291. }
  292. },
  293. preloadImages: function(){
  294. var next, prev;
  295. if (images.length > activeImage + 1) {
  296. next = new Image();
  297. next.src = images[activeImage + 1][0];
  298. }
  299. if (activeImage > 0) {
  300. prev = new Image();
  301. prev.src = images[activeImage - 1][0];
  302. }
  303. },
  304. close: function(){
  305. this.disableKeyNav();
  306. els.lightbox.hide();
  307. els.overlay.fadeOut({
  308. duration: this.overlayDuration
  309. });
  310. els.shim.hide();
  311. this.fireEvent('close', activeImage);
  312. },
  313. getViewSize: function() {
  314. return [Ext.lib.Dom.getViewWidth(), Ext.lib.Dom.getViewHeight()];
  315. }
  316. }
  317. })();
  318. Ext.onReady(Ext.ux.Lightbox.init, Ext.ux.Lightbox);</pre>
  319. </body>
  320. </html>