[Plone-IT] [Fwd: [Plone-Users] style switcher]

Yuri yurj a alfa.it
Gio 8 Apr 2010 12:26:11 UTC


Gio anche a voi, sicuramente avrete affrontato la questione...

su italian skin ho trovato questo:


<?xml version="1.0"?>
<object name="portal_css">

 <stylesheet title="Plone Default (contrast improved)"
    id="italianskin.css"
    media="screen" rel="stylesheet" rendering="import"
    cacheable="True" compression="safe" cookable="True"
    enabled="1" expression=""/>
 <stylesheet title="high contrast (background black)"
    id="highcontrast.css"
    media="screen" rel="stylesheet" rendering="import"
    cacheable="True" compression="safe" cookable="True"
    enabled="1" expression=""/>
 <stylesheet title="high contrast (background black and padding/fonts 
modified)"
    id="highcontrast_padding.css"
    media="screen" rel="stylesheet" rendering="import"
    cacheable="True" compression="safe" cookable="True"
    enabled="1" expression=""/>

</object>

perņ non ho ben capito qual č il javascript che agisce, potete 
indicarmelo? Grazie :)
-------- Messaggio Originale --------
Oggetto: 	[Plone-Users] style switcher
Data: 	Wed, 07 Apr 2010 17:30:35 +0200
Da: 	Yuri <yurj a alfa.it>
A: 	Plone Users List <plone-users a lists.sourceforge.net>



Hi!

 what is the status of plone in style switching? I had to hack various 
part to make it work. There's a minimal styleswitcher.js in plone but 
seems not to work:

/* - styleswitcher.js - */
3// StyleSwitcher functions written by Paul Sowden
4function setActiveStyleSheet(title, reset) {
5 jq('link[rel*=style][title]').attr('disabled', true)
6 .find('[title=' + title + ']').attr('disabled', false);
7 if (reset) createCookie("wstyle", title, 365);
8};
9
10jq(function() {
11 var style = readCookie("wstyle");
12 if (style != null) setActiveStyleSheet(style, 0);
13});
14

a more complete one taken from internet(*) seems to work, I think because:

jq('link[rel*=style][title]').attr('disabled', true)
  .find('[title=' + title + ']').attr('disabled', false); <- this second 
part does not change disabled.

fail to find the stylesheets:


<link rel="stylesheet" type="text/css" href="nonesiste.css" 
title="resetta" />
<link rel="alternative stylesheet" type="text/css" 
href="hiviz-light.css" title="hiviz-light" />
<link rel="alternative stylesheet" type="text/css" href="hiviz-dark.css" 
title="hiviz-dark" />

while:

 for(i=0;(a = document.getElementsByTagName("link")[i]);i++) {
  if(a.getAttribute("rel").indexOf("style") != -1 && 
a.getAttribute("title")) {
  a.disabled = true;
  if(a.getAttribute("title") == title) a.disabled = false;

works.

The cookie is set ok, It changes from hiviz-light to hiviz-dark  and back.

Any idea? :)



(*)
// STYLESWITCHER
// http://alistapart.com/stories/alternate/

function setActiveStyleSheet(title) {
 var i, a, main;
 for(i=0;(a = document.getElementsByTagName("link")[i]);i++) {
 if(a.getAttribute("rel").indexOf("style") != -1 && 
a.getAttribute("title")) {
 a.disabled = true;
 if(a.getAttribute("title") == title) a.disabled = false;
 }
 }
}

function getActiveStyleSheet() {
 var i, a;
 for(i=0;(a = document.getElementsByTagName("link")[i]);i++) {
 if(a.getAttribute("rel").indexOf("style") != -1 && 
a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
 }
 return null;
}

function getPreferredStyleSheet() {
 var i, a;
 for(i=0;(a = document.getElementsByTagName("link")[i]);i++) {
 if(a.getAttribute("rel").indexOf("style") != -1
 && a.getAttribute("rel").indexOf("alt") == -1
 && a.getAttribute("title")
 ) return a.getAttribute("title");
 }
 return null;
}

function createCookie(name,value,days) {
 if (days) {
 var date = new Date();
 date.setTime(date.getTime()+(days*24*60*60*1000));
 var expires = "; expires="+date.toGMTString();
 }
 else expires = "";
 document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
 var nameEQ = name + "=";
 var ca = document.cookie.split(';');
 for(var i=0;i < ca.length;i++) {
 var c = ca[i];
 while (c.charAt(0)==' ') c = c.substring(1,c.length);
 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
 }
 return null;
}

window.onload = function(e) {
 var cookie = readCookie("style");
 var title = cookie ? cookie : getPreferredStyleSheet();
 setActiveStyleSheet(title);
}

window.onunload = function(e) {
 var title = getActiveStyleSheet();
 createCookie("style", title, 0);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

function eraseCookie(name) {
 createCookie(name,"",-1);
}


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Plone-Users mailing list
Plone-Users a lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plone-users





Maggiori informazioni sulla lista Plone-IT