@@ -10,37 +10,27 @@ chrome.storage.sync.get(
10
10
mainContent . theme = localStorage . theme || 'light' ;
11
11
mainContent . fontPt = localStorage . fontPt || 14 ;
12
12
} ) ;
13
- mainContent . addEventListener ( 'template-bound ' , function ( ) {
13
+ mainContent . addEventListener ( 'dom-change ' , function ( ) {
14
14
//Set the font-size
15
- mainContent . ptChange ( ) ;
15
+ mainContent . ptChange ( { detail : mainContent . fontPt } ) ;
16
16
17
17
//Now that the template is bound update the code in the textArea
18
18
//mainContent.$.codeValue = mainContent.code;
19
19
//mainContent.$.agTa.update(mainContent.$.taCode); //Update the autoGrowArea;
20
20
21
- //Add a change listener to the textArea
22
- mainContent . $ . taCode . addEventListener ( 'input' , function ( ) {
23
- mainContent . code = mainContent . $ . taCode . value ;
24
- chrome . storage . sync . set ( { 'theCode' : mainContent . code } , function ( ) {
25
- //Nothing to do
26
- } ) ;
27
- //Code Changed, run the validation for slides
28
- mainContent . validateForSlides ( ) ;
29
- } ) ;
30
-
31
21
//Find the label of the selected language to set it on the paper-dropdown-menu
32
- var mnItems = document . querySelectorAll ( 'paper-item' ) ;
22
+ /* var mnItems = document.querySelectorAll('paper-item');
33
23
[].some.call(mnItems, function(mnItem) {
34
24
if (mnItem.dataset.value == mainContent.language) {
35
25
//Item found, update the selectedItem to change the label
36
26
mainContent.$.pdmLanguage.selectedItemLabel = mnItem.innerText;
37
27
return true;
38
28
}
39
29
return false;
40
- } ) ;
30
+ });*/
41
31
42
32
//Select the theme on the slider
43
- mainContent . $ . ptbTheme . checked = ( mainContent . theme == 'dark' ) ;
33
+ // mainContent.$.ptbTheme.checked = (mainContent.theme == 'dark');
44
34
45
35
//Set the theme and lang on all the components
46
36
setThemeAndLang ( ) ;
@@ -49,13 +39,33 @@ mainContent.addEventListener('template-bound', function() {
49
39
mainContent . validateForSlides ( ) ;
50
40
} ) ;
51
41
42
+ mainContent . _selTheme = function ( theme ) {
43
+ var tmpTheme = theme || 'light' ;
44
+
45
+ return ( tmpTheme == 'dark' ) ;
46
+
47
+ } ;
48
+
49
+ mainContent . codeChanged = function ( newVal ) {
50
+
51
+ chrome . storage . sync . set ( { 'theCode' : mainContent . code } , function ( ) {
52
+ //Nothing to do
53
+ } ) ;
54
+ //Code Changed, run the validation for slides
55
+ mainContent . validateForSlides ( ) ;
56
+
57
+ } ;
58
+
52
59
var setThemeAndLang = function ( ) {
53
60
//Change the classes on the prettyprint element accordingly
54
- document . body . className = 'theme-' + mainContent . theme ;
61
+ var tmpTheme = mainContent . theme || 'light' ;
62
+
63
+ document . body . className = 'theme-' + tmpTheme ;
55
64
56
- mainContent . $ . taCode . className = 'theme-' + mainContent . theme ;
65
+ // mainContent.$.taCode.className = 'theme-' + mainContent.theme;
57
66
58
- mainContent . $ . destination . className = 'theme-' + mainContent . theme ;
67
+ mainContent . $ . destination . className = 'flex theme-' + tmpTheme ;
68
+ Polymer . updateStyles ( ) ;
59
69
60
70
//Change the language class if needed
61
71
/*if (mainContent.lang != '--') {
@@ -97,62 +107,68 @@ var ptToPx = function(valPt) {
97
107
return ( 16 / 12 ) * valPt ; //return the font-size in px from the ptValue
98
108
} ;
99
109
100
- mainContent . ptChange = function ( ) {
101
- //TODO:Validate the value before saving it and using it to calculate the px value
102
-
103
- chrome . storage . sync . set ( { 'fontPt' : mainContent . fontPt } , function ( ) {
110
+ mainContent . ptChange = function ( newVal ) {
111
+
112
+ chrome . storage . sync . set ( { 'fontPt' : newVal . detail . value } , function ( ) {
104
113
//Nothing to do
105
114
} ) ;
106
115
107
116
//Get the px approximate size
108
- var fontPx = ptToPx ( mainContent . fontPt ) + 'px' ;
117
+ mainContent . fontPx = ptToPx ( newVal . detail . value ) + 'px' ;
109
118
110
119
//AutoGrow Text Area
111
- mainContent . $ . agTa . style . fontSize = fontPx ;
120
+ mainContent . $ . agTa . style . fontSize = mainContent . fontPx ;
112
121
//Text Area
113
- mainContent . $ . taCode . style . fontSize = fontPx ;
122
+ //mainContent.$.taCode.style.fontSize = fontPx;
123
+
114
124
//Pre Element
115
- var preElement = mainContent . $ . destination . shadowRoot . querySelector ( 'pre' ) ;
116
- preElement . style . fontSize = fontPx ;
125
+ if ( mainContent . $ . destination . shadowRoot ) {
126
+ var preElement = mainContent . $ . destination . shadowRoot . querySelector ( 'pre' ) ;
127
+ preElement . style . fontSize = mainContent . fontPx ;
128
+ Polymer . updateStyles ( ) ;
129
+ }
117
130
118
131
} ;
119
132
120
133
mainContent . selPrettyCode = function ( sender ) {
121
- //Get the pre element inside the prettyfy -element
122
- var preElement = sender . currentTarget . shadowRoot . querySelector ( 'pre' ) ;
123
-
124
- //Select the text range
125
- var doc = document ;
126
- var selection = window . getSelection ( ) ;
127
- var range = doc . createRange ( ) ;
128
- range . selectNodeContents ( preElement ) ;
129
- selection . removeAllRanges ( ) ;
130
- selection . addRange ( range ) ;
131
-
134
+ //Get the pre element inside the prettify -element
135
+ if ( mainContent . $ . destination . shadowRoot ) {
136
+ var preElement = mainContent . $ . destination . shadowRoot . querySelector ( 'pre' ) ;
137
+ //Select the text range
138
+ var doc = document ;
139
+ var selection = window . getSelection ( ) ;
140
+ var range = doc . createRange ( ) ;
141
+ range . selectNodeContents ( preElement ) ;
142
+ selection . removeAllRanges ( ) ;
143
+ selection . addRange ( range ) ;
144
+ }
132
145
} ;
133
146
134
147
mainContent . validateForSlides = function ( ) {
135
148
var divW = document . querySelector ( '#slidesWarnings' ) ;
136
- var warn = [ ] ;
137
-
138
- var MAX_LINES = 20 ;
139
- if ( ( mainContent . code . match ( / \n / g) || [ ] ) . length >= MAX_LINES ) {
140
- warn . push ( 'More than ' + MAX_LINES +
141
- ' lines of code will be hard to read on a slide.' ) ;
142
- }
143
-
144
- var lines = mainContent . code . split ( '\n' ) || [ ] ;
145
- var MAX_LINE_LENGTH = 80 ;
146
- for ( var i = 0 ; i < lines . length ; i ++ ) {
147
- if ( lines [ i ] . length > MAX_LINE_LENGTH ) {
148
- warn . push ( 'Line ' + ( i + 1 ) + ' has more than ' +
149
- MAX_LINE_LENGTH + ' characters!' ) ;
149
+
150
+ if ( divW ) {
151
+ var warn = [ ] ;
152
+
153
+ var MAX_LINES = 20 ;
154
+ if ( ( mainContent . code . match ( / \n / g) || [ ] ) . length >= MAX_LINES ) {
155
+ warn . push ( 'More than ' + MAX_LINES +
156
+ ' lines of code will be hard to read on a slide.' ) ;
157
+ }
158
+
159
+ var lines = mainContent . code . split ( '\n' ) || [ ] ;
160
+ var MAX_LINE_LENGTH = 80 ;
161
+ for ( var i = 0 ; i < lines . length ; i ++ ) {
162
+ if ( lines [ i ] . length > MAX_LINE_LENGTH ) {
163
+ warn . push ( 'Line ' + ( i + 1 ) + ' has more than ' +
164
+ MAX_LINE_LENGTH + ' characters!' ) ;
165
+ }
166
+ }
167
+ if ( warn . length > 0 ) {
168
+ divW . innerHTML = warn . join ( '<br>' ) ;
169
+ } else {
170
+ divW . innerHTML = 'Perfect code for slides' ;
150
171
}
151
- }
152
- if ( warn . length > 0 ) {
153
- divW . innerHTML = warn . join ( '<br>' ) ;
154
- } else {
155
- divW . innerHTML = 'Perfect code for slides' ;
156
172
}
157
173
} ;
158
174
0 commit comments