slides.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * This file goes along with slides.css
  3. */
  4. if(!jx){
  5. var jx = {}
  6. }
  7. jx.slides = {}
  8. /**
  9. *
  10. * @params args:
  11. * main_id main panel
  12. * nav_id control panel
  13. * nav_left left button
  14. * nav_right right button
  15. * data data (array of items)
  16. * renderer point to the function that will render an item in the data
  17. */
  18. jx.slides.instance = function(args){
  19. this.main_id = args.main_id
  20. this.nav_id = args.nav_id
  21. this.data = args.data
  22. this.nav_left = args.nav_left;
  23. this.nav_right = args.nav_right;
  24. this.enable_auto= args.auto == true
  25. this.handler = null;
  26. this.page = {index:0,count:0};
  27. this.left = function(){
  28. var pane = jx.dom.get.children(this.main_id)[0]
  29. var width = $('#'+this.main_id).width()
  30. // var page = jx.dom.get.attribute('controls','info')
  31. var i = this.page.index
  32. var N = this.page.count
  33. i = ((i+1) < N)? (i+1):0
  34. $(pane).animate({'margin-left':-(width+4)*i})
  35. this.page.index = i
  36. // jx.dom.set.attribute(this.nav_id,'info',page)
  37. }
  38. this.right = function(){
  39. var pane = jx.dom.get.children(this.main_id)[0]
  40. var width = $('#'+this.main_id).width()
  41. // var page = jx.dom.get.attribute('controls','info')
  42. var i = this.page.index
  43. var N = this.page.count
  44. // alert(N)
  45. i = ((i-1) > -1)?(i-1):(N-1) ;
  46. $(pane).animate({'margin-left':-width*i})
  47. this.page.index = i
  48. // jx.dom.set.attribute(this.nav_id,'info',page)
  49. }
  50. this.stop = function(){
  51. if(this.handler != null){
  52. clearInterval(this.handler)
  53. this.handler = null
  54. }
  55. }
  56. this.auto = function(){
  57. if(this.handler == null){
  58. this.handler = setInterval(this.right,2000) }
  59. }
  60. this.bind = function(){
  61. var _ileft = jx.dom.get.instance(this.nav_left)
  62. _ileft.onclick = this.left
  63. _ileft.onmouseover = this.stop
  64. var _iright = jx.dom.get.instance(this.nav_left)
  65. _iright.onclick = this.left
  66. _iright.onmouseover = this.stop
  67. if(this.enable_auto){
  68. _ileft.onmouseout = this.auto
  69. _iright.onmouseout = this.auto
  70. }
  71. }
  72. /**
  73. * This section will handle the initialization
  74. */
  75. var pane = jx.dom.get.instance('DIV')
  76. var width = $('#'+this.main_id).width()
  77. var height = $('#'+this.main_id).height()
  78. var N = this.data.length
  79. this.page = {index:0,count:N}
  80. // jx.dom.set.attribute(this.nav_id,"info",info)
  81. // jx.dom.set.attribute("controls","page.count",N)
  82. // $(pane).width(width*N)
  83. $(pane).css("width",width*N)
  84. $(pane).height(height)
  85. $(pane).css('overflow','hidden')
  86. jx.dom.set.value(this.main_id,'')
  87. jx.dom.append(this.main_id,pane)
  88. jx.utils.patterns.visitor(this.data,function(item){
  89. console.log(item.constructor.prototype.name)
  90. var frame = jx.dom.get.instance('DIV')
  91. var picframe = jx.dom.get.instance('DIV')
  92. var image = jx.dom.get.instance('IMG')
  93. var info = jx.dom.get.instance('DIV')
  94. image.src = item.src
  95. info.innerHTML = item.text
  96. info.className = 'text'
  97. picframe.appendChild(image)
  98. picframe.className = 'pic-frame'
  99. // $(picframe).height(height-148)
  100. $(frame).css("height",height)
  101. $(frame).css("width",width)
  102. $(frame).css('overflow','hidden')
  103. frame.appendChild(picframe)
  104. frame.appendChild(info)
  105. pane.appendChild(frame)
  106. $(frame).width(width)
  107. $(frame).height(height)
  108. frame.className = 'slides left'
  109. })
  110. if(this.enable_auto){
  111. this.auto()
  112. }
  113. }