diff options
author | luxagraf <sng@luxagraf.net> | 2018-11-29 16:57:26 -0600 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2018-11-29 16:57:26 -0600 |
commit | 4974eb58480f413c67f5f6e8fac430186eda2b62 (patch) | |
tree | 7402ecba682dbda38db4b6db221cc8378a390977 /scripts | |
parent | 0c2a092e8d8ad33a1c306ee9efca0da96eb56415 (diff) |
uploading all recent changes ahead of sys upgrade
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/gulpfile.js | 17 | ||||
-rw-r--r-- | scripts/package.json | 20 | ||||
-rw-r--r-- | scripts/src/js.cookie.js | 165 | ||||
-rw-r--r-- | scripts/src/main-nav.js | 71 | ||||
-rw-r--r-- | scripts/src/overlay.js (renamed from scripts/overlay.js) | 0 | ||||
-rw-r--r-- | scripts/src/util.js (renamed from scripts/util.js) | 35 |
6 files changed, 302 insertions, 6 deletions
diff --git a/scripts/gulpfile.js b/scripts/gulpfile.js new file mode 100644 index 0000000..67c5bf7 --- /dev/null +++ b/scripts/gulpfile.js @@ -0,0 +1,17 @@ +const { src, dest } = require('gulp'); +const uglify = require('gulp-uglify'); +const rename = require('gulp-rename'); +const concat = require('gulp-concat'); +const babel = require('gulp-babel'); + +exports.default = function() { + return src('src/*.js') + .pipe(babel({ + presets: ['@babel/env'] + })) + .pipe(concat('package.js')) + .pipe(uglify()) + .pipe(dest('../media/js/')) + .pipe(rename({ extname: '.min.js' })) + .pipe(dest('../media/js/')); +} diff --git a/scripts/package.json b/scripts/package.json new file mode 100644 index 0000000..778b5e6 --- /dev/null +++ b/scripts/package.json @@ -0,0 +1,20 @@ +{ + "name": "scripts", + "version": "1.0.0", + "description": "javascript for aite", + "main": "common.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "luxagraf", + "license": "ISC", + "devDependencies": { + "@babel/core": "^7.1.6", + "@babel/preset-env": "^7.1.6", + "gulp": "^4.0.0", + "gulp-babel": "^8.0.0", + "gulp-concat": "^2.6.1", + "gulp-rename": "^1.4.0", + "gulp-uglify": "^3.0.1" + } +} diff --git a/scripts/src/js.cookie.js b/scripts/src/js.cookie.js new file mode 100644 index 0000000..9a0945e --- /dev/null +++ b/scripts/src/js.cookie.js @@ -0,0 +1,165 @@ +/*! + * JavaScript Cookie v2.2.0 + * https://github.com/js-cookie/js-cookie + * + * Copyright 2006, 2015 Klaus Hartl & Fagner Brack + * Released under the MIT license + */ +;(function (factory) { + var registeredInModuleLoader = false; + if (typeof define === 'function' && define.amd) { + define(factory); + registeredInModuleLoader = true; + } + if (typeof exports === 'object') { + module.exports = factory(); + registeredInModuleLoader = true; + } + if (!registeredInModuleLoader) { + var OldCookies = window.Cookies; + var api = window.Cookies = factory(); + api.noConflict = function () { + window.Cookies = OldCookies; + return api; + }; + } +}(function () { + function extend () { + var i = 0; + var result = {}; + for (; i < arguments.length; i++) { + var attributes = arguments[ i ]; + for (var key in attributes) { + result[key] = attributes[key]; + } + } + return result; + } + + function init (converter) { + function api (key, value, attributes) { + var result; + if (typeof document === 'undefined') { + return; + } + + // Write + + if (arguments.length > 1) { + attributes = extend({ + path: '/' + }, api.defaults, attributes); + + if (typeof attributes.expires === 'number') { + var expires = new Date(); + expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5); + attributes.expires = expires; + } + + // We're using "expires" because "max-age" is not supported by IE + attributes.expires = attributes.expires ? attributes.expires.toUTCString() : ''; + + try { + result = JSON.stringify(value); + if (/^[\{\[]/.test(result)) { + value = result; + } + } catch (e) {} + + if (!converter.write) { + value = encodeURIComponent(String(value)) + .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent); + } else { + value = converter.write(value, key); + } + + key = encodeURIComponent(String(key)); + key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent); + key = key.replace(/[\(\)]/g, escape); + + var stringifiedAttributes = ''; + + for (var attributeName in attributes) { + if (!attributes[attributeName]) { + continue; + } + stringifiedAttributes += '; ' + attributeName; + if (attributes[attributeName] === true) { + continue; + } + stringifiedAttributes += '=' + attributes[attributeName]; + } + return (document.cookie = key + '=' + value + stringifiedAttributes); + } + + // Read + + if (!key) { + result = {}; + } + + // To prevent the for loop in the first place assign an empty array + // in case there are no cookies at all. Also prevents odd result when + // calling "get()" + var cookies = document.cookie ? document.cookie.split('; ') : []; + var rdecode = /(%[0-9A-Z]{2})+/g; + var i = 0; + + for (; i < cookies.length; i++) { + var parts = cookies[i].split('='); + var cookie = parts.slice(1).join('='); + + if (!this.json && cookie.charAt(0) === '"') { + cookie = cookie.slice(1, -1); + } + + try { + var name = parts[0].replace(rdecode, decodeURIComponent); + cookie = converter.read ? + converter.read(cookie, name) : converter(cookie, name) || + cookie.replace(rdecode, decodeURIComponent); + + if (this.json) { + try { + cookie = JSON.parse(cookie); + } catch (e) {} + } + + if (key === name) { + result = cookie; + break; + } + + if (!key) { + result[name] = cookie; + } + } catch (e) {} + } + + return result; + } + + api.set = api; + api.get = function (key) { + return api.call(api, key); + }; + api.getJSON = function () { + return api.apply({ + json: true + }, [].slice.call(arguments)); + }; + api.defaults = {}; + + api.remove = function (key, attributes) { + api(key, '', extend(attributes, { + expires: -1 + })); + }; + + api.withConverter = init; + + return api; + } + + return init(function () {}); +})); diff --git a/scripts/src/main-nav.js b/scripts/src/main-nav.js new file mode 100644 index 0000000..fa6f25a --- /dev/null +++ b/scripts/src/main-nav.js @@ -0,0 +1,71 @@ +function hideOnClickOutsided(element, btn) { + // given a menu element and btn, hide the menu + // whenever the click is not on either the element + // or the btn the opened it + const outsideClickListener = event => { + if (!element.contains(event.target) && (event.target.id != btn)) { // or use: event.target.closest(selector) === null + if (isVisible(element)) { + element.classList.remove('active') + removeClickListener() + } + } + } + + const removeClickListener = () => { + document.removeEventListener('click', outsideClickListener) + } + document.addEventListener('click', outsideClickListener) +} +const isVisible = elem => !!elem && !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length ) // source (2018-03-11): https://github.com/jquery/jquery/blob/master/src/css/hiddenVisibleSelectors.js + +//---------------------------------------- +//Initialize main menu bar with progressive enhancements +//---------------------------------------------- +// Account Menu +var account_a = document.getElementById("account-menu"); +var account_div = document.getElementById("user-menu"); +//Add button function +account_a.addEventListener('click', function(e){ + e.preventDefault(); + account_div.classList.toggle('active') + account_div.focus(); + hideOnClickOutsided(account_div, account_a.id); +}, false); + +// Notebooks Menu +var notebook_a = document.getElementById("notebook-menu-link"); +var notebook_div = document.getElementById("notebooks-menu"); +//Add button function +notebook_a.addEventListener('click', function(e){ + e.preventDefault(); + notebook_div.classList.toggle('active') + notebook_div.focus(); + hideOnClickOutsided(notebook_div, notebook_a.id); +}, false); + + +//function buildNotebookMenu () { +// var data = JSON.parse(this.responseText); +// var div = document.getElementById("notebooks-menu"); +// var ul = document.createElement("ul"); +// ul.classList.add("vertical","list-style-none"); +// div.appendChild(ul); +// for(var i in data) { +// var li = document.createElement("li"); +// var a = document.createElement("a"); +// a.setAttribute("href", data[i]['json_absolute_url']); +// a.innerHTML = data[i]['name']; +// li.append(a); +// ul.append(li); +// } +// var li = document.createElement("li"); +// var a = document.createElement("a"); +// a.setAttribute("href", '/user/{{user.username}}/notebooks/'); +// a.innerHTML = "View all" +// li.append(a); +// ul.append(li); +//} +// +// +//// getJSON("{%url 'notebook-api-list' %}", buildNotebookMenu); + diff --git a/scripts/overlay.js b/scripts/src/overlay.js index b40d911..b40d911 100644 --- a/scripts/overlay.js +++ b/scripts/src/overlay.js diff --git a/scripts/util.js b/scripts/src/util.js index 99a5ef3..3a4efc4 100644 --- a/scripts/util.js +++ b/scripts/src/util.js @@ -1,21 +1,43 @@ +function getJSON(url, callback) { + var request = new XMLHttpRequest(); + request.addEventListener("load", callback); + request.open('GET', url, true); + request.onload = function() { + if (request.status >= 200 && request.status < 400) { + //console.log(request.responseText); + } else { + console.log("server error"); + } + }; + request.onerror = function() { + console.log("error on request"); + }; + request.send(); +} + function edit_note(btn, title, qcontainer, quill, url){ - console.log(editing); - var formElement = document.querySelector("form"); - if (editing === false) { + var formElement = document.getElementById("note-edit-form"); + if (window.editing === false) { title.setAttribute("contenteditable", true); title.classList.add('highlight') qcontainer.classList.remove('inactive') quill.enable(true); btn.innerHTML = "Save" - editing = true; + btn.classList.add("save"); + window.editing = true; + window.titlecontents = title.innerHTML } else { - if (window.quillchange === true) { + if (window.quillchange === true || window.titlecontents != title.innerHTML) { var form_note_title = document.getElementById('id_title'); var note_html = document.getElementById('id_body_html'); + var note_text = document.getElementById('id_body_text'); var note_qjson = document.getElementById('id_body_qjson'); - form_note_title.value = title.innerHTML; + var new_title = document.getElementById('id_title'); + new_title.value = title.innerHTML; note_html.innerHTML = quill.root.innerHTML; + note_text.innerHTML = quill.getText(); note_qjson.innerHTML = JSON.stringify(quill.getContents()); + console.log(note_text); var request = new XMLHttpRequest(); request.open("PATCH", url); var csrftoken = Cookies.get('csrftoken'); @@ -39,6 +61,7 @@ function edit_note(btn, title, qcontainer, quill, url){ qcontainer.classList.add('inactive'); quill.enable(false); btn.innerHTML = "Edit" + btn.classList.remove("save"); document.body.focus(); editing = false; } |