Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: Style Sheet Switcher (v1.1)

  1. #1
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Style Sheet Switcher (v1.1)

    anyone an idea why :: Style Sheet Switcher (v1.1) isnīt working on SAFARI since the Update 5.1 ???

    other browsers are working fine...
    tested versions: IE 9.0, FF 6.0, Safari 5.0, Opera 11.0

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,925
    Thanks
    43
    Thanked 3,187 Times in 3,151 Posts
    Blog Entries
    12

    Default

    It appears Safari 5.1 either cannot set a stylesheet's disabled property to false once it has been set to true and/or that it doesn't follow the standard for alternate stylesheets, or that standard doesn't require it to execute this script as expected.

    In any case, this update seems to fix it without harming others:

    Attachment 4030

    Demo:

    http://home.comcast.net/~jscheuer1/side/style_switch/
    Last edited by jscheuer1; 08-20-2011 at 03:51 PM. Reason: add demo
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Perfect! Works fine... thx

  4. #4
    Join Date
    Aug 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'm getting reports from folks with Macs that this fix doesn't work at all for them. So far reporting in: Safari 5.1 and Safari 5.0.6.

  5. #5
    Join Date
    Aug 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    and this be the website I'm using it on - using the randomize option.

    http://www.sacredfools.org

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,925
    Thanks
    43
    Thanked 3,187 Times in 3,151 Posts
    Blog Entries
    12

    Default

    That's right. This mod was for the non random use of the script. Using (in styleswitch.js):

    Code:
    var manual_or_random="random" //"manual" or "random"
    var randomsetting="eachtime" //"eachtime", "sessiononly", or "x days (replace x with desired integer)". Only applicable if mode is random.
    as I see you have, changes things.

    To fix it for that, find this line (around line #56 in the script):

    Code:
    altsheets[randomnumber].disabled=false
    Change it to:

    Code:
    setStylesheet(altsheets[randomnumber].title);
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Aug 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you! Now to wait for m'friends with Macs to wake up and test it.

  8. #8
    Join Date
    Aug 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hmmmm... no luck, apparently. I at first tried your change in the modified script, which just caused the whole site to hang. I then tried the change in the original script, but it had no effect for the Safari 5 folks.

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,925
    Thanks
    43
    Thanked 3,187 Times in 3,151 Posts
    Blog Entries
    12

    Default

    It would have no effect upon the original script. However, the latest update works fine here:

    http://home.comcast.net/~jscheuer1/s...m_eachtime.htm

    But I see that inserting it's code into your page does in fact cause an endless loop for some reason. Probably due to other scripts on the page. But it might be something else. I'll see if I can figure it out. I'll let you know either way.

    But we're in the midst of a serious hurricane here and may lose power. If we do, it may be out for some time. So it might be awhile before you see anything more from me on this.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,925
    Thanks
    43
    Thanked 3,187 Times in 3,151 Posts
    Blog Entries
    12

    Default

    That didn't take long. Um any reason why the page flies in the face of standards by having stylesheet links in the body?

    Anyways, it's a combination of that and what the updated script does that causes the endless loop.

    Unless you're willing and able to rectify that, use this version:

    Code:
    //Style Sheet Switcher version 1.1 Oct 10th, 2006
    //Author: Dynamic Drive: http://www.dynamicdrive.com
    //Usage terms: http://www.dynamicdrive.com/notice.htm
    
    //Unofficial Update to fix Safari 5.1 glitch re: alternate stylesheets or the disabled property in regards to them
    // See: http://www.dynamicdrive.com/forums/showthread.php?p=259199 for more info
    
    // IMPORTANT //
    //This version appends to the body instead of the head and is not recommended for general use!
    
    var manual_or_random="random" //"manual" or "random"
    var randomsetting="eachtime" //"eachtime", "sessiononly", or "x days (replace x with desired integer)". Only applicable if mode is random.
    
    //////No need to edit beyond here//////////////
    
    function getCookie(Name) { 
    var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
    if (document.cookie.match(re)) //if cookie found
    return document.cookie.match(re)[0].split("=")[1] //return its value
    return null
    }
    
    function setCookie(name, value, days) {
    var expireDate = new Date()
    //set "expstring" to either future or past date, to set or delete cookie, respectively
    var expstring=(typeof days!="undefined")? expireDate.setDate(expireDate.getDate()+parseInt(days)) : expireDate.setDate(expireDate.getDate()-5)
    document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
    }
    
    function deleteCookie(name){
    setCookie(name, "moot")
    }
    
    
    function setStylesheet(title, randomize){ //Main stylesheet switcher function. Second parameter if defined causes a random alternate stylesheet (including none) to be enabled
    var i, cacheobj, altsheets=[""];
    if(setStylesheet.chosen)
    try{
    document.body.removeChild(setStylesheet.chosen);
    }catch(e){}
    for(i=0; (cacheobj=document.getElementsByTagName("link")[i]); i++) {
    if(cacheobj.getAttribute("rel").toLowerCase()=="alternate stylesheet" && cacheobj.getAttribute("title")) { //if this is an alternate stylesheet with title
    cacheobj.disabled = true
    altsheets.push(cacheobj) //store reference to alt stylesheets inside array
    if(cacheobj.getAttribute("title") == title){ //enable alternate stylesheet with title that matches parameter
    cacheobj.disabled = false //enable chosen style sheet
    setStylesheet.chosen = document.createElement('link');//cloneNode(false);
    setStylesheet.chosen.rel = 'stylesheet';
    setStylesheet.chosen.type = 'text/css';
    if(cacheobj.media)
    setStylesheet.chosen.media = cacheobj.media;
    setStylesheet.chosen.href = cacheobj.href;
    document.body.appendChild(setStylesheet.chosen);
    }
    }
    }
    if (typeof randomize!="undefined"){ //if second paramter is defined, randomly enable an alt style sheet (includes non)
    var randomnumber=Math.floor(Math.random()*altsheets.length)
    setStylesheet((selectedtitle = altsheets[randomnumber].title));
    //altsheets[randomnumber].disabled=false
    }
    return (typeof randomize!="undefined" && altsheets[randomnumber]!="")? altsheets[randomnumber].getAttribute("title") : "" //if in "random" mode, return "title" of randomly enabled alt stylesheet
    }
    
    
    
    function chooseStyle(styletitle, days){ //Interface function to switch style sheets plus save "title" attr of selected stylesheet to cookie
    if (document.getElementById){
    setStylesheet(styletitle)
    setCookie("mysheet", styletitle, days)
    }
    }
    
    function indicateSelected(element){ //Optional function that shows which style sheet is currently selected within group of radio buttons or select menu
    if (selectedtitle!=null && (element.type==undefined || element.type=="select-one")){ //if element is a radio button or select menu
    var element=(element.type=="select-one") ? element.options : element
    for (var i=0; i<element.length; i++){
    if (element[i].value==selectedtitle){ //if match found between form element value and cookie value
    if (element[i].tagName=="OPTION") //if this is a select menu
    element[i].selected=true
    else{ //else if it's a radio button
    element[i].checked=true
    }
    break
    }
    }
    }
    }
    
    if (manual_or_random=="manual"){ //IF MANUAL MODE
    var selectedtitle=getCookie("mysheet")
    if (document.getElementById && selectedtitle!=null) //load user chosen style sheet from cookie if there is one stored
    setStylesheet(selectedtitle)
    }
    else if (manual_or_random=="random"){ //IF AUTO RANDOM MODE
    if (randomsetting=="eachtime")
    setStylesheet("", "random")
    else if (randomsetting=="sessiononly"){ //if "sessiononly" setting
    if (getCookie("mysheet_s")==null) //if "mysheet_s" session cookie is empty
    document.cookie="mysheet_s="+setStylesheet("", "random")+"; path=/" //activate random alt stylesheet while remembering its "title" value
    else
    setStylesheet(getCookie("mysheet_s")) //just activate random alt stylesheet stored in cookie
    }
    else if (randomsetting.search(/^[1-9]+ days/i)!=-1){ //if "x days" setting
    if (getCookie("mysheet_r")==null || parseInt(getCookie("mysheet_r_days"))!=parseInt(randomsetting)){ //if "mysheet_r" cookie is empty or admin has changed number of days to persist in "x days" variable
    setCookie("mysheet_r", setStylesheet("", "random"), parseInt(randomsetting)) //activate random alt stylesheet while remembering its "title" value
    setCookie("mysheet_r_days", randomsetting, parseInt(randomsetting)) //Also remember the number of days to persist per the "x days" variable
    }
    else
    setStylesheet(getCookie("mysheet_r")) //just activate random alt stylesheet stored in cookie
    } 
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •