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

119 lines
3.3 KiB
JavaScript
Raw Permalink Normal View History

function changeTheme(theme, setCookie) {
2010-11-23 06:09:18 +00:00
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(style, setCookie){
2010-11-24 17:59:48 +00:00
el = $('html');
el.removeClass('scss'); el.removeClass('sass');
el.addClass(style);
setStyleSyntaxPreference(style);
}
2010-11-23 06:09:18 +00:00
function changeExampleStyleSyntax(style, setCookie){
el = $('html');
el.removeClass('scss'); el.removeClass('sass'); el.removeClass('css');
el.addClass(style);
setExampleStyleSyntaxPreference(style);
}
function changeExampleMarkupSyntax(markup){
el = $('html');
el.removeClass('haml'); el.removeClass('html');
el.addClass(markup);
setExampleMarkupSyntaxPreference(markup);
2010-11-23 06:09:18 +00:00
}
function setThemePreference(theme) {
$.cookie("compass-theme", null);
$.cookie("compass-theme", theme, {
expires: 60 * 60 * 24 * 365 * 10,
path: '/'
});
}
2010-11-23 06:09:18 +00:00
function getThemePreference(defaultTheme) {
theme = $.cookie("compass-theme");
if (theme) {
changeTheme(theme, false);
2010-11-23 06:09:18 +00:00
} else {
changeTheme(defaultTheme, true);
2010-11-23 06:09:18 +00:00
}
}
function setStyleSyntaxPreference (mainSyntax) {
2010-11-23 06:09:18 +00:00
$.cookie("compass-syntax", null);
$.cookie("compass-syntax", mainSyntax, { expires: 60 * 60 * 24 * 365 * 10, path: '/' });
2010-11-23 06:09:18 +00:00
}
function setExampleStyleSyntaxPreference (exampleStyle) {
$.cookie("compass-example-style", null);
$.cookie("compass-example-style", exampleStyle, { expires: 60 * 60 * 24 * 365 * 10, path: '/' });
}
function setExampleMarkupSyntaxPreference (exampleMarkup) {
$.cookie("compass-example-markup", null);
$.cookie("compass-example-markup", exampleMarkup, { expires: 60 * 60 * 24 * 365 * 10, path: '/' });
}
function getSyntaxPreference(defaultSyntax, defaultMarkup) {
mainSyntaxCookie = $.cookie("compass-syntax");
mainSyntax = (mainSyntaxCookie) ? mainSyntaxCookie : defaultSyntax;
changeSyntax(mainSyntax);
// add example styling preferences
if ($('body').hasClass('demo')){
markupCookie = $.cookie("compass-example-markup");
styleCookie = $.cookie("compass-example-style");
markup = (markupCookie) ? markupCookie : defaultMarkup;
style = (styleCookie) ? styleCookie : defaultSyntax;
changeExampleStyleSyntax(style)
changeExampleMarkupSyntax(markup);
2010-11-23 06:09:18 +00:00
}
}
2010-11-24 17:59:48 +00:00
getThemePreference('dark');
2010-11-23 06:09:18 +00:00
$('document').ready(function(){
getSyntaxPreference('scss', 'html');
2010-11-23 06:09:18 +00:00
$('#page').click(function(event){
var target = $(event.target);
// Set Main Syntax Preference
2010-11-23 06:09:18 +00:00
if (target.parent().is('#syntax_pref')) {
changeSyntax(target.attr("rel"), true);
event.preventDefault();
// Set Demo page syntax preferences
} else if (target.parent().is('.syntax_pref')) {
2010-11-23 06:09:18 +00:00
event.preventDefault();
if (target.parent().parent().is('#markup')) {
changeExampleMarkupSyntax(target.attr("rel"), true);
} else {
changeExampleStyleSyntax(target.attr("rel"), true);
}
// Set Theme preference
2010-11-23 06:09:18 +00:00
} else if (target.is('#theme_pref') || target.parent().is('#theme_pref')) {
changeTheme();
event.preventDefault();
2011-01-02 20:34:16 +00:00
// View source for mixins & functions
2010-11-23 06:09:18 +00:00
} else if (target.attr("rel") == "view source") {
$(target.attr("href")).toggle();
event.preventDefault();
}
});
});