web - How to change the html body Theme using Kendo ui html5 -
i'm new use kendoui, html 5 web , have create 1 small demo app in html 5,in need change theme dynamically , means when select color combo-box or drop-down should apply entire page. searched in google did not right solution , please guide me how .
here code fallow sample .
<!doctype html> <html> <head> <title></title> <link href="content/kendo/2013.2.716/kendo.common.min.css" rel="stylesheet" type="text/css" /> <link href="content/kendo/2013.2.716/kendo.default.min.css" rel="stylesheet" typ e="text/css" /> <script src="scripts/kendo/2013.2.716/jquery.min.js" type="text/javascript"></script> <script src="scripts/kendo/2013.2.716/kendo.all.min.js" type="text/javascript"></script> <style> html, body { margin: 0; padding: 0; } body { font: 12px/1.5 tahoma,sans-serif; padding: 2em; } span.themechooser { float: right; } #tree { height: 9em; } </style> </head> <body class="k-content"> <div id="example" class="k-content"> <input class="themechooser" value="default" /> <div id="tree"> </div> <p> note: in order whole page styled, <body> element has <code> k-content</code> class.</p> </div> <script> $(function () { $("#themechooser").kendodropdownlist({ datasource: [ { text: "black", value: "black" }, { text: "blue opal", value: "blueopal" }, { text: "default", value: "default" }, { text: "metro", value: "metro" }, { text: "silver", value: "silver" } ], change: function (e) { var theme = (this.value() || "default").tolowercase(); changetheme(theme); } }); // sample widget on page $("#tree").kendotreeview({ datasource: [ { text: "foo", expanded: true, items: [ { text: "bar", selected: true } ] }, { text: "baz" } ] }); // loads new stylesheet function changetheme(skinname, animate) { var doc = document, kendolinks = $("link[href*='kendo.']", doc.getelementsbytagname("head")[0]), commonlink = kendolinks.filter("[href*='kendo.common']"), skinlink = kendolinks.filter(":not([href*='kendo.common'])"), href = location.href, skinregex = /kendo\.\w+(\.min)?\.css/i, extension = skinlink.attr("rel") === "stylesheet" ? ".css" : ".less", url = commonlink.attr("href").replace(skinregex, "kendo." + skinname + "$1" + extension), exampleelement = $("#example"); function preloadstylesheet(file, callback) { var element = $("<link rel='stylesheet' media='print' href='" + file + "'").appendto("head"); settimeout(function () { callback(); element.remove(); }, 100); } function replacetheme() { var oldskinname = $(doc).data("kendoskin"), newlink; if ($.browser.msie) { newlink = doc.createstylesheet(url); } else { newlink = skinlink.eq(0).clone().attr("href", url); } newlink.insertbefore(skinlink[0]); skinlink.remove(); $(doc.documentelement).removeclass("k-" + oldskinname).addclass("k-" + skinname); } if (animate) { preloadstylesheet(url, replacetheme); } else { replacetheme(); } } }); </script>
thank .
Comments
Post a Comment