Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow library to be inserted in HEAD tag and lazily loaded #18

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/colr_pickr.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions build/colr_pickr.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const concatJS = require('gulp-concat');
const uglifyJS = require('gulp-uglify-es').default;
const concatCSS = require('gulp-concat-css');
const uglifyCSS = require('gulp-uglifycss');
const inject = require('gulp-inject-string');
const sass = require('gulp-sass');
sass.compiler = require('node-sass');

Expand All @@ -20,6 +21,8 @@ sass.compiler = require('node-sass');
gulp.task('devScripts', async function () {
gulp.src(['./src/js/setup.js', './src/js/*.js'])
.pipe(concatJS('colr_pickr.js'))
.pipe(inject.prepend('document.addEventListener("DOMContentLoaded", function () {'))
.pipe(inject.append('window.ColorPicker = ColorPicker;window.colorPickerComp = colorPickerComp;});'))
.pipe(gulp.dest('./build'));
});

Expand All @@ -44,6 +47,8 @@ gulp.task('productionScripts', async function () {
gulp.src(['./src/js/setup.js', './src/js/*.js'])
.pipe(concatJS('colr_pickr.min.js'))
.pipe(uglifyJS())
.pipe(inject.prepend('document.addEventListener("DOMContentLoaded", function () {'))
.pipe(inject.append('window.ColorPicker = ColorPicker;window.colorPickerComp = colorPickerComp;});'))
.pipe(gulp.dest('./build'));
});

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"browser": "build/colr_pickr.min.js",
"license": "MIT",
"scripts": {
"devBuild": "gulp devBuild",
"devWatch": "gulp watch",
"build": "gulp productionBuild",
"doc": "jsdoc -c jsdoc.json",
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down Expand Up @@ -49,6 +51,7 @@
"gulp": "^4.0.2",
"gulp-concat": "^2.6.1",
"gulp-concat-css": "^3.1.0",
"gulp-inject-string": "^1.1.2",
"gulp-markdown": "^5.0.1",
"gulp-rimraf": "^1.0.0",
"gulp-sass": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/js/color_text_values.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ document.getElementById('switch_color_type').addEventListener('click', function
// Event to update the color when the user leaves the hex value box
document.getElementById('hex_input').addEventListener('blur', function () {
// Value
const hexInput = this.value;
const hexInput = this.value.toLowerCase();

// Check to see if the hex is formatted correctly
if (hexInput.match(/^#[0-9a-f]{3}([0-9a-f]{3})?([0-9a-f]{2})?$/)) {
Expand Down
36 changes: 35 additions & 1 deletion src/js/custom_color.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ document.getElementById('custom_colors_box').addEventListener('click', function

// Update
updatePicker();

// Show delete button
document.getElementById('custom_colors_del').style.display = 'inline-block';

}
});

Expand All @@ -38,6 +42,11 @@ colorPickerComp.addCustomColor = function () {
// Getting the color
const color = `hsla(${colorPickerComp.hue}, ${colorPickerComp.saturation}%, ${colorPickerComp.lightness}%, ${colorPickerComp.alpha})`;

// Check if color is already present
for (let i = 0; i < colorPickerComp.LSCustomColors[0].length; i++)
if (colorPickerComp.LSCustomColors[0][i] == color)
return;

// Creating the element
let customColorElem = document.createElement('BUTTON');
customColorElem.className = 'custom_colors_preview';
Expand All @@ -47,15 +56,36 @@ colorPickerComp.addCustomColor = function () {
document.getElementById('custom_colors_box').appendChild(customColorElem);

// Pushing the color to the top of the array
colorPickerComp.LSCustomColors[0].unshift(color);
colorPickerComp.LSCustomColors[0].push(color);

// Updating the local storage with the new custom color
try {
localStorage.setItem('custom_colors', JSON.stringify(colorPickerComp.LSCustomColors));
} catch (e) {}
};
document.getElementById('custom_colors_add').addEventListener('click', function () {
colorPickerComp.addCustomColor();
});

// Function to remove an existing custom color
colorPickerComp.removeCustomColor = function () {
// Update status of remove button
const color = `hsla(${colorPickerComp.hue}, ${colorPickerComp.saturation}%, ${colorPickerComp.lightness}%, ${colorPickerComp.alpha})`;

// Check if color is already present
let isCustomColor = false;
for (let i = 0; i < colorPickerComp.LSCustomColors[0].length; i++)
if (colorPickerComp.LSCustomColors[0][i] == color) {
let elem = document.getElementById('custom_colors_box').getElementsByClassName('custom_colors_preview')[i];
colorPickerComp.clearSingleCustomColor(elem);
document.getElementById('custom_colors_del').style.display = 'none';
return;
}
};
document.getElementById('custom_colors_del').addEventListener('click', function () {
colorPickerComp.removeCustomColor();
});

// Event to fire for a context menu
document.getElementById('custom_colors_box').addEventListener('contextmenu', function (event) {
// Making sure the users has selected a color preview
Expand Down Expand Up @@ -102,7 +132,9 @@ colorPickerComp.clearSingleCustomColor = function (element) {
}

// Updating the local storage
try {
localStorage.setItem('custom_colors', JSON.stringify(colorPickerComp.LSCustomColors));
} catch (e) {}

// Making sure the add color button is displaying
document.getElementById('custom_colors_add').style.display = 'inline-block';
Expand All @@ -124,7 +156,9 @@ colorPickerComp.clearAllCustomColors = function () {
}

// Updating the local storage
try {
localStorage.setItem('custom_colors', JSON.stringify(colorPickerComp.LSCustomColors));
} catch (e) {}

// Making sure the add color button is displaying
document.getElementById('custom_colors_add').style.display = 'inline-block';
Expand Down
137 changes: 0 additions & 137 deletions src/js/saturation_lightness_box.js

This file was deleted.

Loading