mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-30 18:20:15 +02:00
eslint fixes.
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
function deferred() {
|
||||
var d = {};
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
d.resolve = resolve;
|
||||
d.reject = reject;
|
||||
});
|
||||
(function() {
|
||||
window.deferred = function () {
|
||||
var d = {};
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
d.resolve = resolve;
|
||||
d.reject = reject;
|
||||
});
|
||||
|
||||
d.promise = promise;
|
||||
return Object.assign(d, promise);
|
||||
}
|
||||
d.promise = promise;
|
||||
return Object.assign(d, promise);
|
||||
};
|
||||
})();
|
@@ -1,81 +1,12 @@
|
||||
(function(w) {
|
||||
|
||||
// https://github.com/filamentgroup/loadCSS/blob/master/src/loadCSS.js
|
||||
window.loadCSS = function( href, before, media ){
|
||||
// Arguments explained:
|
||||
// `href` [REQUIRED] is the URL for your CSS file.
|
||||
// `before` [OPTIONAL] is the element the script should use as a reference for injecting our stylesheet <link> before
|
||||
// By default, loadCSS attempts to inject the link after the last stylesheet or script in the DOM. However, you might desire a more specific location in your document.
|
||||
// `media` [OPTIONAL] is the media type or query of the stylesheet. By default it will be 'all'
|
||||
var doc = w.document;
|
||||
var ss = doc.createElement( "link" );
|
||||
var ref;
|
||||
if( before ){
|
||||
ref = before;
|
||||
}
|
||||
else {
|
||||
var refs = ( doc.body || doc.getElementsByTagName( "head" )[ 0 ] ).childNodes;
|
||||
ref = refs[ refs.length - 1];
|
||||
}
|
||||
|
||||
var sheets = doc.styleSheets;
|
||||
ss.rel = "stylesheet";
|
||||
ss.href = href;
|
||||
// temporarily set media to something inapplicable to ensure it'll fetch without blocking render
|
||||
ss.media = "only x";
|
||||
|
||||
// wait until body is defined before injecting link. This ensures a non-blocking load in IE11.
|
||||
function ready( cb ){
|
||||
if( doc.body ){
|
||||
return cb();
|
||||
}
|
||||
setTimeout(function(){
|
||||
ready( cb );
|
||||
});
|
||||
}
|
||||
// Inject link
|
||||
// Note: the ternary preserves the existing behavior of "before" argument, but we could choose to change the argument to "after" in a later release and standardize on ref.nextSibling for all refs
|
||||
// Note: `insertBefore` is used instead of `appendChild`, for safety re: http://www.paulirish.com/2011/surefire-dom-element-insertion/
|
||||
ready( function(){
|
||||
ref.parentNode.insertBefore( ss, ( before ? ref : ref.nextSibling ) );
|
||||
});
|
||||
// A method (exposed on return object for external use) that mimics onload by polling document.styleSheets until it includes the new sheet.
|
||||
var onloadcssdefined = function( cb ){
|
||||
var resolvedHref = ss.href;
|
||||
var i = sheets.length;
|
||||
while( i-- ){
|
||||
if( sheets[ i ].href === resolvedHref ){
|
||||
return cb();
|
||||
}
|
||||
}
|
||||
setTimeout(function() {
|
||||
onloadcssdefined( cb );
|
||||
});
|
||||
};
|
||||
|
||||
function loadCB(){
|
||||
if( ss.addEventListener ){
|
||||
ss.removeEventListener( "load", loadCB );
|
||||
}
|
||||
ss.media = media || "all";
|
||||
}
|
||||
|
||||
// once loaded, set link's media back to `all` so that the stylesheet applies once it loads
|
||||
if( ss.addEventListener ){
|
||||
ss.addEventListener( "load", loadCB);
|
||||
}
|
||||
ss.onloadcssdefined = onloadcssdefined;
|
||||
onloadcssdefined( loadCB );
|
||||
return true;
|
||||
};
|
||||
|
||||
window.loadJS = function( src, cb ) {
|
||||
window.loadJS = function(src) {
|
||||
var d = deferred();
|
||||
var ref = w.document.getElementsByTagName( "script" )[ 0 ];
|
||||
var script = w.document.createElement( "script" );
|
||||
var ref = w.document.getElementsByTagName("script")[0];
|
||||
var script = w.document.createElement("script");
|
||||
script.src = src;
|
||||
script.async = true;
|
||||
ref.parentNode.insertBefore( script, ref );
|
||||
ref.parentNode.insertBefore(script, ref);
|
||||
script.onload = function () {
|
||||
d.resolve();
|
||||
};
|
||||
|
@@ -41,6 +41,7 @@
|
||||
, htmlMode = HtmlModes.HTML
|
||||
, jsMode = JsModes.JS
|
||||
, cssMode = CssModes.CSS
|
||||
, sass
|
||||
|
||||
, frame = $('#demo-frame')
|
||||
, htmlCode = $('#js-html-code')
|
||||
@@ -151,7 +152,7 @@
|
||||
loadJS('lib/less.min.js').then(setLoadedFlag);
|
||||
} else if (mode === CssModes.SCSS) {
|
||||
loadJS('lib/sass.js').then(function () {
|
||||
window.sass = new Sass('lib/sass.worker.js');
|
||||
sass = new Sass('lib/sass.worker.js');
|
||||
setLoadedFlag();
|
||||
});
|
||||
} else if (mode === JsModes.COFFEESCRIPT) {
|
||||
@@ -227,7 +228,7 @@
|
||||
if (jsMode === JsModes.JS) {
|
||||
d.resolve(code);
|
||||
} else if (jsMode === JsModes.COFFEESCRIPT) {
|
||||
d.resolve(CoffeeScript.compile(code, {bare: true}));
|
||||
d.resolve(CoffeeScript.compile(code, { bare: true }));
|
||||
} else if (jsMode === JsModes.ES6) {
|
||||
d.resolve(Babel.transform(editur.cm.js.getValue(), { presets: ['es2015'] }).code);
|
||||
}
|
||||
@@ -240,16 +241,16 @@
|
||||
};
|
||||
|
||||
function createPreviewFile(html, css, js) {
|
||||
html = '<html>\n<head>\n<style>\n' + css + '\n</style>\n</head>\n<body>\n' + html + '\n<script>\n' + js + '\n</script></body>\n</html>';
|
||||
var contents = '<html>\n<head>\n<style>\n' + css + '\n</style>\n</head>\n<body>\n' + html + '\n<script>\n' + js + '\n</script></body>\n</html>';
|
||||
|
||||
var fileWritten = false;
|
||||
|
||||
var blob = new Blob([ html ], {type: "text/plain;charset=UTF-8"});
|
||||
var blob = new Blob([ contents ], { type: "text/plain;charset=UTF-8" });
|
||||
|
||||
function errorHandler() { console.log(arguments); }
|
||||
|
||||
window.webkitRequestFileSystem(window.TEMPORARY, 1024 * 1024 * 5, function(fs){
|
||||
fs.root.getFile('preview.html', {create: true}, function(fileEntry) {
|
||||
fs.root.getFile('preview.html', { create: true }, function(fileEntry) {
|
||||
fileEntry.createWriter(function(fileWriter) {
|
||||
function onWriteComplete() {
|
||||
if (fileWritten) {
|
||||
@@ -295,7 +296,7 @@
|
||||
fileName += '.html';
|
||||
|
||||
var a = document.createElement('a');
|
||||
var blob = new Blob([ fileContent ], {type: "text/html;charset=UTF-8"});
|
||||
var blob = new Blob([ fileContent ], { type: "text/html;charset=UTF-8" });
|
||||
a.href = window.URL.createObjectURL(blob);
|
||||
a.download = fileName;
|
||||
a.style.display = 'none';
|
||||
@@ -372,9 +373,13 @@
|
||||
html: editur.cm.html.getValue(),
|
||||
css: editur.cm.css.getValue(),
|
||||
js: editur.cm.js.getValue(),
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
html_pre_processor: modes[htmlMode].codepenVal,
|
||||
css_pre_processor: modes[cssMode].codepenVal,
|
||||
js_pre_processor: modes[jsMode].codepenVal
|
||||
|
||||
/* eslint-enable camelcase */
|
||||
};
|
||||
json = JSON.stringify(json)
|
||||
.replace(/"/g, """)
|
||||
|
Reference in New Issue
Block a user