@@ -10,37 +10,27 @@ chrome.storage.sync.get(
1010 mainContent . theme = localStorage . theme || 'light' ;
1111 mainContent . fontPt = localStorage . fontPt || 14 ;
1212 } ) ;
13- mainContent . addEventListener ( 'template-bound ' , function ( ) {
13+ mainContent . addEventListener ( 'dom-change ' , function ( ) {
1414 //Set the font-size
15- mainContent . ptChange ( ) ;
15+ mainContent . ptChange ( { detail : mainContent . fontPt } ) ;
1616
1717 //Now that the template is bound update the code in the textArea
1818 //mainContent.$.codeValue = mainContent.code;
1919 //mainContent.$.agTa.update(mainContent.$.taCode); //Update the autoGrowArea;
2020
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-
3121 //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');
3323 [].some.call(mnItems, function(mnItem) {
3424 if (mnItem.dataset.value == mainContent.language) {
3525 //Item found, update the selectedItem to change the label
3626 mainContent.$.pdmLanguage.selectedItemLabel = mnItem.innerText;
3727 return true;
3828 }
3929 return false;
40- } ) ;
30+ });*/
4131
4232 //Select the theme on the slider
43- mainContent . $ . ptbTheme . checked = ( mainContent . theme == 'dark' ) ;
33+ // mainContent.$.ptbTheme.checked = (mainContent.theme == 'dark');
4434
4535 //Set the theme and lang on all the components
4636 setThemeAndLang ( ) ;
@@ -49,13 +39,33 @@ mainContent.addEventListener('template-bound', function() {
4939 mainContent . validateForSlides ( ) ;
5040} ) ;
5141
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+
5259var setThemeAndLang = function ( ) {
5360 //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 ;
5564
56- mainContent . $ . taCode . className = 'theme-' + mainContent . theme ;
65+ // mainContent.$.taCode.className = 'theme-' + mainContent.theme;
5766
58- mainContent . $ . destination . className = 'theme-' + mainContent . theme ;
67+ mainContent . $ . destination . className = 'flex theme-' + tmpTheme ;
68+ Polymer . updateStyles ( ) ;
5969
6070 //Change the language class if needed
6171 /*if (mainContent.lang != '--') {
@@ -97,62 +107,68 @@ var ptToPx = function(valPt) {
97107 return ( 16 / 12 ) * valPt ; //return the font-size in px from the ptValue
98108} ;
99109
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 ( ) {
104113 //Nothing to do
105114 } ) ;
106115
107116 //Get the px approximate size
108- var fontPx = ptToPx ( mainContent . fontPt ) + 'px' ;
117+ mainContent . fontPx = ptToPx ( newVal . detail . value ) + 'px' ;
109118
110119 //AutoGrow Text Area
111- mainContent . $ . agTa . style . fontSize = fontPx ;
120+ mainContent . $ . agTa . style . fontSize = mainContent . fontPx ;
112121 //Text Area
113- mainContent . $ . taCode . style . fontSize = fontPx ;
122+ //mainContent.$.taCode.style.fontSize = fontPx;
123+
114124 //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+ }
117130
118131} ;
119132
120133mainContent . 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+ }
132145} ;
133146
134147mainContent . validateForSlides = function ( ) {
135148 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' ;
150171 }
151- }
152- if ( warn . length > 0 ) {
153- divW . innerHTML = warn . join ( '<br>' ) ;
154- } else {
155- divW . innerHTML = 'Perfect code for slides' ;
156172 }
157173} ;
158174
0 commit comments