compass/doc-src/assets/javascripts/site.js

76 lines
1.7 KiB
JavaScript
Raw Normal View History

2010-11-23 06:09:18 +00:00
function changeTheme(theme) {
el = $('html');
if (!theme) theme = el.hasClass('dark') ? 'light': 'dark';
else if (el.hasClass(theme)) return;
el.removeClass('light');
el.removeClass('dark');
el.addClass(theme);
setThemePreference(theme);
}
function changeSyntax(syntax) {
2010-11-24 17:59:48 +00:00
el = $('html');
2010-11-23 06:09:18 +00:00
if (!syntax) {
syntax = el.hasClass('scss') ? 'sass': 'scss';
} else if (el.hasClass(syntax)) {
return;
}
el.removeClass('scss');
el.removeClass('sass');
el.addClass(syntax);
setSyntaxPreference(syntax);
}
function setThemePreference(theme) {
$.cookie("compass-theme", null);
$.cookie("compass-theme", theme, {
expires: 60 * 60 * 24 * 365 * 10,
path: '/'
});
}
function getThemePreference(defaultTheme) {
theme = $.cookie("compass-theme");
if (theme) {
changeTheme(theme);
} else {
changeTheme(defaultTheme);
}
}
function setSyntaxPreference(syntax) {
$.cookie("compass-syntax", null);
$.cookie("compass-syntax", syntax, {
expires: 60 * 60 * 24 * 365 * 10,
path: '/'
});
}
function getSyntaxPreference(defaultSyntax) {
syntax = $.cookie("compass-syntax");
if (syntax){
changeSyntax(syntax);
} else {
changeSyntax(defaultSyntax);
}
}
2010-11-24 17:59:48 +00:00
getThemePreference('dark');
getSyntaxPreference('scss');
2010-11-23 06:09:18 +00:00
$('document').ready(function(){
$('#page').click(function(event){
var target = $(event.target);
if (target.parent().is('#syntax_pref')) {
changeSyntax(target.attr("rel"));
event.preventDefault();
} else if (target.is('#theme_pref') || target.parent().is('#theme_pref')) {
changeTheme();
event.preventDefault();
} else if (target.attr("rel") == "view source") {
$(target.attr("href")).toggle();
event.preventDefault();
}
});
2010-11-24 23:43:25 +00:00
});