basicplaceholder
Advanced tools
Comparing version 1.1.2 to 1.2.0
{ | ||
"name": "basicPlaceholder", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"authors": [ | ||
@@ -5,0 +5,0 @@ "Tobias Reich <tobias.reich.ich@gmail.com>" |
@@ -1,1 +0,1 @@ | ||
"use strict";window.basicPlaceholder={errorText:null,warningText:null,init:function(){var e=void 0===arguments[0]?[]:arguments[0],r=void 0===arguments[1]?{}:arguments[1];basicPlaceholder.errorText=r.errorText||"Invalid",basicPlaceholder.warningText=r.warningText||"Invalid";for(var a=0;a<e.length;++a){var l=e[a];basicPlaceholder._add(l),l.onclick=basicPlaceholder._onChange,l.onkeyup=basicPlaceholder._onChange}return!0},_isError:function(e){var r=e.getAttribute("data-basicPlaceholder-error");return null!==r&&"false"!==r?!0:!1},_isWarning:function(e){var r=e.getAttribute("data-basicPlaceholder-warning");return null!==r&&"false"!==r?!0:!1},_isPersistent:function(e){var r=e.getAttribute("data-basicPlaceholder-persistent");return null!==r&&"false"!==r?!0:!1},_onChange:function(){var e=this,r=basicPlaceholder._isError(e),a=basicPlaceholder._isWarning(e);r===!0&&basicPlaceholder._remove(e),a===!0&&basicPlaceholder._remove(e),e.value.length>0?basicPlaceholder._add(e):basicPlaceholder._remove(e)},_add:function(e){var r=null,a=e.getAttribute("data-basicPlaceholder-text"),l=e.parentElement,t=basicPlaceholder._isError(e),n=basicPlaceholder._isWarning(e),i=basicPlaceholder._isPersistent(e),c=null;return 0===e.value.length&&i===!1&&t===!1&&n===!1?!1:"true"===e.getAttribute("data-basicPlaceholder")?!1:(r=t===!0?basicPlaceholder.errorText:n===!0?basicPlaceholder.warningText:e.getAttribute("placeholder")||null,null!==a&&a.length>0&&(r=a),null===r?!1:(c=basicPlaceholder._render(r),l.insertAdjacentHTML("beforeend",c),e.setAttribute("data-basicPlaceholder",!0),!0))},_remove:function(e){var r=e.parentElement,a=r.querySelector(".basicPlaceholder__placeholder"),l=basicPlaceholder._isPersistent(e);return l===!0?!1:null===a?!1:(a.parentNode.removeChild(a),e.removeAttribute("data-basicPlaceholder-error"),e.removeAttribute("data-basicPlaceholder-warning"),e.removeAttribute("data-basicPlaceholder",!1),!0)},_render:function(){var e=void 0===arguments[0]?"":arguments[0];return'<div class="basicPlaceholder__placeholder">'+e+"</a>"}}; | ||
"use strict";!function(e,t){"undefined"!=typeof module&&module.exports?module.exports=t():"function"==typeof define&&define.amd?define(t):window[e]=t()}("basicPlaceholder",function(){var e=null,t=null,r=function(){var r=void 0===arguments[0]?[]:arguments[0],a=void 0===arguments[1]?{}:arguments[1];e=a.errorText||"Invalid",t=a.warningText||"Invalid";for(var n=0;n<r.length;++n){var l=r[n];i(l),l.onclick=u,l.onkeyup=u}return!0},a=function(e){var t=e.getAttribute("data-basicPlaceholder-error");return null!==t&&"false"!==t?!0:!1},n=function(e){var t=e.getAttribute("data-basicPlaceholder-warning");return null!==t&&"false"!==t?!0:!1},l=function(e){var t=e.getAttribute("data-basicPlaceholder-persistent");return null!==t&&"false"!==t?!0:!1},u=function(){var e=this,t=a(e),r=n(e);t===!0&&o(e),r===!0&&o(e),e.value.length>0?i(e):o(e)},i=function(r){var u=null,i=r.getAttribute("data-basicPlaceholder-text"),o=r.parentElement,d=a(r),s=n(r),b=l(r),v=null;return 0===r.value.length&&b===!1&&d===!1&&s===!1?!1:"true"===r.getAttribute("data-basicPlaceholder")?!1:(u=d===!0?e:s===!0?t:r.getAttribute("placeholder")||null,null!==i&&i.length>0&&(u=i),null===u?!1:(v=c(u),o.insertAdjacentHTML("beforeend",v),r.setAttribute("data-basicPlaceholder",!0),!0))},o=function(e){var t=e.parentElement,r=t.querySelector(".basicPlaceholder__placeholder"),a=l(e);return a===!0?!1:null===r?!1:(r.parentNode.removeChild(r),e.removeAttribute("data-basicPlaceholder-error"),e.removeAttribute("data-basicPlaceholder-warning"),e.removeAttribute("data-basicPlaceholder"),!0)},c=function(){var e=void 0===arguments[0]?"":arguments[0];return'<div class="basicPlaceholder__placeholder">'+e+"</a>"};return{init:r}}); |
@@ -1,25 +0,47 @@ | ||
var gulp = require('gulp'), | ||
plugins = require('gulp-load-plugins')(); | ||
var name = require('./package.json').moduleName, | ||
fs = require('fs'), | ||
gulp = require('gulp'), | ||
plugins = require('gulp-load-plugins')() | ||
gulp.task('styles', function () { | ||
var head = fs.readFileSync('./node_modules/@electerious/modulizer/head.js', { encoding: 'utf8' }), | ||
foot = fs.readFileSync('./node_modules/@electerious/modulizer/foot.js', { encoding: 'utf8' }) | ||
var catchError = function(err) { | ||
console.log(err.toString()) | ||
this.emit('end') | ||
} | ||
gulp.task('styles', function() { | ||
gulp.src('./src/styles/main.scss') | ||
.pipe(plugins.sass()) | ||
.pipe(plugins.concat('basicPlaceholder.min.css', {newLine: "\n"})) | ||
.pipe(plugins.autoprefixer('last 2 version', '> 1%')) | ||
.pipe(plugins.minifyCss()) | ||
.pipe(gulp.dest('./dist')); | ||
.pipe(plugins.sass()) | ||
.pipe(plugins.concat(name + '.min.css', { newLine: "\n" })) | ||
.pipe(plugins.autoprefixer('last 2 version', '> 1%')) | ||
.pipe(plugins.minifyCss()) | ||
.pipe(gulp.dest('./dist')) | ||
}); | ||
}) | ||
gulp.task('scripts', function () { | ||
gulp.task('scripts', function() { | ||
gulp.src('./src/scripts/*.js') | ||
.pipe(plugins.babel()) | ||
.pipe(plugins.concat('basicPlaceholder.min.js', {newLine: "\n"})) | ||
.pipe(plugins.uglify()) | ||
.pipe(gulp.dest('./dist')); | ||
.pipe(plugins.header(head, { name: name })) | ||
.pipe(plugins.footer(foot)) | ||
.pipe(plugins.babel()) | ||
.pipe(plugins.concat(name + '.min.js', { newLine: "\n" })) | ||
.pipe(plugins.uglify()) | ||
.on('error', catchError) | ||
.pipe(gulp.dest('./dist')) | ||
}); | ||
}) | ||
gulp.task('default', ['styles', 'scripts']); | ||
gulp.task('default', ['styles', 'scripts']) | ||
gulp.task('watch', ['styles', 'scripts'], function() { | ||
gulp.watch('./src/styles/*.scss', ['styles']) | ||
gulp.watch('./src/scripts/*.js', ['scripts']) | ||
}) |
{ | ||
"name": "basicplaceholder", | ||
"version": "1.1.2", | ||
"moduleName": "basicPlaceholder", | ||
"version": "1.2.0", | ||
"authors": [ | ||
@@ -30,2 +31,3 @@ "Tobias Reich <tobias.reich.ich@gmail.com>" | ||
"devDependencies": { | ||
"@electerious/modulizer": "^1.0.1", | ||
"gulp": "^3.9.0", | ||
@@ -35,4 +37,6 @@ "gulp-autoprefixer": "2.3.1", | ||
"gulp-concat": "^2.5.2", | ||
"gulp-load-plugins": "^0.10.0", | ||
"gulp-minify-css": "^1.1.5", | ||
"gulp-footer": "^1.0.5", | ||
"gulp-header": "^1.2.2", | ||
"gulp-load-plugins": "^1.0.0-rc", | ||
"gulp-minify-css": "^1.1.6", | ||
"gulp-sass": "^2.0.1", | ||
@@ -39,0 +43,0 @@ "gulp-uglify": "^1.2.0", |
@@ -13,2 +13,8 @@ # basicPlaceholder | ||
## Features | ||
- Works in all modern browsers | ||
- Written in Vanilla JS | ||
- CommonJS and AMD support | ||
## Installation | ||
@@ -15,0 +21,0 @@ |
@@ -1,134 +0,132 @@ | ||
window.basicPlaceholder = { | ||
var errorText = null, | ||
warningText = null | ||
errorText: null, | ||
warningText: null, | ||
const init = function(inputs = [], opts = {}) { | ||
init(inputs = [], opts = {}) { | ||
errorText = opts.errorText || 'Invalid' | ||
warningText = opts.warningText || 'Invalid' | ||
basicPlaceholder.errorText = opts.errorText || 'Invalid' | ||
basicPlaceholder.warningText = opts.warningText || 'Invalid' | ||
for (let i = 0; i < inputs.length; ++i) { | ||
for (let i = 0; i < inputs.length; ++i) { | ||
let input = inputs[i] | ||
let input = inputs[i] | ||
// Add placeholder to all existing inputs | ||
add(input) | ||
// Add placeholder to all existing inputs | ||
basicPlaceholder._add(input) | ||
// Update placeholder | ||
input.onclick = onChange | ||
input.onkeyup = onChange | ||
// Update placeholder | ||
input.onclick = basicPlaceholder._onChange | ||
input.onkeyup = basicPlaceholder._onChange | ||
} | ||
} | ||
return true | ||
return true | ||
} | ||
}, | ||
const isError = function(input) { | ||
_isError(input) { | ||
var error = input.getAttribute('data-basicPlaceholder-error') | ||
var error = input.getAttribute('data-basicPlaceholder-error') | ||
if (error!==null && error!=='false') return true | ||
else return false | ||
if (error!==null&&error!=='false') return true | ||
else return false | ||
} | ||
}, | ||
const isWarning = function(input) { | ||
_isWarning(input) { | ||
var warning = input.getAttribute('data-basicPlaceholder-warning') | ||
var warning = input.getAttribute('data-basicPlaceholder-warning') | ||
if (warning!==null && warning!=='false') return true | ||
else return false | ||
if (warning!==null&&warning!=='false') return true | ||
else return false | ||
} | ||
}, | ||
const isPersistent = function(input) { | ||
_isPersistent(input) { | ||
var persistent = input.getAttribute('data-basicPlaceholder-persistent') | ||
var persistent = input.getAttribute('data-basicPlaceholder-persistent') | ||
if (persistent!==null && persistent!=='false') return true | ||
else return false | ||
if (persistent!==null&&persistent!=='false') return true | ||
else return false | ||
} | ||
}, | ||
const onChange = function() { | ||
_onChange() { | ||
var input = this, | ||
_isError = isError(input), | ||
_isWarning = isWarning(input) | ||
var input = this, | ||
isError = basicPlaceholder._isError(input), | ||
isWarning = basicPlaceholder._isWarning(input) | ||
// Remove error placeholder | ||
if (_isError===true) remove(input) | ||
if (_isWarning===true) remove(input) | ||
// Remove error placeholder | ||
if (isError===true) basicPlaceholder._remove(input) | ||
if (isWarning===true) basicPlaceholder._remove(input) | ||
// Show basicPlaceholder when input contains chars | ||
if (input.value.length>0) add(input) | ||
else remove(input) | ||
// Show basicPlaceholder when input contains chars | ||
if (input.value.length>0) basicPlaceholder._add(input) | ||
else basicPlaceholder._remove(input) | ||
} | ||
}, | ||
const add = function(input) { | ||
_add(input) { | ||
var text = null, | ||
customText = input.getAttribute('data-basicPlaceholder-text'), | ||
wrapper = input.parentElement, | ||
_isError = isError(input), | ||
_isWarning = isWarning(input), | ||
_isPersistent = isPersistent(input), | ||
html = null | ||
var text = null, | ||
customText = input.getAttribute('data-basicPlaceholder-text'), | ||
wrapper = input.parentElement, | ||
isError = basicPlaceholder._isError(input), | ||
isWarning = basicPlaceholder._isWarning(input), | ||
isPersistent = basicPlaceholder._isPersistent(input), | ||
html = null | ||
// Do not add a placeholder when ... | ||
// 1) input empty, not persistent, not an error and not a warning | ||
// 2) a placeholder has already been added to the input | ||
if (input.value.length===0 && _isPersistent===false && _isError===false && _isWarning===false) return false | ||
if (input.getAttribute('data-basicPlaceholder')==='true') return false | ||
// Do not add a placeholder when ... | ||
// 1) input empty, not persistent, not an error and not a warning | ||
// 2) a placeholder has already been added to the input | ||
if (input.value.length===0&&isPersistent===false&&isError===false&&isWarning===false) return false | ||
if (input.getAttribute('data-basicPlaceholder')==='true') return false | ||
// Set placeholder text | ||
if (_isError===true) text = errorText | ||
else if (_isWarning===true) text = warningText | ||
else text = input.getAttribute('placeholder') || null | ||
// Set placeholder text | ||
if (isError===true) text = basicPlaceholder.errorText | ||
else if (isWarning===true) text = basicPlaceholder.warningText | ||
else text = input.getAttribute('placeholder') || null | ||
// Set custom text when available | ||
if (customText!==null && customText.length>0) text = customText | ||
// Set custom text when available | ||
if (customText!==null&&customText.length>0) text = customText | ||
// Prevent undefined title | ||
if (text===null) return false | ||
// Prevent undefined title | ||
if (text===null) return false | ||
// Render and add HTML | ||
html = render(text) | ||
wrapper.insertAdjacentHTML('beforeend', html) | ||
// Render and add HTML | ||
html = basicPlaceholder._render(text) | ||
wrapper.insertAdjacentHTML('beforeend', html) | ||
// Set attribute | ||
input.setAttribute('data-basicPlaceholder', true) | ||
// Set attribute | ||
input.setAttribute('data-basicPlaceholder', true) | ||
return true | ||
return true | ||
} | ||
}, | ||
const remove = function(input) { | ||
_remove(input) { | ||
var wrapper = input.parentElement, | ||
placeholder = wrapper.querySelector('.basicPlaceholder__placeholder'), | ||
_isPersistent = isPersistent(input) | ||
var wrapper = input.parentElement, | ||
placeholder = wrapper.querySelector('.basicPlaceholder__placeholder'), | ||
isPersistent = basicPlaceholder._isPersistent(input) | ||
if (_isPersistent===true) return false | ||
if (placeholder===null) return false | ||
if (isPersistent===true) return false | ||
if (placeholder===null) return false | ||
placeholder.parentNode.removeChild(placeholder) | ||
placeholder.parentNode.removeChild(placeholder) | ||
input.removeAttribute('data-basicPlaceholder-error') | ||
input.removeAttribute('data-basicPlaceholder-warning') | ||
input.removeAttribute('data-basicPlaceholder') | ||
input.removeAttribute('data-basicPlaceholder-error') | ||
input.removeAttribute('data-basicPlaceholder-warning') | ||
input.removeAttribute('data-basicPlaceholder', false) | ||
return true | ||
return true | ||
} | ||
}, | ||
const render = function(text = '') { | ||
_render(text = '') { | ||
return `<div class="basicPlaceholder__placeholder">${ text }</a>` | ||
return `<div class="basicPlaceholder__placeholder">${ text }</a>` | ||
} | ||
} | ||
} | ||
return { init } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19056
14
145
93
12
1