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.

342 lines
11 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.Carousel = Ext.extend(Ext.util.Observable, {
  17. interval: 3,
  18. transitionDuration: 1,
  19. transitionType: 'carousel',
  20. transitionEasing: 'easeOut',
  21. itemSelector: 'img',
  22. activeSlide: 0,
  23. autoPlay: false,
  24. showPlayButton: false,
  25. pauseOnNavigate: false,
  26. wrap: false,
  27. freezeOnHover: false,
  28. navigationOnHover: false,
  29. hideNavigation: false,
  30. width: null,
  31. height: null,
  32. constructor: function(elId, config) {
  33. config = config || {};
  34. Ext.apply(this, config);
  35. Ext.ux.Carousel.superclass.constructor.call(this, config);
  36. this.addEvents(
  37. 'beforeprev',
  38. 'prev',
  39. 'beforenext',
  40. 'next',
  41. 'change',
  42. 'play',
  43. 'pause',
  44. 'freeze',
  45. 'unfreeze'
  46. );
  47. this.el = Ext.get(elId);
  48. this.slides = this.els = [];
  49. if(this.autoPlay || this.showPlayButton) {
  50. this.wrap = true;
  51. };
  52. if(this.autoPlay && typeof config.showPlayButton === 'undefined') {
  53. this.showPlayButton = true;
  54. }
  55. this.initMarkup();
  56. this.initEvents();
  57. if(this.carouselSize > 0) {
  58. this.refresh();
  59. }
  60. },
  61. initMarkup: function() {
  62. var dh = Ext.DomHelper;
  63. this.carouselSize = 0;
  64. var items = this.el.select(this.itemSelector);
  65. this.els.container = dh.append(this.el, {cls: 'ux-carousel-container'}, true);
  66. this.els.slidesWrap = dh.append(this.els.container, {cls: 'ux-carousel-slides-wrap'}, true);
  67. this.els.navigation = dh.append(this.els.container, {cls: 'ux-carousel-nav'}, true).hide();
  68. this.els.caption = dh.append(this.els.navigation, {tag: 'h2', cls: 'ux-carousel-caption'}, true);
  69. this.els.navNext = dh.append(this.els.navigation, {tag: 'a', href: '#', cls: 'ux-carousel-nav-next'}, true);
  70. if(this.showPlayButton) {
  71. this.els.navPlay = dh.append(this.els.navigation, {tag: 'a', href: '#', cls: 'ux-carousel-nav-play'}, true)
  72. }
  73. this.els.navPrev = dh.append(this.els.navigation, {tag: 'a', href: '#', cls: 'ux-carousel-nav-prev'}, true);
  74. // set the dimensions of the container
  75. this.slideWidth = this.width || this.el.getWidth(true);
  76. this.slideHeight = this.height || this.el.getHeight(true);
  77. this.els.container.setStyle({
  78. width: this.slideWidth + 'px',
  79. height: this.slideHeight + 'px'
  80. });
  81. this.els.caption.setWidth((this.slideWidth - (this.els.navNext.getWidth()*2) - (this.showPlayButton ? this.els.navPlay.getWidth() : 0) - 20) + 'px')
  82. items.appendTo(this.els.slidesWrap).each(function(item) {
  83. item = item.wrap({cls: 'ux-carousel-slide'});
  84. this.slides.push(item);
  85. item.setWidth(this.slideWidth + 'px').setHeight(this.slideHeight + 'px');
  86. }, this);
  87. this.carouselSize = this.slides.length;
  88. if(this.navigationOnHover) {
  89. this.els.navigation.setStyle('top', (-1*this.els.navigation.getHeight()) + 'px');
  90. }
  91. this.el.clip();
  92. },
  93. initEvents: function() {
  94. this.els.navPrev.on('click', function(ev) {
  95. ev.preventDefault();
  96. var target = ev.getTarget();
  97. target.blur();
  98. if(Ext.fly(target).hasClass('ux-carousel-nav-disabled')) return;
  99. this.prev();
  100. }, this);
  101. this.els.navNext.on('click', function(ev) {
  102. ev.preventDefault();
  103. var target = ev.getTarget();
  104. target.blur();
  105. if(Ext.fly(target).hasClass('ux-carousel-nav-disabled')) return;
  106. this.next();
  107. }, this);
  108. if(this.showPlayButton) {
  109. this.els.navPlay.on('click', function(ev){
  110. ev.preventDefault();
  111. ev.getTarget().blur();
  112. if(this.playing) {
  113. this.pause();
  114. }
  115. else {
  116. this.play();
  117. }
  118. }, this);
  119. };
  120. if(this.freezeOnHover) {
  121. this.els.container.on('mouseenter', function(){
  122. if(this.playing) {
  123. this.fireEvent('freeze', this.slides[this.activeSlide]);
  124. Ext.TaskMgr.stop(this.playTask);
  125. }
  126. }, this);
  127. this.els.container.on('mouseleave', function(){
  128. if(this.playing) {
  129. this.fireEvent('unfreeze', this.slides[this.activeSlide]);
  130. Ext.TaskMgr.start(this.playTask);
  131. }
  132. }, this, {buffer: (this.interval/2)*1000});
  133. };
  134. if(this.navigationOnHover) {
  135. this.els.container.on('mouseenter', function(){
  136. if(!this.navigationShown) {
  137. this.navigationShown = true;
  138. this.els.navigation.stopFx(false).shift({
  139. y: this.els.container.getY(),
  140. duration: this.transitionDuration
  141. })
  142. }
  143. }, this);
  144. this.els.container.on('mouseleave', function(){
  145. if(this.navigationShown) {
  146. this.navigationShown = false;
  147. this.els.navigation.stopFx(false).shift({
  148. y: this.els.navigation.getHeight() - this.els.container.getY(),
  149. duration: this.transitionDuration
  150. })
  151. }
  152. }, this);
  153. }
  154. if(this.interval && this.autoPlay) {
  155. this.play();
  156. };
  157. },
  158. prev: function() {
  159. if (this.fireEvent('beforeprev') === false) {
  160. return;
  161. }
  162. if(this.pauseOnNavigate) {
  163. this.pause();
  164. }
  165. this.setSlide(this.activeSlide - 1);
  166. this.fireEvent('prev', this.activeSlide);
  167. return this;
  168. },
  169. next: function() {
  170. if(this.fireEvent('beforenext') === false) {
  171. return;
  172. }
  173. if(this.pauseOnNavigate) {
  174. this.pause();
  175. }
  176. this.setSlide(this.activeSlide + 1);
  177. this.fireEvent('next', this.activeSlide);
  178. return this;
  179. },
  180. play: function() {
  181. if(!this.playing) {
  182. this.playTask = this.playTask || {
  183. run: function() {
  184. this.playing = true;
  185. this.setSlide(this.activeSlide+1);
  186. },
  187. interval: this.interval*1000,
  188. scope: this
  189. };
  190. this.playTaskBuffer = this.playTaskBuffer || new Ext.util.DelayedTask(function() {
  191. Ext.TaskMgr.start(this.playTask);
  192. }, this);
  193. this.playTaskBuffer.delay(this.interval*1000);
  194. this.playing = true;
  195. if(this.showPlayButton) {
  196. this.els.navPlay.addClass('ux-carousel-playing');
  197. }
  198. this.fireEvent('play');
  199. }
  200. return this;
  201. },
  202. pause: function() {
  203. if(this.playing) {
  204. Ext.TaskMgr.stop(this.playTask);
  205. this.playTaskBuffer.cancel();
  206. this.playing = false;
  207. if(this.showPlayButton) {
  208. this.els.navPlay.removeClass('ux-carousel-playing');
  209. }
  210. this.fireEvent('pause');
  211. }
  212. return this;
  213. },
  214. clear: function() {
  215. this.els.slidesWrap.update('');
  216. this.slides = [];
  217. this.carouselSize = 0;
  218. this.pause();
  219. return this;
  220. },
  221. add: function(el, refresh) {
  222. var item = Ext.fly(el).appendTo(this.els.slidesWrap).wrap({cls: 'ux-carousel-slide'});
  223. item.setWidth(this.slideWidth + 'px').setHeight(this.slideHeight + 'px');
  224. this.slides.push(item);
  225. if(refresh) {
  226. this.refresh();
  227. }
  228. return this;
  229. },
  230. refresh: function() {
  231. this.carouselSize = this.slides.length;
  232. this.els.slidesWrap.setWidth((this.slideWidth * this.carouselSize) + 'px');
  233. if(this.carouselSize > 0) {
  234. if(!this.hideNavigation) this.els.navigation.show();
  235. this.activeSlide = 0;
  236. this.setSlide(0, true);
  237. }
  238. return this;
  239. },
  240. setSlide: function(index, initial) {
  241. if(!this.wrap && !this.slides[index]) {
  242. return;
  243. }
  244. else if(this.wrap) {
  245. if(index < 0) {
  246. index = this.carouselSize-1;
  247. }
  248. else if(index > this.carouselSize-1) {
  249. index = 0;
  250. }
  251. }
  252. if(!this.slides[index]) {
  253. return;
  254. }
  255. this.els.caption.update(this.slides[index].child(':first-child', true).title || '');
  256. var offset = index * this.slideWidth;
  257. if (!initial) {
  258. switch (this.transitionType) {
  259. case 'fade':
  260. this.slides[index].setOpacity(0);
  261. this.slides[this.activeSlide].stopFx(false).fadeOut({
  262. duration: this.transitionDuration / 2,
  263. callback: function(){
  264. this.els.slidesWrap.setStyle('left', (-1 * offset) + 'px');
  265. this.slides[this.activeSlide].setOpacity(1);
  266. this.slides[index].fadeIn({
  267. duration: this.transitionDuration / 2
  268. });
  269. },
  270. scope: this
  271. })
  272. break;
  273. default:
  274. var xNew = (-1 * offset) + this.els.container.getX();
  275. this.els.slidesWrap.stopFx(false);
  276. this.els.slidesWrap.shift({
  277. duration: this.transitionDuration,
  278. x: xNew,
  279. easing: this.transitionEasing
  280. });
  281. break;
  282. }
  283. }
  284. else {
  285. this.els.slidesWrap.setStyle('left', '0');
  286. }
  287. this.activeSlide = index;
  288. this.updateNav();
  289. this.fireEvent('change', this.slides[index], index);
  290. },
  291. updateNav: function() {
  292. this.els.navPrev.removeClass('ux-carousel-nav-disabled');
  293. this.els.navNext.removeClass('ux-carousel-nav-disabled');
  294. if(!this.wrap) {
  295. if(this.activeSlide === 0) {
  296. this.els.navPrev.addClass('ux-carousel-nav-disabled');
  297. }
  298. if(this.activeSlide === this.carouselSize-1) {
  299. this.els.navNext.addClass('ux-carousel-nav-disabled');
  300. }
  301. }
  302. }
  303. });</pre>
  304. </body>
  305. </html>