[英]Theme doesn't work on dojo's website?
http://demos.dojotoolkit.org/demos/themePreviewer/demo.html在此主題預覽器中,無論我如何更改主題,都不會發生任何事情。 此外,在參考指南的任何示例中,當我嘗試運行它們時,它們看起來完全沒有樣式,就像沒有CSS一樣。 我嘗試了其他瀏覽器,都一樣。 盡管它在我的項目中效果很好,但我想知道哪里出了問題。
我無法想象它會成功。 我看了看源代碼,它似乎並沒有嘗試更改CSS位置或主體上的類名(都需要更改主題)。
似乎唯一發生的是?theme=
查詢參數僅用於定義應顯示為鏈接的主題。 但這甚至是錯誤的。 他們定義如下主題:
var availableThemes = [
{ theme: "claro", author: "Dojo", baseUri: "../themes/" },
{ theme: "tundra", author: "Dojo", baseUri: "../themes/" },
{ theme: "soria", author: "nikolai", baseUri: "../themes/" },
{ theme: "nihilo", author: "nikolai", baseUri: "../themes/" }
];
然后他們像這樣加載當前主題:
var curTheme = location.search.replace(/.*theme=([a-z]+).*/, "$1") || "claro";
然后,他們嘗試加載正確的菜單選項:
var tmpString = '';
array.forEach(availableThemes, function(theme){
if(theme != curTheme){
tmpString +=
'<a href="?theme=' + theme.theme + '">' + theme.theme + '</' + 'a> (' +
'<a href="?theme=' + theme.theme + '&dir=rtl">RTL</' + 'a> ' +
'<a href="?theme=' + theme.theme + '&a11y=true">high-contrast</' + 'a> ' +
'<a href="?theme=' + theme.theme + '&dir=rtl&a11y=true">RTL+high-contrast</' + 'a> )' +
' - by: ' + theme.author + ' <br>';
}
});
但是正如您所看到的,他們正在將對象與字符串( theme != curTheme
)進行比較,這將永遠行不通。 因此,該代碼似乎是錯誤的,所以我認為您不能依靠它。 我建議打開一張票以報告此問題。
如果您對其他主題的外觀感興趣,可以打開DevTools並更改CSS文件(應替換../../dijit/themes/claro/claro.css
),然后更改<body>
標簽上的類名。
或者,您可以只在瀏覽器的控制台中執行以下代碼:
(function() {
var curTheme = location.search.replace(/.*theme=([a-z]+).*/, "$1") || "claro",
newStyle = document.createElement("link"),
styleSheets = document.styleSheets;
newStyle.setAttribute("rel", "stylesheet");
newStyle.setAttribute("type", "text/css");
for (var idx = 0; idx < styleSheets.length; idx++) {
if (styleSheets[idx].href.indexOf("claro.css") >= 0) {
newStyle.setAttribute("href", styleSheets[idx].href.replace(/claro/g, curTheme));
}
}
document.getElementsByTagName("head")[0].appendChild(newStyle);
document.body.className = curTheme;
}());
請改用Dijit主題測試儀 ,它位於themes文件夾下的Dijit包中。
您可能會認為它看起來幾乎相同。 有點是-demos文件夾下的themePreviewer在某種程度上已經從其中復制了一半,但是不幸的是,它從未完全工作過,AFAIK。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.