diff --git a/.gitignore b/.gitignore
index e9b4327..c5f05f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
bower_components
vulcanized.js
-vulcanized.html
\ No newline at end of file
+vulcanized.html
+index.build.html
+index.build.js
\ No newline at end of file
diff --git a/assets/favicon_128.png b/assets/favicon_128.png
new file mode 100644
index 0000000..403143f
Binary files /dev/null and b/assets/favicon_128.png differ
diff --git a/assets/favicon_32.png b/assets/favicon_32.png
new file mode 100644
index 0000000..c57a775
Binary files /dev/null and b/assets/favicon_32.png differ
diff --git a/assets/favicon_512.png b/assets/favicon_512.png
new file mode 100644
index 0000000..d46f4e1
Binary files /dev/null and b/assets/favicon_512.png differ
diff --git a/background.js b/background.js
index f460b13..abc0c16 100644
--- a/background.js
+++ b/background.js
@@ -6,7 +6,7 @@
*/
chrome.app.runtime.onLaunched.addListener(function(launchData) {
chrome.app.window.create(
- 'index.html',
+ 'index.html',//Open the minified and CSP enabled code
{
id: 'mainWindow',
bounds: {width: 800, height: 600}
diff --git a/bower.json b/bower.json
index 54b9d50..3d320da 100644
--- a/bower.json
+++ b/bower.json
@@ -6,13 +6,13 @@
"author": "",
"private": true,
"dependencies": {
- "polymer": "Polymer/polymer#^0.5.2",
- "core-elements": "Polymer/core-elements#^0.5.2",
- "prettify-element": "Polymer/prettify-element3^0.5.2",
- "paper-button": "Polymer/paper-button#~0.5.2",
- "paper-dropdown-menu": "Polymer/paper-dropdown-menu#~0.5.2",
- "paper-dropdown": "Polymer/paper-dropdown#~0.5.2",
- "paper-input": "Polymer/paper-input#~0.5.2",
- "paper-toggle-button": "Polymer/paper-toggle-button#~0.5.2"
+ "polymer": "Polymer/polymer#^1.0.5",
+ "prettify-element": "smokybob/prettify-element#1.0",
+ "iron-flex-layout": "PolymerElements/iron-flex-layout#^1.0.1",
+ "iron-icons": "PolymerElements/iron-icons#^1.0.1",
+ "paper-input": "PolymerElements/paper-input#^1.0.0",
+ "paper-button": "PolymerElements/paper-button#^1.0.1",
+ "paper-toggle-button": "PolymerElements/paper-toggle-button#^1.0.1",
+ "iron-autogrow-textarea": "SmokyBob/iron-autogrow-textarea#inherit-color"
}
}
diff --git a/fonts.css b/fonts.css
index 2168b6a..6e551d4 100644
--- a/fonts.css
+++ b/fonts.css
@@ -1,9 +1,11 @@
+/*Inconsolata Font offline for Chrome Apps*/
+
/* latin-ext */
@font-face {
font-family: 'Inconsolata';
font-style: normal;
font-weight: 400;
- src: local('Inconsolata'), url(http://fonts.gstatic.com/s/inconsolata/v10/BjAYBlHtW3CJxDcjzrnZCCYE0-AqJ3nfInTTiDXDjU4.woff2) format('woff2');
+ src: local('Inconsolata'), url('../fonts/Inconsolata-latin.woff2') format('woff2');
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@@ -11,7 +13,7 @@
font-family: 'Inconsolata';
font-style: normal;
font-weight: 400;
- src: local('Inconsolata'), url(http://fonts.gstatic.com/s/inconsolata/v10/BjAYBlHtW3CJxDcjzrnZCOL2WfuF7Qc3ANwCvwl0TnA.woff2) format('woff2');
+ src: local('Inconsolata'), url('../fonts/Inconsolata-latin-ext.woff2') format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
/* latin-ext */
@@ -19,7 +21,7 @@
font-family: 'Inconsolata';
font-style: normal;
font-weight: 700;
- src: local('Inconsolata Bold'), local('Inconsolata-Bold'), url(http://fonts.gstatic.com/s/inconsolata/v10/AIed271kqQlcIRSOnQH0yejkDdvhIIFj_YMdgqpnSB0.woff2) format('woff2');
+ src: local('Inconsolata Bold'), local('Inconsolata-Bold'), url('../fonts/InconsolataBold-latin-ext.woff2') format('woff2');
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@@ -27,6 +29,6 @@
font-family: 'Inconsolata';
font-style: normal;
font-weight: 700;
- src: local('Inconsolata Bold'), local('Inconsolata-Bold'), url(http://fonts.gstatic.com/s/inconsolata/v10/AIed271kqQlcIRSOnQH0ydGR1r2frwpfjEqI8Bb_XHU.woff2) format('woff2');
+ src: local('Inconsolata Bold'), local('Inconsolata-Bold'), url('../fonts/InconsolataBold-latin.woff2') format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
\ No newline at end of file
diff --git a/fonts/Inconsolata-latin-ext.woff2 b/fonts/Inconsolata-latin-ext.woff2
new file mode 100644
index 0000000..732e27f
Binary files /dev/null and b/fonts/Inconsolata-latin-ext.woff2 differ
diff --git a/fonts/Inconsolata-latin.woff2 b/fonts/Inconsolata-latin.woff2
new file mode 100644
index 0000000..ae4186d
Binary files /dev/null and b/fonts/Inconsolata-latin.woff2 differ
diff --git a/fonts/InconsolataBold-latin-ext.woff2 b/fonts/InconsolataBold-latin-ext.woff2
new file mode 100644
index 0000000..0bc07dc
Binary files /dev/null and b/fonts/InconsolataBold-latin-ext.woff2 differ
diff --git a/fonts/InconsolataBold-latin.woff2 b/fonts/InconsolataBold-latin.woff2
new file mode 100644
index 0000000..6ea4341
Binary files /dev/null and b/fonts/InconsolataBold-latin.woff2 differ
diff --git a/index.html b/index.html
index 8536364..db1bfa5 100644
--- a/index.html
+++ b/index.html
@@ -2,54 +2,69 @@
PrettyCode
-
+
+
+
+
+
-
-
-
+
-
+
-
-
+
+
-
-
-
-
Light
-
-
Dark
+
+
+
-
-
-
-
-
-
-
diff --git a/main.js b/main.js
index b1988ca..2ea0057 100644
--- a/main.js
+++ b/main.js
@@ -1,144 +1,171 @@
//Use Polymer Bindings
var mainContent = document.querySelector('#mainContent');
-//Get data from the localStorage
-mainContent.lang = localStorage.lang || '--';
-mainContent.code = localStorage.theCode || '';
-mainContent.theme = localStorage.theme || 'light';
-mainContent.fontPt = localStorage.fontPt || 14;
-
-mainContent.addEventListener('template-bound', function(){
+//Get data from the syncStorage
+chrome.storage.sync.get(
+ ['language', 'theCode', 'theme', 'fontPt'],
+ function(localStorage) {
+ mainContent.language = localStorage.language || '--';
+ mainContent.code = localStorage.theCode || '';
+ mainContent.theme = localStorage.theme || 'light';
+ mainContent.fontPt = localStorage.fontPt || 14;
+ });
+mainContent.addEventListener('dom-change', function() {
//Set the font-size
- mainContent.ptChange();
+ mainContent.ptChange({detail: mainContent.fontPt});
//Now that the template is bound update the code in the textArea
- mainContent.$.taCode.value = mainContent.code;
- mainContent.$.agTa.update(mainContent.$.taCode); //Update the autoGrowArea;
-
- //Add a change listener to the textArea
- mainContent.$.taCode.addEventListener('input', function() {
- localStorage.theCode = mainContent.code = mainContent.$.taCode.value;
- //Code Changed, run the validation for slides
- mainContent.validateForSlides();
- });
+ //mainContent.$.codeValue = mainContent.code;
+ //mainContent.$.agTa.update(mainContent.$.taCode); //Update the autoGrowArea;
//Find the label of the selected language to set it on the paper-dropdown-menu
- var mnItems =document.querySelectorAll('paper-item');
- [].some.call(mnItems, function(mnItem){
- if (mnItem.dataset.value==mainContent.lang){
+ /*var mnItems = document.querySelectorAll('paper-item');
+ [].some.call(mnItems, function(mnItem) {
+ if (mnItem.dataset.value == mainContent.language) {
//Item found, update the selectedItem to change the label
- mainContent.$.pdmLanguage.selectedItemLabel=mnItem.innerText;
+ mainContent.$.pdmLanguage.selectedItemLabel = mnItem.innerText;
return true;
}
return false;
- });
+ });*/
//Select the theme on the slider
- mainContent.$.ptbTheme.checked=(mainContent.theme=='dark');
+ //mainContent.$.ptbTheme.checked = (mainContent.theme == 'dark');
- //Set the theme and lang on all the components
- setThemeAndLang();
+ //Update Computed Styles
+ Polymer.updateStyles();
//Run validation
mainContent.validateForSlides();
});
-var setThemeAndLang = function(){
- //Change the classes on the prettyprint element accordingly
- document.body.className = 'theme-' + mainContent.theme;
-
- mainContent.$.taCode.className = 'theme-' + mainContent.theme;
-
- mainContent.$.destination.className = 'theme-' + mainContent.theme;
-
- //Change the language class if needed
- /*if (mainContent.lang != '--') {
- mainContent.$.destination.className += ' lang-' + mainContent.lang;
- }*/
-}
+//Computed Styles
+mainContent._computedBodyClass = function(theme) {
+ return 'fit layout vertical theme-' + (theme || 'light');
+};
+
+mainContent._computedThemeClass = function(theme){
+ return 'theme-' + (theme || 'light');
+};
+
+mainContent._computedDestinationClass = function(theme) {
+ return 'flex theme-' + (theme || 'light');
+};
+
+mainContent._selTheme = function(theme) {
+ var tmpTheme = theme || 'light';
+
+ return (tmpTheme == 'dark');
+
+};
+
+mainContent.codeChanged = function(newVal) {
+
+ chrome.storage.sync.set({'theCode': mainContent.code}, function() {
+ //Nothing to do
+ });
+ //Code Changed, run the validation for slides
+ mainContent.validateForSlides();
+
+};
-mainContent.languageSelected = function(selMenu){
+mainContent.languageSelected = function(selMenu) {
//Changed selected language, update the value and store
- if(selMenu.detail.isSelected){
- localStorage.lang = mainContent.lang=selMenu.detail.item.dataset.value;
+ if (selMenu.detail.isSelected) {
+ mainContent.language = selMenu.detail.item.dataset.value;
+ chrome.storage.sync.set({'language': mainContent.language}, function() {
+ //Nothing to do
+ });
//Set the theme and lang
- setThemeAndLang();
+ Polymer.updateStyles();
}
-}
+};
-mainContent.chTheme = function(){
+mainContent.chTheme = function() {
//if checked theme is dark, otherwise light
- if(mainContent.$.ptbTheme.checked){
- localStorage.theme = mainContent.theme = 'dark';
- }else{
- localStorage.theme = mainContent.theme = 'light';
+ if (mainContent.$.ptbTheme.checked) {
+ mainContent.theme = 'dark';
+ }else {
+ mainContent.theme = 'light';
}
+ chrome.storage.sync.set({'theme': mainContent.theme}, function() {
+ //Nothing to do
+ });
- //Set the theme and lang
- setThemeAndLang();
+ //Update styles
+ Polymer.updateStyles();
-}
+};
-var ptToPx = function(valPt){
- return (16/12)*valPt;//return the font-size in px from the ptValue
-}
+var ptToPx = function(valPt) {
+ return (16 / 12) * valPt;//return the font-size in px from the ptValue
+};
-mainContent.ptChange = function(){
- //TODO:Validate the value before saving it and using it to calculate the px value
- localStorage.fontPt = mainContent.fontPt;
+mainContent.ptChange = function(newVal) {
+
+ chrome.storage.sync.set({'fontPt': newVal.detail.value}, function() {
+ //Nothing to do
+ });
//Get the px approximate size
- var fontPx = ptToPx(mainContent.fontPt) + 'px';
+ mainContent.fontPx = ptToPx(newVal.detail.value) + 'px';
//AutoGrow Text Area
- mainContent.$.agTa.style.fontSize = fontPx;
- //Text Area
- mainContent.$.taCode.style.fontSize = fontPx;
+ mainContent.$.agTa.style.fontSize = mainContent.fontPx;//Done to avoid errors in Polymer library... TODO:open Issue?
+ //--paper-input-container-input
+ mainContent.$.agTa.customStyle['--paper-input-container-input'] = {'font-size': mainContent.fontPx};
+
//Pre Element
- var preElement = mainContent.$.destination.shadowRoot.querySelector('pre');
- preElement.style.fontSize = fontPx;
-
-}
-
-mainContent.selPrettyCode = function(sender){
- //Get the pre element inside the prettyfy-element
- var preElement = sender.currentTarget.shadowRoot.querySelector('pre');
-
- //Select the text range
- var doc = document;
- var selection = window.getSelection();
- var range = doc.createRange();
- range.selectNodeContents(preElement);
- selection.removeAllRanges();
- selection.addRange(range);
-
-}
-
-mainContent.validateForSlides = function(){
- var divW = document.querySelector("#slidesWarnings");
- var warn = [];
-
- var MAX_LINES = 20;
- if ((mainContent.code.match(/\n/g) || []).length >= MAX_LINES) {
- warn.push('More than ' + MAX_LINES + ' lines of code will be hard to read on a slide.');
+ if (mainContent.$.destination.shadowRoot) {
+ var preElement = mainContent.$.destination.shadowRoot.querySelector('pre');
+ preElement.style.fontSize = mainContent.fontPx;
}
-
- var lines = mainContent.code.split('\n') || [];
- var MAX_LINE_LENGTH = 80;
- for (var i = 0; i < lines.length; i++) {
- if (lines[i].length > MAX_LINE_LENGTH) {
- warn.push('Line ' + (i + 1) + ' has more than ' + MAX_LINE_LENGTH + ' characters!');
- }
+ Polymer.updateStyles();
+
+};
+
+mainContent.selPrettyCode = function(sender) {
+ //Get the pre element inside the prettify-element
+ if (mainContent.$.destination.shadowRoot) {
+ var preElement = mainContent.$.destination.shadowRoot.querySelector('pre');
+ //Select the text range
+ var doc = document;
+ var selection = window.getSelection();
+ var range = doc.createRange();
+ range.selectNodeContents(preElement);
+ selection.removeAllRanges();
+ selection.addRange(range);
}
- if (warn.length>0){
- divW.innerHTML = warn.join('
');
- }else{
- divW.innerHTML='Perfect code for slides';
+};
+
+mainContent.validateForSlides = function() {
+ var divW = document.querySelector('#slidesWarnings');
+
+ if (divW){
+ var warn = [];
+
+ var MAX_LINES = 20;
+ if ((mainContent.code.match(/\n/g) || []).length >= MAX_LINES) {
+ warn.push('More than ' + MAX_LINES +
+ ' lines of code will be hard to read on a slide.');
+ }
+
+ var lines = mainContent.code.split('\n') || [];
+ var MAX_LINE_LENGTH = 80;
+ for (var i = 0; i < lines.length; i++) {
+ if (lines[i].length > MAX_LINE_LENGTH) {
+ warn.push('Line ' + (i + 1) + ' has more than ' +
+ MAX_LINE_LENGTH + ' characters!');
+ }
+ }
+ if (warn.length > 0) {
+ divW.innerHTML = warn.join('
');
+ }else {
+ divW.innerHTML = 'Perfect code for slides';
+ }
}
-}
-
-
+};
diff --git a/manifest.json b/manifest.json
index 7f30ed7..48a0da6 100644
--- a/manifest.json
+++ b/manifest.json
@@ -2,15 +2,17 @@
"manifest_version": 2,
"name": "PrettyCode",
"short_name": "PrettyCode",
- "description": "Description for PrettyCode",
+ "description": "Code prettyfier following guidelines for GDE Videos",
- "version": "0.0.1.0",
+ "version": "1.0.0",
"icons": {
- "16": "assets/icon_16.png",
- "128": "assets/icon_128.png"
+ "32": "assets/favicon_32.png",
+ "128": "assets/favicon_128.png"
},
-
+ "permissions": [
+ "storage"
+ ],
"app": {
"background": {
"scripts": ["background.js"]
diff --git a/setShadow.js b/setShadow.js
new file mode 100644
index 0000000..4d351f5
--- /dev/null
+++ b/setShadow.js
@@ -0,0 +1,2 @@
+window.Polymer = window.Polymer || {};
+window.Polymer.dom = 'shadow';
\ No newline at end of file
diff --git a/styles.css b/styles.css
deleted file mode 100644
index de7ffb5..0000000
--- a/styles.css
+++ /dev/null
@@ -1,82 +0,0 @@
-/* CSS Styles adapted from http://www.nurik.net/exp/iohighlighter/ */
-body {
- background-color: #e8e8e8;
- -webkit-font-smoothing: antialiased;
-}
-
-body.theme-light {
- background-color: #e8e8e8;
- color: #000;
-}
-
-body.theme-dark {
- background-color: #222;
- color: #fff;
-}
-
-paper-autogrow-textarea{
- width: 100%;
- min-height: 90px;
- font-family: Inconsolata;
- font-size: 20px;/*= 15pt, more info http://kyleschaeffer.com/development/css-font-size-em-vs-px-vs-pt-vs/*/
-}
-#taCode {
- font-family: Inconsolata;
- font-size: 20px;/*= 15pt, more info http://kyleschaeffer.com/development/css-font-size-em-vs-px-vs-pt-vs/*/
-}
-
-.theme-light #taCode {
- background-color: #ffcccc;
-}
-
-#slidesWarnings {
- background-color: #f00;
- color: #fff;
- padding: 20px;
- font-family: Inconsolata;
- font-weight: bold;
- border-radius: 6px;
- }
-
-/*Themes*/
-.theme-dark #taCode {
- background-color: #300;
- color: #fff;
-}
-
-.theme-dark prettify-element::shadow pre { font-family: Inconsolata; font-size: 20px; background-color:transparent;}
-.theme-dark prettify-element::shadow .pln { color: #fff } /* plain text */
-.theme-dark prettify-element::shadow .str,
-.theme-dark prettify-element::shadow .atv { color: #57bb8a } /* string content and attribute value */
-.theme-dark prettify-element::shadow .kwd,
-.theme-dark prettify-element::shadow .tag { color: #7baaf7; } /* a keyword or tag */
-.theme-dark prettify-element::shadow .com { color: #aaa } /* a comment */
-.theme-dark prettify-element::shadow .typ,
-.theme-dark prettify-element::shadow .var { color: #ff8a65 } /* a type name or xq variable */
-.theme-dark prettify-element::shadow .lit { color: #f4b400 } /* a literal value */
-.theme-dark prettify-element::shadow .pun,
-.theme-dark prettify-element::shadow .opn,
-.theme-dark prettify-element::shadow .clo { color: #a3a3a3 } /* punctuation, lisp open bracket, lisp close bracket */
-.theme-dark prettify-element::shadow .atn { color: #f06292 } /* a markup attribute name */
-.theme-dark prettify-element::shadow .dec,
-.theme-dark prettify-element::shadow .var { color: #e67c73 } /* a declaration like doctype */
-.theme-dark prettify-element::shadow .fun { color: #fff } /* a function name */
-
-
-.theme-light prettify-element::shadow pre { font-family: Inconsolata; font-size: 20px; background-color:transparent;}
-.theme-light prettify-element::shadow .pln { color: #000 } /* plain text */
-.theme-light prettify-element::shadow .str,
-.theme-light prettify-element::shadow .atv { color: #0f9d58 } /* string content and attribute value */
-.theme-light prettify-element::shadow .kwd,
-.theme-light prettify-element::shadow .tag { color: #4285f4; } /* a keyword or tag */
-.theme-light prettify-element::shadow .com { color: #999 } /* a comment */
-.theme-light prettify-element::shadow .typ,
-.theme-light prettify-element::shadow .var { color: #673ab7 } /* a type name or xq variable */
-.theme-light prettify-element::shadow .lit { color: #db4437 } /* a literal value */
-.theme-light prettify-element::shadow .pun,
-.theme-light prettify-element::shadow .opn,
-.theme-light prettify-element::shadow .clo { color: #a3a3a3 } /* punctuation, lisp open bracket, lisp close bracket */
-.theme-light prettify-element::shadow .atn { color: #e91e63 } /* a markup attribute name */
-.theme-light prettify-element::shadow .dec,
-.theme-light prettify-element::shadow .var { color: #e67c73 } /* a declaration like doctype */
-.theme-light prettify-element::shadow .fun { color: #fff } /* a function name */
diff --git a/styles.html b/styles.html
new file mode 100644
index 0000000..3e30865
--- /dev/null
+++ b/styles.html
@@ -0,0 +1,151 @@
+
+
\ No newline at end of file