New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

anima-pop

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anima-pop - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

14

HISTORY.md

@@ -5,8 +5,16 @@ # History

## 1.0.0
## 1.1.0
`new` /pop First version.
`new` 重构,缩减依赖链,不再依赖`anima-widget`
## 1.0.3
`fixed` semver规范支持
## 1.0.1
* 替换为anima-yocto-lite
`change` 替换为anima-yocto-lite
## 1.0.0
`new` /pop First version.
{
"name": "anima-pop",
"version": "1.0.3",
"version": "1.1.0",
"description": "The best project ever.",

@@ -8,3 +8,4 @@ "homepage": "http://gitlab.alibaba-inc.com/animajs/pop",

"maintainers": [
"dxq613"
"dxq613",
"yuanfei.gyf"
],

@@ -31,3 +32,2 @@ "repository": {

"dependencies": {
"anima-widget": "1.1.4",
"anima-yocto-lite": "~1.1.0",

@@ -34,0 +34,0 @@ "import-style": "1.0.0"

@@ -1,117 +0,82 @@

/**
* @fileOverview 对齐,仅提供上下左右、中间的对齐
* @author dxq613
*/
var $ = require('anima-yocto-lite');
var $ = require('anima-yocto-lite');
var Align = function(){};
var Align = function(){
Align.ATTRS = {
/**
* 对齐方式
* @type {Object}
*/
align : null
}
};
Align.prototype= {
getAlignPoint : function(align){
var _self = this,
point = null;
align = align || _self.get('align');
if(align){
var offset = align.offset,
type = align.type,
offX = offset ? offset[0] : 0,
offY = offset ? offset[1] : 0,
vHight = $(window).height(),
height = _self.element.height(),
width = _self.element.width(),
vWidth = $(window).width();
Align.ATTRS = {
/**
* 对齐方式
* @type {Object}
*/
align : null
}
Align.prototype= {
//resize方法
bindAlignEvent : function () {
var _self = this;
_self.on('change:visible',function (visible) {
if(visible){
this.resetAlign();
$(window).on('resize',resize);
}else{
$(window).off('resize',resize);
}
});
var handler;
function resize () {
handler && clearTimeout(handler);
handler = setTimeout(function () {
if(_self.get('visible') && !_self.get('closing')){
_self.resetAlign();
switch(type){
case 'top' :
point = {
x : offX,
y : offY
};
break;
case 'bottom':
point = {
x : offX,
y : offY + vHight - height
};
break;
case 'left':
point = {
x : offX,
y : offY
}
},200);
break;
case 'right':
point = {
x : offX + vWidth - width,
y : offY
}
break;
case 'center' :
point = {
x : offX + (vWidth - width)/2,
y : offY + (vHight - height)/2
};
break;
default :
break;
}
},
/**
* 获取对齐的点
* @return {Object} 对齐的点
*/
getAlignPoint : function(align){
var _self = this,
point = null;
align = align || _self.get('align');
if(align){
var offset = align.offset,
type = align.type,
offX = offset ? offset[0] : 0,
offY = offset ? offset[1] : 0,
vHight = $(window).height(),
height = _self.element.height(),
width = _self.element.width(),
vWidth = $(window).width();
switch(type){
case 'top' :
point = {
x : offX,
y : offY
};
break;
case 'bottom':
point = {
x : offX,
y : offY + vHight - height
};
break;
case 'left':
point = {
x : offX,
y : offY
}
break;
case 'right':
point = {
x : offX + vWidth - width,
y : offY
}
break;
case 'center' :
point = {
x : offX + (vWidth - width)/2,
y : offY + (vHight - height)/2
};
break;
default :
break;
}
}
return point;
},
_onRenderAlign : function(align){
}
return point;
},
if(this.rendered){
this.resetAlign(align);
}
},
resetAlign : function(align){
var _self = this,
point = _self.getAlignPoint(align);
_onRenderAlign : function(align){
if(this.rendered){
this.resetAlign(align);
}
},/**/
//重新设置对齐
resetAlign : function(align){
var _self = this,
point = _self.getAlignPoint(align);
if(point){
_self.set('xy',[point.x,point.y]);
}
if(point){
_self.set('xy',[point.x,point.y]);
}
};
}
};
module.exports = Align;
module.exports = Align;

@@ -1,169 +0,141 @@

/**
* @fileOverview 控件的动画扩展
* @author dxq613
* @ignore
*/
var $ = require('anima-yocto-lite');
var animateEvent = 'webkitAnimationEnd';
var $ = require('anima-yocto-lite');
function addAnimEnd(el, callback) {
el.addEventListener(animateEvent, callback, false);
}
//https://github.com/Modernizr/Modernizr/issues/897
var _transitionFinishedEvents = {
'WebkitTransition' : 'webkitTransitionEnd',
'MozTransition' : 'transitionend',
'OTransition' : 'oTransitionEnd',
'msTransition' : 'msTransitionEnd',
'transition' : 'transitionEnd'
},_transitionFinishedEvent;
function removeAnimEnd(el, callback) {
el.removeEventListener(animateEvent, callback, false);
}
/* Create a cached element for re-use when checking for CSS property prefixes. */
var _prefixElement= document.createElement("div");
for(var i in _transitionFinishedEvents){
if (typeof _prefixElement.style[i] === "string") {
_transitionFinishedEvent=_transitionFinishedEvents[i];
break;
}
}
function ucfirst(s){
s += '';
return s.charAt(0).toUpperCase() + s.substring(1);
}
var animateEvent = 'webkitAnimationEnd';
var inverse = {
'up' : 'down',
'down' : 'up',
'left' : 'left',
'right' : 'right'
};
function addAnimEnd(el, callback) {
el.addEventListener(animateEvent, callback, false);
}
function removeAnimEnd(el, callback) {
el.removeEventListener(animateEvent, callback, false);
}
var Animate = function(){};
function ucfirst(s){
s += '';
return s.charAt(0).toUpperCase() + s.substring(1);
}
Animate.ATTRS = {
/**
* 动画时间
* @type {Number}
*/
duration : 400,
/**
* 动画类型
* @type {String}
*/
easing : 'linear',
var inverse = {
'up' : 'down',
'down' : 'up',
'left' : 'left',
'right' : 'right'
};
direction : 'up'
};
var Animate = function(){
Animate.prototype = {
//获取动画名称
_getAnimName : function(effect,type){
var _self = this,
name = effect + ucfirst(type),
direction;
};
if(effect == 'slide'){
direction = _self.get('direction');
Animate.ATTRS = {
if(type == 'in'){
name = name + ucfirst(direction);
}else{ //取反,slideOut,执行的动画有所差异
name = name + ucfirst(inverse[direction]);
}
/**
* 动画时间
* @type {Number}
*/
duration : 400,
/**
* 动画类型
* @type {String}
*/
easing : 'linear',
}
return name;
},
//显示动画
animateEffectIn : function(effect){
var _self = this,
direction : 'up'
params = {
'-webkit-animation-name' : _self._getAnimName(effect,'in')
};
};
_self.set('visible',true);
_self.set('closing',false);
_self.animate(params,null,true);
},
Animate.prototype = {
//获取动画名称
_getAnimName : function(effect,type){
var _self = this,
name = effect + ucfirst(type),
direction;
if(effect == 'slide'){
direction = _self.get('direction');
//隐藏动画
animateEffectOut : function(effect){
var _self = this,
params = {
'-webkit-animation-name' : _self._getAnimName(effect,'out')
};
if(type == 'in'){
name = name + ucfirst(direction);
}else{ //取反,slideOut,执行的动画有所差异
name = name + ucfirst(inverse[direction]);
}
_self.set('closing',true);
_self.animate(params,callback,true);
function callback(){
if(_self.get('closing')){
_self.set('visible',false);
_self.set('closing',false);
}
return name;
},
//显示动画
animateEffectIn : function(effect){
var _self = this,
}
},
/**
* 执行动画
* @private
*/
animate : function(params,endCallback){
var _self = this,
el = _self.element;
params = {
'-webkit-animation-name' : _self._getAnimName(effect,'in')
};
_self.set('visible',true);
_self.set('closing',false);
_self.animate(params,null,true);
},
//隐藏动画
animateEffectOut : function(effect){
var _self = this,
params = {
'-webkit-animation-name' : _self._getAnimName(effect,'out')
};
_self.set('closing',true);
_self.animate(params,callback,true);
function callback(){
if(_self.get('closing')){
_self.set('visible',false);
_self.set('closing',false);
function callback(e){
//If el have child, and also have transition, so child transition end event will pop
//to el, and make the issue happen. so we should judge the target element ,then kill
//the animation
//btw: Timeout vs webkitTransitionEnd http://jsperf.com/timeout-vs-webkittransitionend/3
if(e.target == _self.element[0]) {
_self.offAnimate();
removeAnimEnd(el[0], callback);
endCallback && endCallback();
}
}
},
/**
* 执行动画
* @private
*/
animate : function(params,endCallback){
var _self = this,
el = _self.element;
}
function callback(e){
//If el have child, and also have transition, so child transition end event will pop
//to el, and make the issue happen. so we should judge the target element ,then kill
//the animation
//btw: Timeout vs webkitTransitionEnd http://jsperf.com/timeout-vs-webkittransitionend/3
if(e.target == _self.element[0]) {
_self.offAnimate();
removeAnimEnd(el[0], callback);
endCallback && endCallback();
}
}
addAnimEnd(el[0],callback);
addAnimEnd(el[0],callback);
_self.applyAnimate();
el.css(params)
},
//应用动画
applyAnimate : function(){
var _self = this,
el = _self.element;
el.css(_self.getAnimateStyle());
},
//去除动画
offAnimate : function(){
this.element.css({
//'-webkit-transition' : 'none',
'-webkit-animation' : 'none'
});
},
//获取动画相关的样式
getAnimateStyle : function(){
var _self = this,
duration = _self.get('duration');
return {
//'-webkit-transition' : 'all '+ duration + 'ms '+ _self.get('easing'),
'-webkit-animation-duration': duration + 'ms ',
'-webkit-animation-timing-function' : _self.get('easing')
};
}
};
_self.applyAnimate();
el.css(params)
},
//应用动画
applyAnimate : function(){
var _self = this,
el = _self.element;
el.css(_self.getAnimateStyle());
},
//去除动画
offAnimate : function(){
this.element.css({
//'-webkit-transition' : 'none',
'-webkit-animation' : 'none'
});
},
//获取动画相关的样式
getAnimateStyle : function(){
var _self = this,
duration = _self.get('duration');
return {
//'-webkit-transition' : 'all '+ duration + 'ms '+ _self.get('easing'),
'-webkit-animation-duration': duration + 'ms ',
'-webkit-animation-timing-function' : _self.get('easing')
};
}
};
module.exports = Animate
module.exports = Animate

@@ -0,72 +1,65 @@

var $ = require('anima-yocto-lite'),
CLS_MASK_RELATIVE = 'am-mask-relative';
var $ = require('anima-yocto-lite'),
CLS_MASK_RELATIVE = 'am-mask-relative';
var Mask = function(){};
/* */
var Mask = function(){};
Mask.ATTRS = {
//是否显示mask
mask : false,
//遮蔽的节点
maskNode : null,
//mask层
maskEl : null,
//遮蔽的模板
maskTpl : '<div class="am-mask" style="width:100%;height:100%;top:0;left:0;"></div>'
};
Mask.ATTRS = {
//是否显示mask
mask : false,
//遮蔽的节点
maskNode : null,
//mask层
maskEl : null,
//遮蔽的模板
maskTpl : '<div class="am-mask" style="width:100%;height:100%;top:0;left:0;"></div>'
}
Mask.prototype = {
/**
* 显示mask
* @protected
*/
showMask : function(){
var _self = this,
maskNode = _self.get('maskNode') || 'body',
zIndex = _self.get('zIndex'),
maskEl = _self.get('maskEl');
if(!maskEl){
maskEl = $(_self.get('maskTpl')).appendTo(maskNode);
var positon = maskNode == 'body' ? 'fixed' : 'absolute';
maskEl.css('position',positon);
if (zIndex) {
maskEl.css('zIndex', zIndex - 1);
}
_self.set('maskEl',maskEl);
Mask.prototype = {
/**
* 显示mask
* @protected
*/
showMask : function(){
var _self = this,
maskNode = _self.get('maskNode') || 'body',
zIndex = _self.get('zIndex'),
maskEl = _self.get('maskEl');
if(!maskEl){
maskEl = $(_self.get('maskTpl')).appendTo(maskNode);
var positon = maskNode == 'body' ? 'fixed' : 'absolute';
maskEl.css('position',positon);
if (zIndex) {
maskEl.css('zIndex', zIndex - 1);
}
$(maskNode).addClass(CLS_MASK_RELATIVE);
maskEl.show();
},
/**
* 隐藏mask
*/
hideMask : function(){
var _self = this,
maskNode = _self.get('maskNode') || 'body',
maskEl = _self.get('maskEl');
if(maskEl){
maskEl.hide();
$(maskNode).removeClass(CLS_MASK_RELATIVE);
}
},
/**
* 释放mask
*/
destroyMask : function(){
var _self = this,
maskNode = _self.get('maskNode') || 'body',
maskEl = _self.get('maskEl');
if(maskEl){
maskEl.remove();
$(maskNode).removeClass(CLS_MASK_RELATIVE);
}
_self.set('maskEl',maskEl);
}
};
$(maskNode).addClass(CLS_MASK_RELATIVE);
maskEl.show();
},
/**
* 隐藏mask
*/
hideMask : function(){
var _self = this,
maskNode = _self.get('maskNode') || 'body',
maskEl = _self.get('maskEl');
if(maskEl){
maskEl.hide();
$(maskNode).removeClass(CLS_MASK_RELATIVE);
}
},
/**
* 释放mask
*/
destroyMask : function(){
var _self = this,
maskNode = _self.get('maskNode') || 'body',
maskEl = _self.get('maskEl');
if(maskEl){
maskEl.remove();
$(maskNode).removeClass(CLS_MASK_RELATIVE);
}
}
};
module.exports = Mask;
module.exports = Mask;

@@ -5,115 +5,228 @@ /**

*/
var $ = require('anima-yocto-lite'),
Widget = require('anima-widget'),
Position = require('./position'),
Animate = require('./animate'),
Align = require('./align'),
Mask = require('./mask');
var ON_RENDER = '_onRender';
var $ = require('anima-yocto-lite'),
Widget = require('anima-widget'),
Position = require('./position'),
Animate = require('./animate'),
Align = require('./align'),
Mask = require('./mask');
function Pop(config){
this.attrs = $.extend(true, {}, Position.ATTRS, Mask.ATTRS, Animate.ATTRS, Align.ATTRS,{
width : null,
height : null,
visible : false,
className : 'am-pop',
effect : 'none',
template: '<div></div>',
// 组件的默认父节点
parentNode: document.body
}, config);
require('./pop.css');
// 是否由 template 初始化
this._isTemplate = !(config && config.element);
var Pop = Widget.extend({
attrs : $.extend(true,{},Position.ATTRS,Mask.ATTRS,Animate.ATTRS,Align.ATTRS,{
width : null,
height : null,
visible : false,
className : 'am-pop',
effect : 'none'
})
});
this.setup();
}
Pop.implement([Position.prototype,Mask.prototype,Animate.prototype,Align.prototype,{
//初始化事件
setup : function () {
this._initElement();
this.bindAlignEvent();
this.processMask();
},
_initElement : function(){
var _self = this,
element = _self.element;
if(!_self._isTemplate){
element.appendTo('body');
}
if(!_self.get('visible')){
element.css('visibility','hidden');
}
},
processMask : function () {
if (!this.get('mask')) return;
Pop.prototype = $.extend(true, {}, Position.prototype, Mask.prototype, Animate.prototype, Align.prototype, {
//初始化事件
setup : function () {
this.parseElement();
var _self = this;
this.on('show', function () {
_self.showMask();
});
this.on('hide', function () {
_self.hideMask();
}) ;
},
/**
* 显示
*/
show : function(){
var _self = this,
effect = _self.get('effect');
if (!this.rendered) {
this.render();
this._initElement();
this.processMask();
},
// 构建 this.element
parseElement: function() {
var element = this.element;
if (element) {
this.element = $(element);
}
// 未传入 element 时,从 template 构建
else if (this.get('template')) {
this.element = $(this.get('template'));
}
// 如果对应的 DOM 元素不存在,则报错
if (!this.element || !this.element[0]) {
throw new Error('element is invalid')
}
},
// 将 widget 渲染到页面上
// 渲染不仅仅包括插入到 DOM 树中,还包括样式渲染等
// 约定:子类覆盖时,需保持 `return this`
render: function() {
// 让渲染相关属性的初始值生效,并绑定到 change 事件
if (!this.rendered) {
this._renderAndBindAttrs();
this.rendered = true;
}
// 插入到文档流中
var parentNode = this.get('parentNode');
if (parentNode && !isInDocument(this.element[0])) {
this.element.appendTo(parentNode);
}
this._onRenderAlign(this.attrs.align);
return this;
},
_initElement : function(){
var _self = this,
element = _self.element;
if(!_self._isTemplate){
element.appendTo('body');
}
if(!_self.get('visible')){
element.css('visibility','hidden');
}
},
processMask : function () {
var pop = this,
_self = $(this);
if (!pop.get('mask')) return;
_self.on('show', function () {
pop.showMask();
});
_self.on('hide', function () {
pop.hideMask();
});
},
_renderAndBindAttrs: function() {
var widget = this;
var attrs = widget.attrs;
for (var attr in attrs) {
if (!attrs.hasOwnProperty(attr)) continue;
var m = ON_RENDER + ucfirst(attr);
if (this[m]) {
var val = this.get(attr);
// 让属性的初始值生效。注:默认空值不触发
if (!isEmptyAttrValue(val)) {
this[m](val, undefined, attr);
}
}
if(effect == 'none'){
_self.set('visible',true);
}else{
_self.animateEffectIn(effect);
}
},
/**
* 隐藏
*/
hide : function(){
var _self = this,
effect = _self.get('effect');
if(!_self.get('visible') || _self.get('closing')){
return true;
}
if(effect == 'none'){
_self.set('visible',false);
}else{
_self.animateEffectOut(effect);
}
},
//更改宽
_onRenderWidth: function(val) {
this.element.css('width', val);
},
//更改高
_onRenderHeight: function(val) {
this.element.css('height', val);
},
//更改zIndex
_onRenderZIndex: function(val) {
this.element.css('zIndex', val);
},
//更改是否可见
_onRenderVisible: function(val) {
var visibility = val ? 'visible' : 'hidden';
this.element.css('visibility',visibility);
if(val){
this.trigger('show');
}else{
this.trigger('hide');
}
},
//销毁
destroy : function (argument) {
var _self = this;
if(_self.get('mask')){
_self.hideMask();
_self.destroyMask();
}
Pop.superclass.destroy.call(this);
}
}]);
},
/**
* 显示
*/
show : function(){
var _self = this,
effect = _self.get('effect');
if (!this.rendered) {
this.render();
}
if(effect == 'none'){
_self.set('visible',true);
}else{
_self.animateEffectIn(effect);
}
module.exports = Pop;
$(_self).trigger('show');
},
/**
* 隐藏
*/
hide : function(){
var _self = this,
effect = _self.get('effect');
if(!_self.get('visible') || _self.get('closing')){
return true;
}
if(effect == 'none'){
_self.set('visible',false);
}else{
_self.animateEffectOut(effect);
}
$(_self).trigger('hide');
},
//更改宽
_onRenderWidth: function(val) {
this.element.css('width', val);
},
//更改高
_onRenderHeight: function(val) {
this.element.css('height', val);
},
//更改zIndex
_onRenderZIndex: function(val) {
this.element.css('zIndex', val);
},
//更改是否可见
_onRenderVisible: function(val) {
var visibility = val ? 'visible' : 'hidden';
this.element.css('visibility',visibility);
if(val){
$(this).trigger('show');
}else{
$(this).trigger('hide');
}
},
_onRenderClassName: function(val) {
this.element.addClass(val);
},
//销毁
destroy : function (argument) {
var _self = this;
if(_self.get('mask')){
_self.hideMask();
_self.destroyMask();
}
if (this.element) {
this.element.off();
this.element.remove();
}
this.element = null;
}
});
Pop.prototype.constructor = Pop;
Pop.prototype.get = function(key){
return this.attrs[key] || null;
};
Pop.prototype.set = function(key, val){
this.attrs[key] = val;
this[ON_RENDER + ucfirst(key)] && this[ON_RENDER + ucfirst(key)](val);
return this;
};
module.exports = Pop;
function isInDocument(element) {
return !!(document.documentElement.compareDocumentPosition(element) & 16);
}
// 对于 attrs 的 value 来说,以下值都认为是空值: null, undefined
function isEmptyAttrValue(o) {
return o == null || o === undefined
}
function ucfirst(s){
s += '';
return s.charAt(0).toUpperCase() + s.substring(1);
}

@@ -1,48 +0,34 @@

/**
* @fileOverview 定位的扩展,仅考虑移动端
* @author
*/
var Position = function(){};
var Position = function(){
}
Position.ATTRS = {
x : -999,
y : -999,
xy : {
/*setter : function(v){
this.set('x',v[0]);
this.set('y',v[1]);
}*/
},
zIndex: 99
}
Position.prototype = {
//设置x
_onRenderX : function(x){
if (x != null) {
this.element.css('left',x);
}
},
//设置y
_onRenderY : function(y){
this.element.css('top',y);
},
//设置z-Index
_onRenderZIndex: function(val) {
this.element.css('zIndex', val);
},
_onRenderXy : function(v){
Position.ATTRS = {
x : -999,
y : -999,
xy : {
/*setter : function(v){
this.set('x',v[0]);
this.set('y',v[1]);
}
};
}*/
},
zIndex: 99
};
Position.prototype = {
//设置x
_onRenderX : function(x){
x != null && this.element.css('left',x);
},
//设置y
_onRenderY : function(y){
y != null && this.element.css('top',y);
},
//设置z-Index
_onRenderZIndex: function(val) {
val != null && this.element.css('zIndex', val);
},
_onRenderXy : function(v){
this.set('x',v[0]);
this.set('y',v[1]);
}
};
module.exports = Position;
module.exports = Position;
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