summaryrefslogtreecommitdiff
path: root/public/js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js')
-rw-r--r--public/js/cover.js2
-rw-r--r--public/js/extra.js43
-rw-r--r--public/js/history.js62
-rw-r--r--public/js/index.js16
-rw-r--r--public/js/locale.js2
-rw-r--r--public/js/pretty.js5
-rw-r--r--public/js/public.js25
-rw-r--r--public/js/slide.js19
8 files changed, 66 insertions, 108 deletions
diff --git a/public/js/cover.js b/public/js/cover.js
index 3dd4de09..c02f6c81 100644
--- a/public/js/cover.js
+++ b/public/js/cover.js
@@ -1,3 +1,5 @@
+require('./locale');
+
var common = require('./common');
var checkIfAuth = common.checkIfAuth;
var urlpath = common.urlpath;
diff --git a/public/js/extra.js b/public/js/extra.js
index 436721a3..499bdc4c 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -1,3 +1,8 @@
+require('prismjs/themes/prism.css');
+require('highlight.js/styles/github-gist.css');
+
+var Prism = require('prismjs');
+require('prismjs/components/prism-wiki');
var hljs = require('highlight.js');
var PDFObject = require('pdfobject');
var S = require('string');
@@ -101,6 +106,41 @@ function renderFilename(view) {
return filename;
}
+// render tags
+function renderTags(view) {
+ var tags = [];
+ var rawtags = [];
+ if (md && md.meta && md.meta.tags && (typeof md.meta.tags == "string" || typeof md.meta.tags == "number")) {
+ var metaTags = ('' + md.meta.tags).split(',');
+ for (var i = 0; i < metaTags.length; i++) {
+ var text = metaTags[i].trim();
+ if (text) rawtags.push(text);
+ }
+ } else {
+ view.find('h6').each(function (key, value) {
+ if (/^tags/gmi.test($(value).text())) {
+ var codes = $(value).find("code");
+ for (var i = 0; i < codes.length; i++) {
+ var text = codes[i].innerHTML.trim();
+ if (text) rawtags.push(text);
+ }
+ }
+ });
+ }
+ for (var i = 0; i < rawtags.length; i++) {
+ var found = false;
+ for (var j = 0; j < tags.length; j++) {
+ if (tags[j] == rawtags[i]) {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ tags.push(rawtags[i]);
+ }
+ return tags;
+}
+
function slugifyWithUTF8(text) {
var newText = S(text.toLowerCase()).trim().stripTags().dasherize().s;
newText = newText.replace(/([\!\"\#\$\%\&\'\(\)\*\+\,\.\/\:\;\<\=\>\?\@\[\\\]\^\`\{\|\}\~])/g, '');
@@ -844,8 +884,6 @@ md.use(require('markdown-it-emoji'), {
shortcuts: false
});
-var emojify = require('emojify.js');
-
emojify.setConfig({
blacklist: {
elements: ['script', 'textarea', 'a', 'pre', 'code', 'svg'],
@@ -1076,6 +1114,7 @@ module.exports = {
renderTOC: renderTOC,
renderTitle: renderTitle,
renderFilename: renderFilename,
+ renderTags: renderTags,
generateToc: generateToc,
smoothHashScroll: smoothHashScroll,
scrollToHash: scrollToHash,
diff --git a/public/js/history.js b/public/js/history.js
index d924eec1..390e38eb 100644
--- a/public/js/history.js
+++ b/public/js/history.js
@@ -5,10 +5,6 @@ var checkIfAuth = common.checkIfAuth;
var urlpath = common.urlpath;
var getLoginState = common.getLoginState;
-var extra = require('./extra');
-var renderFilename = extra.renderFilename;
-var md = extra.md;
-
window.migrateHistoryFromTempCallback = null;
migrateHistoryFromTemp();
@@ -147,19 +143,19 @@ function removeHistory(id, notehistory) {
}
//used for inner
-function writeHistory(view) {
+function writeHistory(title, tags) {
checkIfAuth(
function () {
// no need to do this anymore, this will count from server-side
- // writeHistoryToServer(view);
+ // writeHistoryToServer(title, tags);
},
function () {
- writeHistoryToStorage(view);
+ writeHistoryToStorage(title, tags);
}
);
}
-function writeHistoryToServer(view) {
+function writeHistoryToServer(title, tags) {
$.get(serverurl + '/history')
.done(function (data) {
try {
@@ -174,7 +170,7 @@ function writeHistoryToServer(view) {
if (!notehistory)
notehistory = [];
- var newnotehistory = generateHistory(view, notehistory);
+ var newnotehistory = generateHistory(title, tags, notehistory);
saveHistoryToServer(newnotehistory);
})
.fail(function (xhr, status, error) {
@@ -182,7 +178,7 @@ function writeHistoryToServer(view) {
});
}
-function writeHistoryToCookie(view) {
+function writeHistoryToCookie(title, tags) {
try {
var notehistory = Cookies.getJSON('notehistory');
} catch (err) {
@@ -191,11 +187,11 @@ function writeHistoryToCookie(view) {
if (!notehistory)
notehistory = [];
- var newnotehistory = generateHistory(view, notehistory);
+ var newnotehistory = generateHistory(title, tags, notehistory);
saveHistoryToCookie(newnotehistory);
}
-function writeHistoryToStorage(view) {
+function writeHistoryToStorage(title, tags) {
if (store.enabled) {
var data = store.get('notehistory');
if (data) {
@@ -207,10 +203,10 @@ function writeHistoryToStorage(view) {
if (!notehistory)
notehistory = [];
- var newnotehistory = generateHistory(view, notehistory);
+ var newnotehistory = generateHistory(title, tags, notehistory);
saveHistoryToStorage(newnotehistory);
} else {
- writeHistoryToCookie(view);
+ writeHistoryToCookie(title, tags);
}
}
@@ -220,39 +216,7 @@ if (!Array.isArray) {
};
}
-function renderHistory(view) {
- var title = renderFilename(view);
-
- var tags = [];
- var rawtags = [];
- if (md && md.meta && md.meta.tags && (typeof md.meta.tags == "string" || typeof md.meta.tags == "number")) {
- var metaTags = ('' + md.meta.tags).split(',');
- for (var i = 0; i < metaTags.length; i++) {
- var text = metaTags[i].trim();
- if (text) rawtags.push(text);
- }
- } else {
- view.find('h6').each(function (key, value) {
- if (/^tags/gmi.test($(value).text())) {
- var codes = $(value).find("code");
- for (var i = 0; i < codes.length; i++) {
- var text = codes[i].innerHTML.trim();
- if (text) rawtags.push(text);
- }
- }
- });
- }
- for (var i = 0; i < rawtags.length; i++) {
- var found = false;
- for (var j = 0; j < tags.length; j++) {
- if (tags[j] == rawtags[i]) {
- found = true;
- break;
- }
- }
- if (!found)
- tags.push(rawtags[i]);
- }
+function renderHistory(title, tags) {
//console.debug(tags);
var id = urlpath ? location.pathname.slice(urlpath.length + 1, location.pathname.length).split('/')[1] : location.pathname.split('/')[1];
return {
@@ -263,8 +227,8 @@ function renderHistory(view) {
};
}
-function generateHistory(view, notehistory) {
- var info = renderHistory(view);
+function generateHistory(title, tags, notehistory) {
+ var info = renderHistory(title, tags);
//keep any pinned data
var pinned = false;
for (var i = 0; i < notehistory.length; i++) {
diff --git a/public/js/index.js b/public/js/index.js
index bdd4c822..4be11e86 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -1,16 +1,11 @@
/* jquery and jquery plugins */
require('../vendor/showup/showup');
-require('prismjs/themes/prism.css');
-require('highlight.js/styles/github-gist.css');
-
-require('prismjs');
-require('prismjs/components/prism-wiki');
var toMarkdown = require('to-markdown');
var saveAs = require('file-saver').saveAs;
-require('js-url');
-require('randomcolor');
+var url = require('js-url');
+var randomColor = require('randomcolor');
var _ = require("lodash");
@@ -28,7 +23,6 @@ var noteurl = common.noteurl;
var checkLoginStateChanged = common.checkLoginStateChanged;
-require('./pretty');
var extra = require('./extra');
var md = extra.md;
var updateLastChange = extra.updateLastChange;
@@ -41,6 +35,7 @@ var deduplicatedHeaderId = extra.deduplicatedHeaderId;
var renderTOC = extra.renderTOC;
var renderTitle = extra.renderTitle;
var renderFilename = extra.renderFilename;
+var renderTags = extra.renderTags;
var scrollToHash = extra.scrollToHash;
var updateLastChangeUser = extra.updateLastChangeUser;
var updateOwner = extra.updateOwner;
@@ -1541,6 +1536,7 @@ function onGoogleClientLoaded() {
googleApiAuth(true);
buildImportFromGoogleDrive();
}
+window.onGoogleClientLoaded = onGoogleClientLoaded;
// export to google drive
ui.toolbar.export.googleDrive.click(function (e) {
var token = gapi.auth.getToken();
@@ -3414,7 +3410,7 @@ var updateHistoryDebounce = 600;
var updateHistory = _.debounce(updateHistoryInner, updateHistoryDebounce)
function updateHistoryInner() {
- writeHistory(ui.area.markdown);
+ writeHistory(renderFilename(ui.area.markdown), renderTags(ui.area.markdown));
}
function updateDataAttrs(src, des) {
@@ -3732,8 +3728,6 @@ function matchInContainer(text) {
}
}
-var emojify = require('emojify.js');
-
$(editor.getInputField())
.textcomplete([
{ // emoji strategy
diff --git a/public/js/locale.js b/public/js/locale.js
index 484ce22f..702496e7 100644
--- a/public/js/locale.js
+++ b/public/js/locale.js
@@ -1,5 +1,3 @@
-require('./cover');
-
var lang = "en";
var userLang = navigator.language || navigator.userLanguage;
var userLangCode = userLang.split('-')[0];
diff --git a/public/js/pretty.js b/public/js/pretty.js
index c5211202..59403586 100644
--- a/public/js/pretty.js
+++ b/public/js/pretty.js
@@ -1,3 +1,6 @@
+/* other vendors plugin */
+var S = require('string');
+
var extra = require('./extra');
var md = extra.md;
var finishView = extra.finishView;
@@ -12,7 +15,7 @@ var parseMeta = extra.parseMeta;
var preventXSS = require('./render').preventXSS;
var markdown = $("#doc.markdown-body");
-var text = $('<textarea/>').html(markdown.html()).text();
+var text = S(markdown.html()).unescapeHTML().s;
var lastMeta = md.meta;
md.meta = {};
var rendered = md.render(text);
diff --git a/public/js/public.js b/public/js/public.js
deleted file mode 100644
index f83ef41f..00000000
--- a/public/js/public.js
+++ /dev/null
@@ -1,25 +0,0 @@
-/* jquery and jquery plugins */
-require('../vendor/showup/showup');
-
-require('prismjs/themes/prism.css');
-require('highlight.js/styles/github-gist.css');
-
-/* other vendors plugin */
-require('string');
-require('prismjs');
-require('prismjs/components/prism-wiki');
-require('to-markdown');
-
-require('file-saver');
-require('store');
-require('js-url');
-require('visibilityjs');
-require('list.js');
-require('../vendor/md-toc');
-require('randomcolor');
-
-require('./extra');
-require('./syncscroll');
-require('./history');
-require('./pretty');
-require('./render');
diff --git a/public/js/slide.js b/public/js/slide.js
index 2536c602..c260de6d 100644
--- a/public/js/slide.js
+++ b/public/js/slide.js
@@ -1,30 +1,13 @@
-require('prismjs/themes/prism.css');
/* other vendors plugin */
var S = require('string');
-require('prismjs');
-require('prismjs/components/prism-wiki');
-require('to-markdown');
-
-require('../vendor/md-toc');
-require('randomcolor');
-
-var commonModule = require('./common');
-var urlpath = commonModule.urlpath;
-var noteid = commonModule.noteid;
-var debug = commonModule.debug;
-var version = commonModule.version;
-var GOOGLE_API_KEY = commonModule.GOOGLE_API_KEY;
-var GOOGLE_CLIENT_ID = commonModule.GOOGLE_CLIENT_ID;
-var DROPBOX_APP_KEY = commonModule.DROPBOX_APP_KEY;
-var noteurl = commonModule.noteurl;
var extraModule = require('./extra');
var md = extraModule.md;
var updateLastChange = extraModule.updateLastChange;
var finishView = extraModule.finishView;
-require('./render');
+var preventXSS = require('./render').preventXSS;
var body = $(".slides").html();
$(".slides").html(S(body).unescapeHTML().s);