home *** CD-ROM | disk | FTP | other *** search
/ CD Action 54 / cdactioncoverdisc54.iso / Bonus / rpg.exe / Tawerna_listopad / skrypty / przewijanie.js < prev    next >
Text File  |  2000-07-30  |  13KB  |  367 lines

  1. // Scroll Object
  2. // Copyright 1998 Dan Steinman
  3. // Available at the Dynamic Duo (http://www.dansteinman.com/dynduo/)
  4. // June 7, 1998.  Last Updated July 6, 1998.
  5. // In order to use this code you must keep this disclaimer
  6.  
  7. ns4 = (document.layers)? true:false
  8. ie4 = (document.all)? true:false
  9.  
  10. function Scroll(name,x,y,width,height) {
  11.     this.name = name
  12.     ScrollObjects[ScrollObjects.length] = this.name
  13.     this.x = x
  14.     this.y = y
  15.     this.w = width
  16.     this.h = height
  17.     this.url = null
  18.     this.loaded = false
  19.     this.refresh = false
  20.     this.active = false
  21.     this.mouseYnew = 0
  22.     this.mouseYold = 0
  23.     this.bar = new Object()
  24.     this.arrow = new Object()
  25.     this.arrow.active = false
  26.     this.box = new Object()
  27.     this.border = new Object()
  28.     this.images = false
  29.     this.visible = true
  30.     this.setH = false
  31.     this.history = new Array()
  32.     this.historyLoc = -1
  33.     this.historyLen = -1
  34.     this.css = ''
  35.     this.div = ''
  36.     this.visibility = null
  37.     this.zIndex = null
  38.     this.slideInc = 7
  39.     this.slideSpeed = 20
  40.     this.obj = name + "Object"
  41.     eval(this.obj + "=this")
  42.     this.setMargins = ScrollSetMargins
  43.     this.setMargins(10,10,10,10)
  44.     this.setDimensions = ScrollSetDimensions
  45.     this.setDimensions(15,15,30,1)
  46.     this.setColors = ScrollSetColors
  47.     this.setColors(null,"#000000","#C5C5C5","#555555","#898989")
  48.     this.setNestInfo = ScrollSetNestInfo
  49.     this.setNestInfo(null,0,0)
  50.     this.preload = ScrollPreload
  51.     this.setImages = ScrollSetImages
  52.     this.setImages()
  53.     this.setHeight = ScrollSetHeight
  54.     this.build = ScrollBuild
  55.     this.load = ScrollLoad
  56.     this.back = ScrollBack
  57.     this.forward = ScrollForward
  58.     this.reload = ScrollReload
  59.     this.activate = ScrollActivate
  60.     this.hide = ScrollHide
  61.     this.show = ScrollShow
  62.     this.jumpTop = ScrollJumpTop
  63.     this.jumpBottom = ScrollJumpBottom
  64.     this.mouseDown = ScrollMouseDown
  65.     this.mouseMove = ScrollMouseMove
  66.     this.mouseUp = ScrollMouseUp
  67.     this.slide = ScrollSlide
  68. }
  69. function ScrollSetDimensions(bar,arrow,box,border) {
  70.     this.bar.v = bar
  71.     this.arrow.v = arrow
  72.     this.box.v = box
  73.     this.border.v = border
  74.     this.bar.height = this.h-2*this.border.v-this.box.v-this.arrow.v
  75. }
  76. function ScrollSetColors(background,border,bar,arrow,box) {
  77.     this.bgcolor = background
  78.     this.border.color = border
  79.     this.bar.color = bar
  80.     this.arrow.color = arrow
  81.     this.box.color = box
  82. }
  83. function ScrollSetMargins(left,right,top,bottom) {
  84.     this.marginLeft = left
  85.     this.marginRight = right
  86.     this.marginTop = top
  87.     this.marginBottom = bottom
  88. }
  89. function ScrollPreload(imgObj,imgSrc) {
  90.     if (imgSrc!=null) {
  91.         eval(imgObj+' = new Image()')
  92.         eval(imgObj+'.src = "'+imgSrc+'"')
  93.         eval(imgObj+'s = true')
  94.     }
  95.     else eval(imgObj+'s = false')
  96. }
  97. function ScrollSetImages(box0,box1,arrowUp0,arrowUp1,arrowDn0,arrowDn1,bar,barHeight) {
  98.     this.preload(this.obj+'.box.image0',box0)
  99.     this.preload(this.obj+'.box.image1',box1)
  100.     this.preload(this.obj+'.arrow.upimage0',arrowUp0)
  101.     this.preload(this.obj+'.arrow.upimage1',arrowUp1)
  102.     this.preload(this.obj+'.arrow.dnimage0',arrowDn0)
  103.     this.preload(this.obj+'.arrow.dnimage1',arrowDn1)
  104.     this.preload(this.obj+'.bar.image',bar)
  105.     this.bar.imageH = barHeight
  106. }
  107. function ScrollSetNestInfo(nestref,x,y) {
  108.     if (ns4 && nestref) {
  109.         this.nestref = nestref
  110.         this.nest = nestref+'.document.'
  111.     }
  112.     else {
  113.         this.nestref = null
  114.         this.nest = ''
  115.     }
  116.     this.nestX = x
  117.     this.nestY = y
  118.     this.ref = this.nest+this.name+'Div.document.'+this.name+'TextCtr.document.'+this.name+'TextDiv'
  119. }
  120. function ScrollBuild() {
  121.     var nm = this.name
  122.     var b = this.border.v
  123.     var a = this.arrow.v
  124.     var br = this.bar.v
  125.     var bx = this.box.v
  126.     var ml = this.marginLeft
  127.     var mr = this.marginRight
  128.     var mt = this.marginTop
  129.     this.refX = this.x+b+ml
  130.     this.refY = this.y+b+mt
  131.     var pa = ' {position:absolute'
  132.     var l = '; left:'
  133.     var t = '; top:'
  134.     var w = '; width:'
  135.     var h = '; height:'
  136.     var c = '; clip:rect(0,'
  137.     var ec = ',0); '
  138.     var h2b = this.h-2*b
  139.     var ibc = 'background-color:'
  140.     var nbc = '; layer-background-color:'
  141.     var tw = ""+this.w-br-2*b-ml-mr
  142.     var bgc = (this.bgcolor!=null) ? ibc+this.bgcolor+nbc+this.bgcolor : ''
  143.     var bdc = (this.border.color!=null) ? ibc+this.border.color+nbc+this.border.color : ''
  144.     var barc = (this.bar.color!=null) ? ibc+this.bar.color+nbc+this.bar.color : ''
  145.     var boxc = (this.box.color!=null) ? ibc+this.box.color+nbc+this.box.color : ''
  146.     var arc = (this.arrow.color!=null) ? ibc+this.arrow.color+nbc+this.arrow.color : ''
  147.     end = ';}\n'
  148.     var vis = (this.visibility!=null)? '; visibility:'+this.visibility : ''
  149.     var z = (this.zIndex!=null)? '; z-index:'+this.zIndex : ''
  150.     this.css = '<STYLE TYPE="text/css">\n'+
  151.     '#'+nm+'Div'+pa+l+this.x+t+this.y+w+this.w+h+this.h+c+this.w+','+this.h+ec+bgc+vis+z+end+
  152.     '#'+nm+'BorderTop'+pa+w+this.w+h+b+c+this.w+','+b+ec+bdc+end+
  153.     '#'+nm+'BorderBottom'+pa+t+(this.h-b)+w+this.w+h+b+c+this.w+','+b+ec+bdc+end+
  154.     '#'+nm+'BorderLeft'+pa+w+b+h+this.h+c+b+','+this.h+ec+bdc+end+
  155.     '#'+nm+'BorderRight'+pa+l+(this.w-b)+w+b+h+this.h+c+b+','+this.h+ec+bdc+end+
  156.     '#'+nm+'BarDiv'+pa+l+(this.w-b-br)+t+b+w+br+h+h2b+c+br+','+h2b+ec+barc+'; visibility:hidden'+end+
  157.     '#'+nm+'BoxDiv'+pa+t+a+w+br+h+bx+c+br+','+bx+ec+boxc+end+
  158.     '#'+nm+'ArrowUpDiv'+pa+l+0+t+0+w+br+h+a+c+br+','+a+ec+arc+end+
  159.     '#'+nm+'ArrowDnDiv'+pa+l+0+t+(h2b-a)+w+br+h+a+c+br+','+a+ec+arc+end+
  160.     '#'+nm+'BarCover'+pa+l+0+t+0+w+br+h+h2b+c+br+','+h2b+ec+'}\n'+
  161.     '#'+nm+'TextCtr'+pa+l+(b+ml)+t+b+w+tw+h+h2b+c+tw+','+h2b+ec+'}\n'+
  162.     '#'+nm+'TextDiv'+pa+t+mt+w+tw+end+
  163.     '</STYLE>'
  164.     this.div = ''
  165.     if (ie4) this.div += '<IFRAME NAME="'+this.name+'Frame" WIDTH=0 HEIGHT=0 STYLE="display:none"></IFRAME>\n'
  166.     this.div += '<DIV ID="'+nm+'Div">\n'+
  167.     '<DIV ID="'+nm+'BarDiv">\n'
  168.     this.div += (this.bar.images)? '<IMG SRC="'+this.bar.image.src+'" WIDTH="'+this.bar.v+'" HEIGHT="'+this.bar.imageH+'">':''
  169.     this.div += '\n<DIV ID="'+nm+'BoxDiv">'
  170.     this.div += (this.box.image0s)? '<IMG NAME="'+nm+'BoxImg" SRC="'+this.box.image0.src+'">':''
  171.     this.div += '</DIV>\n<DIV ID="'+nm+'ArrowUpDiv">'
  172.     this.div += (this.arrow.upimage0s)? '<IMG NAME="'+nm+'ArrowUpImg" SRC="'+this.arrow.upimage0.src+'">':''
  173.     this.div += '</DIV>\n<DIV ID="'+nm+'ArrowDnDiv">'
  174.     this.div += (this.arrow.dnimage0s)? '<IMG NAME="'+nm+'ArrowDnImg" SRC="'+this.arrow.dnimage0.src+'">':''
  175.     this.div += '</DIV>\n'+
  176.     '<DIV ID="'+nm+'BarCover"></DIV>\n'+
  177.     '</DIV>\n'+
  178.     '<DIV ID="'+nm+'BorderTop"></DIV>\n'+
  179.     '<DIV ID="'+nm+'BorderBottom"></DIV>\n'+
  180.     '<DIV ID="'+nm+'BorderLeft"></DIV>\n'+
  181.     '<DIV ID="'+nm+'BorderRight"></DIV>\n'+
  182.     '<DIV ID="'+nm+'TextCtr">\n'+
  183.     '<DIV ID="'+nm+'TextDiv">\n'
  184.     this.divStart = this.div
  185.     this.divEnd = '</DIV></DIV></DIV>'
  186.     this.div += this.divEnd
  187.     document.write(this.css)
  188. }
  189. function ScrollLoad(url) {
  190.     if (url != this.url) {
  191.         this.historyLoc += 1
  192.         this.historyLen = this.historyLoc
  193.         this.history[this.historyLen] = url
  194.         this.reload()
  195.     }
  196. }
  197. function ScrollBack() {
  198.     if (this.historyLoc > 0) {
  199.         this.historyLoc -= 1
  200.         this.reload()
  201.     }
  202. }
  203. function ScrollForward() {
  204.     if (this.historyLoc < this.historyLen) {
  205.         this.historyLoc += 1
  206.         this.reload()
  207.     }
  208. }
  209. function ScrollReload() {
  210.     this.url = this.history[this.historyLoc]
  211.     this.refresh = true
  212.     if (ns4) eval('document.'+this.nest+this.name+'Div.document.'+this.name+'TextCtr.document.'+this.name+'TextDiv.src = "'+this.url+'"')
  213.     else if (ie4) parent.frames[this.name+'Frame'].document.location = this.url
  214. }
  215. ScrollObjects = new Array()
  216. function ScrollRefresh() {
  217.     for (var i=0;i<ScrollObjects.length;i++) {
  218.         if (eval(ScrollObjects[i]+".refresh")) {
  219.             eval(ScrollObjects[i]+".activate()")
  220.         }
  221.     }
  222. }
  223. function ScrollSetHeight(height) {
  224.     this.newHeight = height
  225.     this.setH = true
  226.     this.activate()
  227. }
  228. function ScrollActivate() {
  229.     if (this.refresh) {
  230.         this.refresh = false
  231.         if (ie4) document.all[this.name+'TextDiv'].innerHTML = parent.frames[this.name+'Frame'].document.body.innerHTML
  232.     }
  233.     this.lyr = new DynLayer(this.name+'Div',this.nestref)
  234.     this.textlyr = new DynLayer(this.name+'TextDiv',this.nest+this.name+'Div.document.'+this.name+'TextCtr')
  235.     this.boxlyr = new DynLayer(this.name+'BoxDiv',this.nest+this.name+'Div.document.'+this.name+'BarDiv')
  236.     this.arrowuplyr = new DynLayer(this.name+'ArrowUpDiv',this.nest+this.name+'Div.document.'+this.name+'BarDiv')
  237.     this.arrowdnlyr = new DynLayer(this.name+'ArrowDnDiv',this.nest+this.name+'Div.document.'+this.name+'BarDiv')
  238.     this.barlyr = new DynLayer(this.name+'BarDiv',this.nest+this.name+'Div')
  239.     if (ns4) {
  240.         this.textlyr.css.clip.right = this.w-this.bar.v-2*this.border.v-this.marginLeft-this.marginRight
  241.         if (!this.setH) {
  242.             this.textlyr.height = this.textlyr.doc.height
  243.             this.textlyr.css.clip.bottom = Math.max(this.textlyr.height,this.h-2*this.border.v-this.marginTop)
  244.         }
  245.         else {
  246.             this.textlyr.height = this.newHeight
  247.             this.textlyr.css.clip.bottom = this.newHeight
  248.             this.setH = false
  249.         }
  250.     }
  251.     else if (ie4) {
  252.         if (!this.setH) this.textlyr.height = document.all[this.name+"TextDiv"].scrollHeight
  253.         else {
  254.             this.textlyr.height = this.newHeight
  255.             this.setH = true
  256.         }
  257.     }
  258.     this.ratio = (this.textlyr.height+this.marginTop+this.marginBottom-this.h+2*this.border.v)/(this.bar.height-this.arrow.v)
  259.     this.jumpTop()
  260.     if (this.ratio>0) {
  261.         this.loaded = true
  262.         if (this.visibility!='hidden') this.barlyr.show()
  263.     }
  264.     else {
  265.         this.loaded = false
  266.         this.barlyr.hide()
  267.     }
  268. }
  269. function ScrollHide() {
  270.     this.visibility = 'hidden'
  271.     this.lyr.hide()
  272.     this.barlyr.hide()
  273. }
  274. function ScrollShow() {
  275.     this.visibility = 'visible'
  276.     this.lyr.show()
  277.     if (this.ratio>0) this.barlyr.show()
  278. }
  279. function ScrollJumpTop() {
  280.     this.boxlyr.moveTo(0,this.arrow.v)
  281.     this.textlyr.moveTo(0,this.marginTop)
  282. }
  283. function ScrollJumpBottom() {
  284.     this.boxlyr.moveTo(0,this.bar.height)
  285.     this.textlyr.moveTo(0,-this.ratio*(this.boxlyr.y-this.arrow.v)+this.marginTop)
  286. }
  287. function ScrollMouseDown(x,y) {
  288.     var b = this.border.v
  289.     var a = this.arrow.v
  290.     var br = this.bar.v
  291.     var bx = this.box.v
  292.     var xr = this.x+this.nestX
  293.     var yr = this.y+this.nestY
  294.     var brl = xr+this.w-b-br
  295.     if (this.ratio>0 && x>brl && x<brl+br && y>=yr+b && y<yr+this.h-b) {
  296.         var bxt = yr+b+this.boxlyr.y
  297.         if (y>=bxt && y<bxt+bx) {
  298.             if (this.box.image1s) this.boxlyr.doc.images[this.name+"BoxImg"].src = this.box.image1.src
  299.             this.clickYnew = y-this.boxlyr.y
  300.             this.clickYold = y
  301.             this.active = true
  302.         }            
  303.         else if (y<yr+b+a) {
  304.             if (this.arrow.upimage1s) this.arrowuplyr.doc.images[this.name+"ArrowUpImg"].src = this.arrow.upimage1.src
  305.             this.arrow.dir = 1
  306.             this.arrow.active = true
  307.             this.slide()
  308.         }
  309.         else if (y>=yr+this.h-b-a) {
  310.             if (this.arrow.dnimage1s) this.arrowdnlyr.doc.images[this.name+"ArrowDnImg"].src = this.arrow.dnimage1.src
  311.             this.arrow.dir = -1
  312.             this.arrow.active = true
  313.             this.slide()
  314.         }
  315.         else {
  316.             if (y<=yr+b+a+bx/2) this.boxlyr.moveTo(0,a)
  317.             else if (y>yr+this.h-b-a-bx/2) this.boxlyr.moveTo(0,this.bar.height)
  318.             else this.boxlyr.moveTo(0,y-this.y-this.nestY-b-bx/2)
  319.             if (this.box.image1s) this.boxlyr.doc.images[this.name+"BoxImg"].src = this.box.image1.src
  320.             this.textlyr.moveTo(0,-this.ratio*(this.boxlyr.y-a)+this.marginTop)
  321.             this.clickYnew = y-this.boxlyr.y
  322.             this.clickYold = y
  323.             this.active = true
  324.         }
  325.     }
  326. }
  327. function ScrollMouseUp() {
  328.     this.active = false
  329.     this.arrow.active = false
  330.     this.refY = this.y+this.border.v+Math.floor(this.textlyr.y)
  331.     if (this.box.image1s) this.boxlyr.doc.images[this.name+"BoxImg"].src = this.box.image0.src
  332.     if (this.arrow.upimage1s)this.arrowuplyr.doc.images[this.name+"ArrowUpImg"].src = this.arrow.upimage0.src
  333.     if (this.arrow.dnimage1s)this.arrowdnlyr.doc.images[this.name+"ArrowDnImg"].src = this.arrow.dnimage0.src
  334. }
  335. function ScrollMouseMove(x,y) {
  336.     if (!this.active) return
  337.     var diff = y-this.clickYold
  338.     var a = this.arrow.v
  339.     var bxy = this.boxlyr.y
  340.     var brh = this.bar.height
  341.     if ((bxy>a && bxy<brh) || (bxy==a && diff>=0) || (bxy==brh && diff<=0)) {
  342.         if ((bxy>a && bxy+diff<a) || (bxy<brh && bxy+diff>brh)) {
  343.             if (bxy+diff<a) this.boxlyr.moveTo(0,a)
  344.             else if (bxy+diff>brh) this.boxlyr.moveTo(0,brh)
  345.             this.clickYold = bxy+this.clickYnew
  346.         }
  347.         else {
  348.             this.boxlyr.moveTo(0,y-this.clickYnew)
  349.             this.clickYold = y
  350.         }
  351.         this.textlyr.moveTo(0,-this.ratio*(this.boxlyr.y-a)+this.marginTop)
  352.     }
  353. }
  354. function ScrollSlide() {
  355.     if (this.arrow.active) {
  356.         if ((this.arrow.dir==1 && this.textlyr.y<this.marginTop-this.slideInc) || (this.arrow.dir==-1 && this.textlyr.y>-(this.textlyr.height+2*this.border.v+this.marginBottom-this.h-this.slideInc))) {
  357.             this.textlyr.moveBy(0,this.arrow.dir*this.slideInc)
  358.             this.boxlyr.moveTo(0,(this.textlyr.y-this.marginTop)/-this.ratio+this.arrow.v)
  359.             setTimeout(this.obj+".slide()",this.slideSpeed)
  360.         }
  361.         else {
  362.             if (this.arrow.dir==1) this.textlyr.moveTo(0,this.marginTop)
  363.             else if (this.arrow.dir==-1) this.textlyr.moveTo(0,-(this.textlyr.height+2*this.border.v+this.marginBottom-this.h))
  364.             this.boxlyr.moveTo(0,(this.textlyr.y-this.marginTop)/-this.ratio+this.arrow.v)
  365.         }
  366.     }
  367. }