forked from bokub/nopaste
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Prism autoloader plugin; fix bugs
- Loading branch information
Showing
4 changed files
with
63 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,9 @@ | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<title>Paste</title> | ||
<script src="https://cdn.jsdelivr.net/combine/ | ||
npm/[email protected]/build/codeflask.min.js, | ||
npm/[email protected]/components/prism-markup-templating.min.js, | ||
npm/[email protected]/src/lzma.min.js, | ||
npm/[email protected]/build/codeflask.min.js, | ||
npm/[email protected]/plugins/autoloader/prism-autoloader.min.js, | ||
npm/[email protected]/dist/slimselect.min.js, | ||
npm/clipboard@2/dist/clipboard.min.js | ||
"></script> | ||
|
@@ -21,9 +21,7 @@ | |
type="text/css" | ||
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/slimselect.min.css" | ||
/> | ||
<link rel="stylesheet" href="theme.css" /> | ||
<link rel="stylesheet" href="styles.css" /> | ||
<style></style> | ||
<link rel="stylesheet" href="style.css" /> | ||
</head> | ||
<body> | ||
<div id="editor"></div> | ||
|
@@ -36,7 +34,7 @@ | |
</div> | ||
</div> | ||
<div id="copy" style="display: none"> | ||
<input type="text" value="copy me" id="copy-link" /> | ||
<input type="text" value="copy me" id="copy-link" onClick="this.setSelectionRange(0, this.value.length)" /> | ||
<button class="clipboard" data-clipboard-target="#copy-link" type="button">Copy</button> | ||
<button onclick="copyElement.style.display = 'none'" type="button">Cancel</button> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
let copyElement = document.getElementById('copy'); | ||
const flask = new CodeFlask('#editor', { language: 'javascript', lineNumbers: true, defaultTheme: false }); | ||
const lzma = new LZMA('lzma.min.js'); | ||
Prism.plugins.autoloader.languages_path = 'https://cdn.jsdelivr.net/npm/[email protected]/components/'; | ||
let select; | ||
|
||
function init() { | ||
|
@@ -17,14 +18,14 @@ function initLangSelector() { | |
select: '#language', | ||
data: Object.entries(languages).map(([value, text]) => ({ text, value })), | ||
showContent: 'up', | ||
onChange: () => { | ||
updateLanguage(); | ||
onChange: e => { | ||
console.log(e.value); | ||
flask.updateLanguage(e.value); | ||
} | ||
}); | ||
|
||
const urlParams = new URLSearchParams(window.location.search); | ||
select.set(Object.keys(languages).indexOf(urlParams.get('lang')) === -1 ? 'javascript' : urlParams.get('lang')); | ||
updateLanguage(); | ||
} | ||
|
||
function initCode() { | ||
|
@@ -55,32 +56,6 @@ function initCode() { | |
}); | ||
} | ||
|
||
function updateLanguage() { | ||
const lang = select.selected(); | ||
if (!Prism.languages.hasOwnProperty(lang)) { | ||
addLanguage(lang); | ||
return; | ||
} | ||
flask.updateLanguage(lang); | ||
} | ||
|
||
function addLanguage(lang) { | ||
// Add a setter to detect when a language is available | ||
Object.defineProperty(Prism.languages, lang, { | ||
set: function(val) { | ||
Prism.languages['_custom_' + lang] = val; | ||
flask.updateLanguage(lang); | ||
}, | ||
get: function() { | ||
return Prism.languages['_custom_' + lang]; | ||
} | ||
}); | ||
|
||
const script = document.createElement('script'); | ||
script.setAttribute('src', `https://cdn.jsdelivr.net/npm/[email protected]/components/prism-${lang}.min.js`); | ||
document.getElementsByTagName('head')[0].appendChild(script); | ||
} | ||
|
||
function generateLink() { | ||
const code = flask.getCode(); | ||
lzma.compress(code, 1, function(compressed, error) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.