Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Writing a stylesheet switcher

  1. #1
    Join Date
    Aug 2009
    Location
    utf-8
    Posts
    205
    Thanks
    4
    Thanked 7 Times in 7 Posts

    Exclamation Writing a stylesheet switcher

    I found this stylesheet switcher here:
    http://www.jqueryscript.net/demo/Cha...itcher-Plugin/

    However I have spent the past few hours trying to turn the links from this
    Code:
    <a href="javascript: void(0)" data-theme="theme1">Default</a>
    To something like this
    Code:
    <a href="javascript: void(0)" id="theme1">Default</a>
    As well as changing the selection to a dropdown instead of a link, and a fade between the change of stylesheets. I know there is a stylesheet switcher hosted on this site, however it does not have what I am looking for
    Last edited by FrickenTrevor; 01-23-2015 at 10:20 PM.
    An inline div is a freak of the web and should be beaten until it becomes a span

  2. #2
    Join Date
    Aug 2009
    Location
    utf-8
    Posts
    205
    Thanks
    4
    Thanked 7 Times in 7 Posts

    Default

    Hello? Anyone?
    An inline div is a freak of the web and should be beaten until it becomes a span

  3. #3
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Is there any reason you need to change it from data-theme to id?
    If you take a quick look at the script they're demoing on that first page you'll see sections like this -
    Code:
    var asset = $(this).data('theme'),
    which is the part getting the data-theme attribute of the element. You could change each of these to something like var asset = $(this).attr("id"), I believe (untested)

    Not sure about changing it to a select. The script is designed to work on a tags only so you'd probably need to just rewrite it to accomodate for that.

    Fading between the sheets would be painful as you would have to clone the entire website with the old sheet and then switch it to the new sheet then fade between them. Is this the sort of thing you were talking about?

    Let me know if you need specific code examples or just one big example showing what you've asked for.

  4. #4
    Join Date
    Aug 2009
    Location
    utf-8
    Posts
    205
    Thanks
    4
    Thanked 7 Times in 7 Posts

    Default

    Quote Originally Posted by keyboard View Post
    Fading between the sheets would be painful as you would have to clone the entire website with the old sheet and then switch it to the new sheet then fade between them. Is this the sort of thing you were talking about?
    Let me know if you need specific code examples or just one big example showing what you've asked for.
    Yes it is, but I don't know how it would be "painful". I will look into the script and see what I can do to change it to work with a select tag instead of links, although I'm not the best at jQuery.
    An inline div is a freak of the web and should be beaten until it becomes a span

  5. #5
    Join Date
    Aug 2009
    Location
    utf-8
    Posts
    205
    Thanks
    4
    Thanked 7 Times in 7 Posts

    Default

    Quote Originally Posted by keyboard View Post

    Let me know if you need specific code examples or just one big example showing what you've asked for.
    Could I have the examples?
    An inline div is a freak of the web and should be beaten until it becomes a span

  6. #6
    Join Date
    Aug 2009
    Location
    utf-8
    Posts
    205
    Thanks
    4
    Thanked 7 Times in 7 Posts

    Default

    Bumping again so this thread doesn't get buried
    An inline div is a freak of the web and should be beaten until it becomes a span

  7. #7
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <link rel="stylesheet" title="default" href="theam1.css" type="text/css" />
    <style type="text/css">
    /*<![CDATA[*/
    
    .sheet1 {
      width:200px;height:200px;background-Color:red;
    }
    
    /*]]>*/
    </style>
    </head>
    
    <body>
    <div class="sheet1" ></div>
    <select onchange="SwapSheet('default',this.value);" >
     <option value="theam1.css" >theam1.css</option>
     <option value="theam2.css" >theam2.css</option>
     <option value="theam3.css" >theam3.css</option>
    </select>
    
    
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function SwapSheet(t,ns){
     var s=document.getElementsByTagName('LINK'),os,z0=0;;
     for (var os,z0=0;z0<s.length;z0++){
      if (s[z0].title==t){
       os=s[z0];
       break;
      }
     }
     if (os&&typeof(ns)=='string'){
      var s=os.cloneNode(false);
      s.href=ns;
      os.parentNode.appendChild(s);
      os.parentNode.removeChild(os);
     }
    }
    
    SwapSheet('default','theam3.css');
    /*]]>*/
    </script>
    </body>
    
    </html>

    theam1.css

    Code:
    .sheet1 {
      width:200px;height:200px;background-Color:red;
    }

    theam2.css

    Code:
    .sheet1 {
      width:200px;height:200px;background-Color:blue;
    }



    theam3.css

    Code:
    .sheet1 {
      width:200px;height:200px;background-Color:yellow;
    }
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  8. #8
    Join Date
    Aug 2009
    Location
    utf-8
    Posts
    205
    Thanks
    4
    Thanked 7 Times in 7 Posts

    Default

    Thanks, but I cant tell if the script remembers the users choice and the drop down is a little buggy. Not really sure how to fix it myself since the script looks a little complicated.
    An inline div is a freak of the web and should be beaten until it becomes a span

  9. #9
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    with persistance

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <link rel="stylesheet" title="default" href="theam1.css" type="text/css" />
    <style type="text/css">
    /*<![CDATA[*/
    
    .sheet1 {
      width:200px;height:200px;background-Color:red;
    }
    
    /*]]>*/
    </style>
    </head>
    
    <body>
    <div class="sheet1" ></div>
    <select id="s1" onchange="SwapSheet('default',this.value);" >
     <option value="theam1.css" >theam1.css</option>
     <option value="theam2.css" >theam2.css</option>
     <option value="theam3.css" >theam3.css</option>
    </select>
    
    
    
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function SwapSheet(t,ns,days){
     var s=document.getElementsByTagName('LINK'),os,z0=0;;
     for (var os,z0=0;z0<s.length;z0++){
      if (s[z0].title==t){
       os=s[z0];
       break;
      }
     }
     if (os&&typeof(ns)=='string'){
      var s=os.cloneNode(false);
      s.href=ns;
      os.parentNode.appendChild(s);
      os.parentNode.removeChild(os);
      days!=-1?document.cookie=t+'='+ns+(typeof(days)=='number'?';expires='+(new Date(new Date().getTime()+days*86400000).toGMTString())+';path/;':';'):null;
     }
    }
    
    
    function cookie(t,days,id){
     var re=new RegExp(t+'=[^;]+','i'),ns,s=document.getElementById(id),o,z0=0;
     ns=document.cookie.match(re)?document.cookie.match(re)[0].split("=")[1]:null;
     if (ns){
      SwapSheet(t,ns,days);
      if (s){
       o=s.options||[];
       for (;z0<o.length;z0++){
        if (o[z0].value==ns){
         s.selectedIndex=z0;
         break;
        }
       }
      }
     }
    }
    
    
    //parameter 0 = the style sheet title.
    //parameter 1 = the number of days to restore the last HREF.
    //parameter 2 = the unique ID name is the select element.
    cookie('default',1,'s1')
    /*]]>*/
    </script>
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  10. #10
    Join Date
    Aug 2009
    Location
    utf-8
    Posts
    205
    Thanks
    4
    Thanked 7 Times in 7 Posts

    Default

    Thanks! I still cant seem to figure out how to add the fade between stylesheets though.
    An inline div is a freak of the web and should be beaten until it becomes a span

Similar Threads

  1. StyleSheet Switcher - HELP!!!
    By muckel_buckel in forum MySQL and other databases
    Replies: 3
    Last Post: 12-14-2008, 05:52 PM
  2. Stylesheet switcher forgets the setting
    By Trupik in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 12-04-2007, 10:48 AM
  3. Stylesheet switcher w/Slashdot Menu
    By julmado in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 08-24-2007, 07:02 AM
  4. Stylesheet switcher (v1.1) not working?
    By CJ-real in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 04-09-2007, 12:51 PM
  5. Stylesheet Switcher
    By education in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 07-17-2006, 05:26 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •