- Noof http://www.noof.pun.pl/index.php - CSS http://www.noof.pun.pl/viewforum.php?id=1 - [CSS]Wybór stylu (skórki) z poziomu strony głównej http://www.noof.pun.pl/viewtopic.php?id=117 |
ffox - 2011-12-01 21:56:24 |
Wstęp: Kod:/** * @author Sławomir Kokłowski {@link http://www.kurshtml.edu.pl} * @copyright NIE usuwaj tego komentarza! (Do NOT remove this comment!) */ function Skin(name, expires, path, message) { this.expires = typeof expires != 'undefined' ? expires : 365; this.message = typeof message != 'undefined' ? message : 'Wymagana obsługa cookie'; this.name = typeof name != 'undefined' ? name : 'skin'; this.path = typeof path != 'undefined' ? path : '/'; var link = null; var original = ''; var css = ''; this.get = function() { if (css != '') return css; var matches = document.cookie.match(new RegExp('(^|;\\s*)' + this.name + '=([^;]*)')); if (matches && matches.length == 3) css = matches[2]; return css; } this.set = function(url) { document.cookie = this.name + '=' + url + (this.expires > 0 ? ';expires=' + new Date(new Date().getTime() + 86400000 * this.expires).toGMTString() : '') + ';path=' + this.path; css = url; if (this.message != '' && !navigator.cookieEnabled) window.alert(this.message); this.show(); } this.reset = function() { css = ''; document.cookie = this.name + '=;path=' + this.path; this.show(); } this.show = function() { var url = this.get(); if (url != '' || original != '') { if (link == null || original == '') { for (var i = 0; i < document.getElementsByTagName('link').length; i++) { if (document.getElementsByTagName('link')[i].getAttribute('rel').toLowerCase() == 'stylesheet') { link = document.getElementsByTagName('link')[i]; original = link.getAttribute('href'); break; } } } link.setAttribute('href', url != '' ? url : original); } } this.show(); } var skin = new Skin(); Zapisany plik skopiuj na serwer tak, aby był pod łatwo dostępnym adresem, np. w lokalizacji: http://mojserwer.pl/skins.js Kod:body {background: #FFFFFF;} #punwrap {background: #FFFFFF;} Plik 2 (alternatywny): skin2.css Kod:@import url('http://www.mojeforum.pun.pl/style/Test9.css'); body {background: #000000 !important;} #punwrap {background: #000000 !important;} Przygotowane skórki będą na bazie stylu Test9, a więc w drugim pliku .css (alternatywnym) należy pamiętać o koniecznym dodaniu kodu @import url('http://www.mojeforum.pun.pl/style/Test9.css');. Kod:<style type="text/css"> @import url('http://mojserwer.pl/skin1.css'); </style> Do ogłoszenia wklej to: Kod:<link rel="Stylesheet" type="text/css" href="http://mojserwer.pl/skin1.css" /> <script type="text/javascript" charset="iso-8859-2" src="http://mojserwer.pl/skins.js"></script> Wybierz motyw: <a href="javascript:void(0)" onclick="skin.reset(); return false">Skórka 1</a> | <a href="javascript:void(0)" onclick="skin.set('http://mojserwer.pl/skin2.css'); return false">Skórka 2</a> Takim oto sposobem, w ogłoszeniu pojawi nam się napis "Wybierz motyw: Skórka 1 | Skórka 2" z możliwością dostosowania wyglądu do swojego gustu. Kod:<link rel="Stylesheet" type="text/css" href="http://mojserwer.pl/skin1.css" /> <script type="text/javascript" charset="iso-8859-2" src="http://wrocek.hostit.pl/temp/e2140/skins.js"></script> Wybierz motyw: <a href="javascript:void(0)" onclick="skin.reset(); return false">Skórka 1</a> | <a href="javascript:void(0)" onclick="skin.set('http://mojserwer.pl/skin2.css'); return false">Skórka 2</a> | <a href="javascript:void(0)" onclick="skin.set('http://mojserwer.pl/skin3.css'); return false">Skórka 3</a> | <a href="javascript:void(0)" onclick="skin.set('http://mojserwer.pl/skin4.css'); return false">Skórka 4</a> Należy tylko pamiętać o przygotowaniu wcześniej odpowiednich pliczków .css. |