mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
Merge pull request #88 from chenjiahan/dev
dalete merge && class operating methods
This commit is contained in:
commit
fc452f8677
@ -80,7 +80,7 @@ export default {
|
||||
return;
|
||||
} else {
|
||||
this.swipeMove(0);
|
||||
once(this.wrap, 'webkitTransitionEnd', _ => {
|
||||
once(this.wrap, 'webkitTransitionEnd', () => {
|
||||
this.wrap.style.webkitTransform = '';
|
||||
this.rightWrapElm.style.webkitTransform = this.rightDefaultTransform;
|
||||
this.leftWrapElm.style.webkitTransform = this.leftDefaultTransform;
|
||||
|
@ -1,4 +1,3 @@
|
||||
import merge from '../../utils/merge';
|
||||
import PopupManager from './popup-manager';
|
||||
import PopupContext from './popup-context';
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
import merge from '../../utils/merge';
|
||||
import Vue from 'vue';
|
||||
|
||||
let context;
|
||||
@ -16,7 +15,10 @@ const DEFAULT_CONTEXT = {
|
||||
modalStack: []
|
||||
};
|
||||
|
||||
context = _global.popupContext = merge({}, DEFAULT_CONTEXT, context);
|
||||
context = _global.popupContext = {
|
||||
...DEFAULT_CONTEXT,
|
||||
...context
|
||||
};
|
||||
|
||||
const PopupContext = {
|
||||
getContext(key) {
|
||||
|
@ -1,5 +1,4 @@
|
||||
import Vue from 'vue';
|
||||
import { addClass } from '../../utils/dom';
|
||||
import PopupContext from './popup-context';
|
||||
|
||||
const getModal = function() {
|
||||
@ -79,7 +78,7 @@ const PopupManager = {
|
||||
|
||||
const modalDom = getModal();
|
||||
|
||||
addClass(modalDom, 'van-modal');
|
||||
modalDom.classList.add('van-modal');
|
||||
|
||||
let domParentNode;
|
||||
if (dom && dom.parentNode && dom.parentNode.nodeType !== 11) {
|
||||
|
@ -1,5 +1,4 @@
|
||||
import Vue from 'vue';
|
||||
import merge from '../utils/merge';
|
||||
import ToastComponent from './toast';
|
||||
|
||||
const ToastConstructor = Vue.extend(ToastComponent);
|
||||
@ -50,25 +49,28 @@ var Toast = (options = {}) => {
|
||||
};
|
||||
|
||||
Toast.loading = (options) => {
|
||||
return new Toast(merge({
|
||||
type: 'loading'
|
||||
}, options));
|
||||
return new Toast({
|
||||
type: 'loading',
|
||||
...options
|
||||
});
|
||||
};
|
||||
|
||||
Toast.success = (options) => {
|
||||
const message = typeof options === 'string' ? options : options.message;
|
||||
return new Toast(merge({
|
||||
return new Toast({
|
||||
type: 'success',
|
||||
message: message
|
||||
}, options));
|
||||
message: message,
|
||||
...options
|
||||
});
|
||||
};
|
||||
|
||||
Toast.fail = (options) => {
|
||||
const message = typeof options === 'string' ? options : options.message;
|
||||
return new Toast(merge({
|
||||
return new Toast({
|
||||
type: 'fail',
|
||||
message: message
|
||||
}, options));
|
||||
message: message,
|
||||
...options
|
||||
});
|
||||
};
|
||||
|
||||
Toast.clear = () => {
|
||||
|
@ -1,101 +1,11 @@
|
||||
import Vue from 'vue';
|
||||
const isServer = Vue.prototype.$isServer;
|
||||
|
||||
const trim = function(string) {
|
||||
return (string || '').replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, '');
|
||||
};
|
||||
|
||||
export function hasClass(el, cls) {
|
||||
if (!el || !cls) return false;
|
||||
if (cls.indexOf(' ') !== -1) throw new Error('className should not contain space.');
|
||||
if (el.classList) {
|
||||
return el.classList.contains(cls);
|
||||
} else {
|
||||
return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1;
|
||||
}
|
||||
};
|
||||
|
||||
export function addClass(el, cls) {
|
||||
if (!el) return;
|
||||
var curClass = el.className;
|
||||
var classes = (cls || '').split(' ');
|
||||
|
||||
for (var i = 0, j = classes.length; i < j; i++) {
|
||||
var clsName = classes[i];
|
||||
if (!clsName) continue;
|
||||
|
||||
if (el.classList) {
|
||||
el.classList.add(clsName);
|
||||
} else {
|
||||
if (!hasClass(el, clsName)) {
|
||||
curClass += ' ' + clsName;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!el.classList) {
|
||||
el.className = curClass;
|
||||
}
|
||||
};
|
||||
|
||||
export function removeClass(el, cls) {
|
||||
if (!el || !cls) return;
|
||||
var classes = cls.split(' ');
|
||||
var curClass = ' ' + el.className + ' ';
|
||||
|
||||
for (var i = 0, j = classes.length; i < j; i++) {
|
||||
var clsName = classes[i];
|
||||
if (!clsName) continue;
|
||||
|
||||
if (el.classList) {
|
||||
el.classList.remove(clsName);
|
||||
} else {
|
||||
if (hasClass(el, clsName)) {
|
||||
curClass = curClass.replace(' ' + clsName + ' ', ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!el.classList) {
|
||||
el.className = trim(curClass);
|
||||
}
|
||||
};
|
||||
export const once = function(el, event, fn) {
|
||||
var listener = function() {
|
||||
const listener = function() {
|
||||
if (fn) {
|
||||
fn.apply(this, arguments);
|
||||
}
|
||||
off(el, event, listener);
|
||||
el.removeEventListener(event, listener);
|
||||
};
|
||||
on(el, event, listener);
|
||||
el.addEventListener(event, listener);
|
||||
};
|
||||
|
||||
export const on = (function() {
|
||||
if (!isServer && document.addEventListener) {
|
||||
return function(element, event, handler) {
|
||||
if (element && event && handler) {
|
||||
element.addEventListener(event, handler, false);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return function(element, event, handler) {
|
||||
if (element && event && handler) {
|
||||
element.attachEvent('on' + event, handler);
|
||||
}
|
||||
};
|
||||
}
|
||||
})();
|
||||
|
||||
export const off = (function() {
|
||||
if (!isServer && document.removeEventListener) {
|
||||
return function(element, event, handler) {
|
||||
if (element && event) {
|
||||
element.removeEventListener(event, handler, false);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return function(element, event, handler) {
|
||||
if (element && event) {
|
||||
element.detachEvent('on' + event, handler);
|
||||
}
|
||||
};
|
||||
}
|
||||
})();
|
||||
|
@ -1,15 +0,0 @@
|
||||
export default function(target, ...sources) {
|
||||
for (let i = 0; i < sources.length; i++) {
|
||||
const source = sources[i] || {};
|
||||
for (const prop in source) {
|
||||
if (source.hasOwnProperty(prop)) {
|
||||
const value = source[prop];
|
||||
if (value !== undefined) {
|
||||
target[prop] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user