Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

speeddial

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

speeddial - npm Package Compare versions

Comparing version 0.2.4 to 0.2.6

563

dist/speeddial.js
/**
* speeddial - Speed dial button inspired by Google Material design
*
* @version v0.2.4
* @version v0.2.6
* @homepage https://github.com/iliketomatoes/speeddial

@@ -14,273 +14,386 @@ * @license MIT

(global.speeddial = factory());
}(this, function () { 'use strict';
}(this, (function () { 'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
};
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
/**
* Deep-extends an object with another object
*
* @param { Object } a The object that will be extended, then returned
* @param { Object } b The object that will extend the first paramter
* @return { Object }
*/
function extend(a, b) {
for (var key in b) {
if (b.hasOwnProperty(key)) {
if (_typeof(b[key]) === 'object' && b[key] !== null) {
a[key] = extend(a[key], b[key]);
} else {
a[key] = b[key];
}
}
}
return a;
var asyncGenerator = function () {
function AwaitValue(value) {
this.value = value;
}
/**
* Utility function that throws an error if querySelector returns null
*
* @param { String } selector
* @param { HTMLElement } context If not specified the default context is the
* whole document
* @return { HTMLElement }
*/
function getElement(selector, context) {
var where = context || document;
var element = where.querySelector(selector);
function AsyncGenerator(gen) {
var front, back;
function send(key, arg) {
return new Promise(function (resolve, reject) {
var request = {
key: key,
arg: arg,
resolve: resolve,
reject: reject,
next: null
};
if (back) {
back = back.next = request;
} else {
front = back = request;
resume(key, arg);
}
});
}
function resume(key, arg) {
try {
if (element === null) throw new Error('SpeedDial could not find any ' + selector);
var result = gen[key](arg);
var value = result.value;
if (value instanceof AwaitValue) {
Promise.resolve(value.value).then(function (arg) {
resume("next", arg);
}, function (arg) {
resume("throw", arg);
});
} else {
settle(result.done ? "return" : "normal", result.value);
}
} catch (err) {
console.error(err.message);
} finally {
return element;
settle("throw", err);
}
}
function settle(type, value) {
switch (type) {
case "return":
front.resolve({
value: value,
done: true
});
break;
case "throw":
front.reject(value);
break;
default:
front.resolve({
value: value,
done: false
});
break;
}
front = front.next;
if (front) {
resume(front.key, front.arg);
} else {
back = null;
}
}
this._invoke = send;
if (typeof gen.return !== "function") {
this.return = undefined;
}
}
// Default settings
var defaults = {
if (typeof Symbol === "function" && Symbol.asyncIterator) {
AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
return this;
};
}
// The actual speed dial button default class
button: '.speed-dial__btn',
AsyncGenerator.prototype.next = function (arg) {
return this._invoke("next", arg);
};
// Default list of options class
list: '.speed-dial__list',
AsyncGenerator.prototype.throw = function (arg) {
return this._invoke("throw", arg);
};
// Default list of options direction
direction: 'up'
AsyncGenerator.prototype.return = function (arg) {
return this._invoke("return", arg);
};
var SpeedDial = {
/**
* Method called for initializing a new instance of SpeedDial
*
* @param { String } selector This is the selector
* of the speed dial button container
* @param { Object } options Object to override the default settings
*/
init: function init(selector, options) {
return {
wrap: function (fn) {
return function () {
return new AsyncGenerator(fn.apply(this, arguments));
};
},
await: function (value) {
return new AwaitValue(value);
}
};
}();
// Override defauls
this.settings = extend(defaults, options);
/**
* Deep-extends an object with another object
*
* @param { Object } a The object that will be extended, then returned
* @param { Object } b The object that will extend the first paramter
* @return { Object }
*/
function extend(a, b) {
for (var key in b) {
if (b.hasOwnProperty(key)) {
if (_typeof(b[key]) === 'object' && b[key] !== null) {
a[key] = extend(a[key], b[key]);
} else {
a[key] = b[key];
}
}
}
return a;
}
/**
* Get the HTMLElement which contains both the button
* and the list of options
*/
this.container = getElement(selector);
/**
* Utility function that throws an error if querySelector returns null
*
* @param { String } selector
* @param { HTMLElement } context If not specified the default context is the
* whole document
* @return { HTMLElement }
*/
function getElement(selector, context) {
var where = context || document;
var element = where.querySelector(selector);
try {
if (element === null) throw new Error('SpeedDial could not find any ' + selector);
} catch (err) {
console.error(err.message);
} finally {
return element;
}
}
if (this.container) {
this.bindEvents();
this.setDirection(this.settings.direction);
}
},
// Default settings
var defaults = {
/**
* Get the container
*
* @return { HTMLElement }
*/
getContainer: function getContainer() {
return this.container;
},
// The actual speed dial button default class
button: '.speed-dial__btn',
/**
* Get the button which triggers the list of options to open/close
*
* @return { HTMLElement }
*/
getButton: function getButton() {
return getElement(this.settings.button, this.container);
},
// Default list of options class
list: '.speed-dial__list',
/**
* Get the list which contains the speed dial options
*
* @return { HTMLElement }
*/
getList: function getList() {
return getElement(this.settings.list, this.container);
},
// Default list of options direction
direction: 'up'
};
// Add click listener to the speed-dial button
bindEvents: function bindEvents() {
var btn = this.getButton();
btn.addEventListener('click', this.clickHandler.bind(this));
},
var SpeedDial = {
/**
* Method called for initializing a new instance of SpeedDial
*
* @param { String } selector This is the selector
* of the speed dial button container
* @param { Object } options Object to override the default settings
*/
init: function init(selector, options) {
// Method called when speed-dial button is clicked
clickHandler: function clickHandler() {
var listEl = this.getList();
// Override defauls
this.settings = extend(defaults, options);
if (listEl.classList.contains('is-visible')) {
// Close the list of options
listEl.classList.remove('is-visible');
} else {
// Open the list of options
listEl.classList.add('is-visible');
}
},
/**
* Get the HTMLElement which contains both the button
* and the list of options
*/
this.container = getElement(selector);
// Close the list of options
close: function close() {
var listEl = this.getList();
listEl.classList.remove('is-visible');
},
if (this.container) {
this.bindEvents();
this.setDirection(this.settings.direction);
}
},
// Open the list of options
open: function open() {
var listEl = this.getList();
listEl.classList.add('is-visible');
},
/**
* Get the container
*
* @return { HTMLElement }
*/
getContainer: function getContainer() {
return this.container;
},
/**
* Speed dial list of options can be viewed in 4 different directions:
* 'up', 'down', 'left', 'right'
* The CSS class responsible to handle the list of options direction is added
* to the container
*
* @param { String } direction
*/
setDirection: function setDirection(direction) {
/**
* Get the button which triggers the list of options to open/close
*
* @return { HTMLElement }
*/
getButton: function getButton() {
return getElement(this.settings.button, this.container);
},
// Clean the classList first
this.container.classList.remove('speed-dial--' + this.settings.direction);
/**
* Get the list which contains the speed dial options
*
* @return { HTMLElement }
*/
getList: function getList() {
return getElement(this.settings.list, this.container);
},
switch (direction) {
case 'up':
this.container.classList.add('speed-dial--up');
break;
case 'down':
this.container.classList.add('speed-dial--down');
break;
case 'left':
this.container.classList.add('speed-dial--left');
break;
case 'right':
this.container.classList.add('speed-dial--right');
break;
default:
this.container.classList.add('speed-dial--up');
break;
}
// Add click listener to the speed-dial button
bindEvents: function bindEvents() {
var btn = this.getButton();
btn.addEventListener('click', this.clickHandler.bind(this));
},
// Update the settings object with the new direction
this.settings.direction = direction;
// Method called when speed-dial button is clicked
clickHandler: function clickHandler() {
var listEl = this.getList();
// Call an helper to set some style with Javascript
this.styleUpdate();
},
if (listEl.classList.contains('is-visible')) {
// Close the list of options
listEl.classList.remove('is-visible');
} else {
// Open the list of options
listEl.classList.add('is-visible');
}
},
// @return { String }
getDirection: function getDirection() {
return this.settings.direction;
},
// Close the list of options
close: function close() {
var listEl = this.getList();
listEl.classList.remove('is-visible');
},
/**
* Left and right directions require some style computation
* in order to properly show the list of options
*/
styleUpdate: function styleUpdate() {
var listEl = this.getList();
var direction = this.getDirection();
// Open the list of options
open: function open() {
var listEl = this.getList();
listEl.classList.add('is-visible');
},
switch (direction) {
case 'up':
break;
case 'down':
break;
case 'left':
listEl.style.left = -listEl.offsetWidth + 'px';
break;
case 'right':
listEl.style.right = -listEl.offsetWidth + 'px';
break;
default:
break;
}
}
/**
* Speed dial list of options can be viewed in 4 different directions:
* 'up', 'down', 'left', 'right'
* The CSS class responsible to handle the list of options direction is added
* to the container
*
* @param { String } direction
*/
setDirection: function setDirection(direction) {
};
// Clean the classList first
this.container.classList.remove('speed-dial--' + this.settings.direction);
/**
* This is the function invoked for creating a new instance of speed dial button
*
* @param { String } selector This is the selector
* of the speed dial button container
* @param { Object } options Object to override the default settings
* @return { Object } Returns an object which exposes the
* SpeedDial public methods
*/
function index(selector, options) {
switch (direction) {
case 'up':
this.container.classList.add('speed-dial--up');
break;
case 'down':
this.container.classList.add('speed-dial--down');
break;
case 'left':
this.container.classList.add('speed-dial--left');
break;
case 'right':
this.container.classList.add('speed-dial--right');
break;
default:
this.container.classList.add('speed-dial--up');
break;
}
var sd = Object.create(SpeedDial);
// Update the settings object with the new direction
this.settings.direction = direction;
sd.init(selector, options);
// Call an helper to set some style with Javascript
this.styleUpdate();
},
function getContainer() {
return sd.getContainer();
}
// @return { String }
getDirection: function getDirection() {
return this.settings.direction;
},
function getButton() {
return sd.getButton();
}
/**
* Left and right directions require some style computation
* in order to properly show the list of options
*/
styleUpdate: function styleUpdate() {
var listEl = this.getList();
var direction = this.getDirection();
function getList() {
return sd.getList();
}
switch (direction) {
case 'up':
break;
case 'down':
break;
case 'left':
listEl.style.left = -listEl.offsetWidth + 'px';
break;
case 'right':
listEl.style.right = -listEl.offsetWidth + 'px';
break;
default:
break;
}
}
function getDirection() {
return sd.getDirection();
}
};
function setDirection(direction) {
return sd.setDirection(direction);
}
/**
* This is the function invoked for creating a new instance of speed dial button
*
* @param { String } selector This is the selector
* of the speed dial button container
* @param { Object } options Object to override the default settings
* @return { Object } Returns an object which exposes the
* SpeedDial public methods
*/
function index(selector, options) {
function close() {
return sd.close();
}
var sd = Object.create(SpeedDial);
function open() {
return sd.open();
}
sd.init(selector, options);
// Return an object in a pseudo-module pattern way
return {
getContainer: getContainer,
getButton: getButton,
getList: getList,
getDirection: getDirection,
setDirection: setDirection,
close: close,
open: open
};
}
function getContainer() {
return sd.getContainer();
}
return index;
function getButton() {
return sd.getButton();
}
}));
function getList() {
return sd.getList();
}
function getDirection() {
return sd.getDirection();
}
function setDirection(direction) {
return sd.setDirection(direction);
}
function close() {
return sd.close();
}
function open() {
return sd.open();
}
// Return an object in a pseudo-module pattern way
return {
getContainer: getContainer,
getButton: getButton,
getList: getList,
getDirection: getDirection,
setDirection: setDirection,
close: close,
open: open
};
}
return index;
})));
//# sourceMappingURL=speeddial.js.map

