За последние 24 часа нас посетили 42575 программистов и 1814 роботов. Сейчас ищут 1509 программистов ...

Помогите разобраться !

Тема в разделе "JavaScript и AJAX", создана пользователем lemonl, 26 мар 2011.

  1. lemonl

    lemonl Активный пользователь

    С нами с:
    10 июн 2009
    Сообщения:
    164
    Симпатии:
    0
    Здравствуйте,


    Помогите пожалуйста разобраться с показом контента ...

    [​IMG]


    У меня есть вкладка Год (2011, 2010) и Тип

    Мне нужно что бы когда я нажимаю на год у меня появлялся контент данного года, а также Тип того же года индикатор и диаграм ... так как на картинке ...[/img] так что бы можно было по этим вкладкам доступиться до той или иной информации....


    Ниже пример кода как я сделал когда я нажимаю на год у меня появлялся контент данного года ....
    И нужно еще что бы год взаимодействовал с типом (Type: indicator diagram )

    Код (Text):
    1.  
    2.  
    3. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    4. <html dir="LTR" lang="en">
    5. <head>
    6.     <meta http-equiv="Content-Type" content="text/html; charset=Unicode">
    7.     <title>SAMPLE</title>
    8.     <script>
    9.    
    10. function ddtabcontent(tabinterfaceid){
    11.     this.tabinterfaceid=tabinterfaceid //ID of Tab Menu main container
    12.     this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a") //Get all tab links within container
    13.     this.enabletabpersistence=true
    14.     this.hottabspositions=[] //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container
    15.     this.currentTabIndex=0 //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array
    16.     this.subcontentids=[] //Array to store ids of the sub contents ("rel" attr values)
    17.     this.revcontentids=[] //Array to store ids of arbitrary contents to expand/contact as well ("rev" attr values)
    18.     this.selectedClassTarget="link" //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link")
    19. }
    20.  
    21. ddtabcontent.getCookie=function(Name){
    22.     var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
    23.     if (document.cookie.match(re)) //if cookie found
    24.         return document.cookie.match(re)[0].split("=")[1] //return its value
    25.     return ""
    26. }
    27.  
    28. ddtabcontent.setCookie=function(name, value){
    29.     document.cookie = name+"="+value+";path=/" //cookie value is domain wide (path=/)
    30. }
    31.  
    32. ddtabcontent.prototype={
    33.  
    34.     expandit:function(tabid_or_position){ //PUBLIC function to select a tab either by its ID or position(int) within its peers
    35.         this.cancelautorun() //stop auto cycling of tabs (if running)
    36.         var tabref=""
    37.         try{
    38.             if (typeof tabid_or_position=="string" && document.getElementById(tabid_or_position).getAttribute("rel")) //if specified tab contains "rel" attr
    39.                 tabref=document.getElementById(tabid_or_position)
    40.             else if (parseInt(tabid_or_position)!=NaN && this.tabs[tabid_or_position].getAttribute("rel")) //if specified tab contains "rel" attr
    41.                 tabref=this.tabs[tabid_or_position]
    42.         }
    43.         catch(err){alert("Invalid Tab ID or position entered!")}
    44.         if (tabref!="") //if a valid tab is found based on function parameter
    45.             this.expandtab(tabref) //expand this tab
    46.     },
    47.  
    48.     cycleit:function(dir, autorun){ //PUBLIC function to move foward or backwards through each hot tab (tabinstance.cycleit('foward/back') )
    49.         if (dir=="next"){
    50.             var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0
    51.         }
    52.         else if (dir=="prev"){
    53.             var currentTabIndex=(this.currentTabIndex>0)? this.currentTabIndex-1 : this.hottabspositions.length-1
    54.         }
    55.         if (typeof autorun=="undefined") //if cycleit() is being called by user, versus autorun() function
    56.             this.cancelautorun() //stop auto cycling of tabs (if running)
    57.         this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])
    58.     },
    59.  
    60.     setpersist:function(bool){ //PUBLIC function to toggle persistence feature
    61.             this.enabletabpersistence=bool
    62.     },
    63.  
    64.     setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")
    65.         this.selectedClassTarget=objstr || "link"
    66.     },
    67.  
    68.     getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to
    69.         return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref
    70.     },
    71.  
    72.     urlparamselect:function(tabinterfaceid){
    73.         var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)", "i")) //check for "?tabinterfaceid=2" in URL
    74.         return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
    75.     },
    76.  
    77.     expandtab:function(tabref){
    78.         var subcontentid=tabref.getAttribute("rel") //Get id of subcontent to expand
    79.         //Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easily search through
    80.         var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : ""
    81.         this.expandsubcontent(subcontentid)
    82.         this.expandrevcontent(associatedrevids)
    83.         for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"
    84.             this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("rel")==subcontentid)? "selected" : ""
    85.         }
    86.         if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers
    87.             ddtabcontent.setCookie(this.tabinterfaceid, tabref.tabposition)
    88.         this.setcurrenttabindex(tabref.tabposition) //remember position of selected tab within hottabspositions[] array
    89.     },
    90.  
    91.     expandsubcontent:function(subcontentid){
    92.         for (var i=0; i<this.subcontentids.length; i++){
    93.             var subcontent=document.getElementById(this.subcontentids[i]) //cache current subcontent obj (in for loop)
    94.             subcontent.style.display=(subcontent.id==subcontentid)? "block" : "none" //"show" or hide sub content based on matching id attr value
    95.         }
    96.     },
    97.  
    98.     expandrevcontent:function(associatedrevids){
    99.         var allrevids=this.revcontentids
    100.         for (var i=0; i<allrevids.length; i++){ //Loop through rev attributes for all tabs in this tab interface
    101.             //if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it
    102.             document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none"
    103.         }
    104.     },
    105.  
    106.     setcurrenttabindex:function(tabposition){ //store current position of tab (within hottabspositions[] array)
    107.         for (var i=0; i<this.hottabspositions.length; i++){
    108.             if (tabposition==this.hottabspositions[i]){
    109.                 this.currentTabIndex=i
    110.                 break
    111.             }
    112.         }
    113.     },
    114.  
    115.     autorun:function(){ //function to auto cycle through and select tabs based on a set interval
    116.         this.cycleit('next', true)
    117.     },
    118.  
    119.     cancelautorun:function(){
    120.         if (typeof this.autoruntimer!="undefined")
    121.             clearInterval(this.autoruntimer)
    122.     },
    123.  
    124.     init:function(automodeperiod){
    125.         var persistedtab=ddtabcontent.getCookie(this.tabinterfaceid) //get position of persisted tab (applicable if persistence is enabled)
    126.         var selectedtab=-1 //Currently selected tab index (-1 meaning none)
    127.         var selectedtabfromurl=this.urlparamselect(this.tabinterfaceid) //returns null or index from: tabcontent.htm?tabinterfaceid=index
    128.         this.automodeperiod=automodeperiod || 0
    129.         for (var i=0; i<this.tabs.length; i++){
    130.             this.tabs[i].tabposition=i //remember position of tab relative to its peers
    131.             if (this.tabs[i].getAttribute("rel")){
    132.                 var tabinstance=this
    133.                 this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers
    134.                 this.subcontentids[this.subcontentids.length]=this.tabs[i].getAttribute("rel") //store id of sub content ("rel" attr value)
    135.                 this.tabs[i].onclick=function(){
    136.                     tabinstance.expandtab(this)
    137.                     tabinstance.cancelautorun() //stop auto cycling of tabs (if running)
    138.                     return false
    139.                 }
    140.                 if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each value within "rev" as an array element
    141.                     this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))
    142.                 }
    143.                 if (selectedtabfromurl==i || this.enabletabpersistence && selectedtab==-1 && parseInt(persistedtab)==i || !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
    144.                     selectedtab=i //Selected tab index, if found
    145.                 }
    146.             }
    147.         } //END for loop
    148.         if (selectedtab!=-1) //if a valid default selected tab index is found
    149.             this.expandtab(this.tabs[selectedtab]) //expand selected tab (either from URL parameter, persistent feature, or class="selected" class)
    150.         else //if no valid default selected index found
    151.             this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr
    152.         if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){
    153.             this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)
    154.         }
    155.     } //END int() function
    156.  
    157. } //END Prototype assignment
    158.    
    159.     </script>
    160.  
    161.  
    162.  
    163. </head>
    164.  
    165. <body>
    166.  
    167.  
    168. <div id="flowernote" style="display:none; position:absolute; right: 30px; width:150px; height:150px; background-color:red; color:white">
    169. Arbitrary DIV 1
    170. </div>
    171.  
    172. <div id="flowernote2" style="display:none; right: 200px; width:80px; height:80px; background-color:black; color:white">
    173. Arbitrary DIV 2
    174. </div>
    175.  
    176. <div id="flowernote3" style="display:none; position:absolute; right: 30px; width:140px; height:140px; background-color:navy; color:white">
    177. Arbitrary DIV 3
    178. </div>
    179.  
    180. <style>
    181.  
    182. .shadetabs li a{
    183. color: #fff;
    184. background: #777;
    185. }
    186.  
    187. .shadetabs li a:visited{
    188. color: #fff;
    189. }
    190.  
    191. .shadetabs li a:hover{
    192. text-decoration: underline;
    193. color: #2d2b2b;
    194. }
    195.  
    196. .shadetabs li a.selected{
    197. background: red;
    198.  
    199. }
    200.  
    201.  
    202. </style>
    203.  
    204. <ul id="flowertabs" class="shadetabs">
    205. <li>год</li>
    206. <li><a href="#" rel="tcontent1" class="selected">2011</a></li>
    207. <li><a href="#" rel="tcontent2">2010</a></li>
    208. <li>-----------------------------------------------------</li>
    209.  
    210. </ul>
    211.  
    212. <div style="border:1px solid gray; width:450px; margin-bottom: 1em; padding: 10px">
    213.  
    214. <div id="tcontent1" class="tabcontent">
    215. Контент за 2011 год
    216. </div>
    217.  
    218. <div id="tcontent2" class="tabcontent">
    219. Контент за 2010 год
    220. </div>
    221.  
    222.  
    223. </div>
    224.  
    225. <script type="text/javascript">
    226.  
    227. var myflowers=new ddtabcontent("flowertabs")
    228. myflowers.setpersist(true)
    229. myflowers.setselectedClassTarget("link") //"link" or "linkparent"
    230. myflowers.init()
    231.  
    232. </script>
    233.  
    234.  
    235. </body>
    236. </html>