Skip to content

Commit 442dde3

Browse files
committed
added method to change stylesheet on air. For example if external script changes the stylesheet attribute, theme will be toggled
1 parent e9d06f5 commit 442dde3

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-gist",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"authors": [
55
"Dmitry Maslov <[email protected]>"
66
],

github-gist.html

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Polymer({
55
gistid: null,
66
stylesheet: null,
7+
defaultStylesheet: null,
78
styleEl: null,
89
gistEl: null,
910
scriptEl: null,
@@ -17,6 +18,12 @@
1718
this.loadJSON();
1819
},
1920

21+
stylesheetChanged: function(){
22+
//toggle themes without process response (if external script toggles stylesheet attribute)
23+
this.stylesheet = this.stylesheet || this.defaultStylesheet
24+
this.applyStyle(this.stylesheet);
25+
},
26+
2027
loadJSON: function(){
2128
var callbackFunc = callbackFuncName + '_' + callbackId++;
2229
window[callbackFunc] = function(object){
@@ -28,20 +35,19 @@
2835
},
2936

3037
processResponse: function(object){
31-
if(this.stylesheet !== null) {
32-
this.applyStyle(this.stylesheet);
33-
this.applyGist(object.div);
34-
}
35-
else if(object && object.div && object.stylesheet){
36-
if(object.stylesheet.indexOf('http') !== 0){
37-
if(object.stylesheet.indexOf('/') !== 0){
38-
object.stylesheet = '/' + object.stylesheet;
39-
}
40-
object.stylesheet = 'https://gist.github.com' + object.stylesheet;
41-
}
42-
this.applyStyle(object.stylesheet);
43-
this.applyGist(object.div);
38+
if(object && object.div && object.stylesheet){
39+
if(object.stylesheet.indexOf('http') !== 0){
40+
if(object.stylesheet.indexOf('/') !== 0){
41+
object.stylesheet = '/' + object.stylesheet;
42+
}
43+
object.stylesheet = 'https://gist.github.com' + object.stylesheet;
44+
}
45+
this.defaultStylesheet = object.stylesheet || null;
4446
}
47+
48+
this.stylesheet = this.stylesheet || this.defaultStylesheet;
49+
this.applyStyle(this.stylesheet);
50+
this.applyGist(object.div);
4551
},
4652

4753
applyGist: function(htmlString){

0 commit comments

Comments
 (0)