@@ -1,1 +0,1 @@

(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):global.speeddial=factory()})(this,function(){"use strict";var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol?"symbol":typeof obj};function extend(a,b){for(var key in b){if(b.hasOwnProperty(key)){if(_typeof(b[key])==="object"&&b[key]!==null){a[key]=extend(a[key],b[key])}else{a[key]=b[key]}}}return a}function getElement(selector,context){var where=context||document;var element=where.querySelector(selector);try{if(element===null)throw new Error("SpeedDial could not find any "+selector)}catch(err){console.error(err.message)}finally{return element}}var defaults={button:".speed-dial__btn",list:".speed-dial__list",direction:"up"};var SpeedDial={init:function init(selector,options){this.settings=extend(defaults,options);this.container=getElement(selector);if(this.container){this.bindEvents();this.setDirection(this.settings.direction)}},getContainer:function getContainer(){return this.container},getButton:function getButton(){return getElement(this.settings.button,this.container)},getList:function getList(){return getElement(this.settings.list,this.container)},bindEvents:function bindEvents(){var btn=this.getButton();btn.addEventListener("click",this.clickHandler.bind(this))},clickHandler:function clickHandler(){var listEl=this.getList();if(listEl.classList.contains("is-visible")){listEl.classList.remove("is-visible")}else{listEl.classList.add("is-visible")}},close:function close(){var listEl=this.getList();listEl.classList.remove("is-visible")},open:function open(){var listEl=this.getList();listEl.classList.add("is-visible")},setDirection:function setDirection(direction){this.container.classList.remove("speed-dial--"+this.settings.direction);switch(direction){case"up":this.container.classList.add("speed-dial--up");break;case"down":this.container.classList.add("speed-dial--down");break;case"left":this.container.classList.add("speed-dial--left");break;case"right":this.container.classList.add("speed-dial--right");break;default:this.container.classList.add("speed-dial--up");break}this.settings.direction=direction;this.styleUpdate()},getDirection:function getDirection(){return this.settings.direction},styleUpdate:function styleUpdate(){var listEl=this.getList();var direction=this.getDirection();switch(direction){case"up":break;case"down":break;case"left":listEl.style.left=-listEl.offsetWidth+"px";break;case"right":listEl.style.right=-listEl.offsetWidth+"px";break;default:break}}};function index(selector,options){var sd=Object.create(SpeedDial);sd.init(selector,options);function getContainer(){return sd.getContainer()}function getButton(){return sd.getButton()}function getList(){return sd.getList()}function getDirection(){return sd.getDirection()}function setDirection(direction){return sd.setDirection(direction)}function close(){return sd.close()}function open(){return sd.open()}return{getContainer:getContainer,getButton:getButton,getList:getList,getDirection:getDirection,setDirection:setDirection,close:close,open:open}}return index});
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):global.speeddial=factory()})(this,function(){"use strict";var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj};var asyncGenerator=function(){function AwaitValue(value){this.value=value}function AsyncGenerator(gen){var front,back;function send(key,arg){return new Promise(function(resolve,reject){var request={key:key,arg:arg,resolve:resolve,reject:reject,next:null};if(back){back=back.next=request}else{front=back=request;resume(key,arg)}})}function resume(key,arg){try{var result=gen[key](arg);var value=result.value;if(value instanceof AwaitValue){Promise.resolve(value.value).then(function(arg){resume("next",arg)},function(arg){resume("throw",arg)})}else{settle(result.done?"return":"normal",result.value)}}catch(err){settle("throw",err)}}function settle(type,value){switch(type){case"return":front.resolve({value:value,done:true});break;case"throw":front.reject(value);break;default:front.resolve({value:value,done:false});break}front=front.next;if(front){resume(front.key,front.arg)}else{back=null}}this._invoke=send;if(typeof gen.return!=="function"){this.return=undefined}}if(typeof Symbol==="function"&&Symbol.asyncIterator){AsyncGenerator.prototype[Symbol.asyncIterator]=function(){return this}}AsyncGenerator.prototype.next=function(arg){return this._invoke("next",arg)};AsyncGenerator.prototype.throw=function(arg){return this._invoke("throw",arg)};AsyncGenerator.prototype.return=function(arg){return this._invoke("return",arg)};return{wrap:function(fn){return function(){return new AsyncGenerator(fn.apply(this,arguments))}},await:function(value){return new AwaitValue(value)}}}();function extend(a,b){for(var key in b){if(b.hasOwnProperty(key)){if(_typeof(b[key])==="object"&&b[key]!==null){a[key]=extend(a[key],b[key])}else{a[key]=b[key]}}}return a}function getElement(selector,context){var where=context||document;var element=where.querySelector(selector);try{if(element===null)throw new Error("SpeedDial could not find any "+selector)}catch(err){console.error(err.message)}finally{return element}}var defaults={button:".speed-dial__btn",list:".speed-dial__list",direction:"up"};var SpeedDial={init:function init(selector,options){this.settings=extend(defaults,options);this.container=getElement(selector);if(this.container){this.bindEvents();this.setDirection(this.settings.direction)}},getContainer:function getContainer(){return this.container},getButton:function getButton(){return getElement(this.settings.button,this.container)},getList:function getList(){return getElement(this.settings.list,this.container)},bindEvents:function bindEvents(){var btn=this.getButton();btn.addEventListener("click",this.clickHandler.bind(this))},clickHandler:function clickHandler(){var listEl=this.getList();if(listEl.classList.contains("is-visible")){listEl.classList.remove("is-visible")}else{listEl.classList.add("is-visible")}},close:function close(){var listEl=this.getList();listEl.classList.remove("is-visible")},open:function open(){var listEl=this.getList();listEl.classList.add("is-visible")},setDirection:function setDirection(direction){this.container.classList.remove("speed-dial--"+this.settings.direction);switch(direction){case"up":this.container.classList.add("speed-dial--up");break;case"down":this.container.classList.add("speed-dial--down");break;case"left":this.container.classList.add("speed-dial--left");break;case"right":this.container.classList.add("speed-dial--right");break;default:this.container.classList.add("speed-dial--up");break}this.settings.direction=direction;this.styleUpdate()},getDirection:function getDirection(){return this.settings.direction},styleUpdate:function styleUpdate(){var listEl=this.getList();var direction=this.getDirection();switch(direction){case"up":break;case"down":break;case"left":listEl.style.left=-listEl.offsetWidth+"px";break;case"right":listEl.style.right=-listEl.offsetWidth+"px";break;default:break}}};function index(selector,options){var sd=Object.create(SpeedDial);sd.init(selector,options);function getContainer(){return sd.getContainer()}function getButton(){return sd.getButton()}function getList(){return sd.getList()}function getDirection(){return sd.getDirection()}function setDirection(direction){return sd.setDirection(direction)}function close(){return sd.close()}function open(){return sd.open()}return{getContainer:getContainer,getButton:getButton,getList:getList,getDirection:getDirection,setDirection:setDirection,close:close,open:open}}return index});
{
"name": "speeddial",
"version": "0.2.4",
"version": "0.2.6",
"description": "Speed dial button inspired by Google Material design",

@@ -46,3 +46,3 @@ "main": "dist/speeddial.js",

"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^1.0.1",
"karma-chrome-launcher": "^2.0.0",
"karma-fixture": "^0.2.6",

@@ -53,3 +53,3 @@ "karma-html2js-preprocessor": "^1.0.0",

"karma-phantomjs-launcher": "^1.0.1",
"mocha": "^2.5.3",
"mocha": "^3.0.2",
"node-sass": "^3.8.0",

@@ -59,4 +59,5 @@ "nodemon": "^1.9.2",

"rollup-plugin-babel": "^2.5.1",
"rollup-watch": "^2.4.0"
"rollup-watch": "^2.4.0",
"uglify-js": "^2.7.4"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc