SSR feature

pull/1982/head
qingwei.li 2016-12-26 10:45:20 +08:00
parent e181fec748
commit daec90af9f
18 changed files with 35 additions and 25 deletions

View File

@ -42,7 +42,7 @@ if [ "$TRAVIS_TAG" ]; then
export SUB_FOLDER=$(echo "$TRAVIS_TAG" | grep -o -E "\d+\.\d+") export SUB_FOLDER=$(echo "$TRAVIS_TAG" | grep -o -E "\d+\.\d+")
echo $SUB_FOLDER echo $SUB_FOLDER
SUB_FOLDER='1.0' SUB_FOLDER='1.1'
mkdir $SUB_FOLDER mkdir $SUB_FOLDER
rm -rf *.js *.css *.map static rm -rf *.js *.css *.map static
rm -rf $SUB_FOLDER/** rm -rf $SUB_FOLDER/**

View File

@ -375,6 +375,7 @@ export default {
}, },
showPicker() { showPicker() {
if (this.$isServer) return;
if (!this.picker) { if (!this.picker) {
this.panel.defaultValue = this.internalValue; this.panel.defaultValue = this.internalValue;
this.picker = new Vue(this.panel).$mount(document.createElement('div')); this.picker = new Vue(this.panel).$mount(document.createElement('div'));

View File

@ -22,7 +22,7 @@
</template> </template>
<template slot="append" v-if="$slots.append"> <template slot="append" v-if="$slots.append">
<slot name="append"></slot> <slot name="append"></slot>
</template> </template>
</el-input> </el-input>
<span <span
v-if="controls" v-if="controls"
@ -79,11 +79,8 @@
let interval = null; let interval = null;
let startTime; let startTime;
const handler = () => { const handler = () => vnode.context[binding.expression]();
vnode.context[binding.expression](); const clear = () => {
};
const clear = function() {
if (new Date() - startTime < 100) { if (new Date() - startTime < 100) {
handler(); handler();
} }
@ -91,12 +88,10 @@
interval = null; interval = null;
}; };
on(el, 'mousedown', function() { on(el, 'mousedown', () => {
startTime = new Date(); startTime = new Date();
once(document, 'mouseup', clear); once(document, 'mouseup', clear);
interval = setInterval(function() { interval = setInterval(handler, 100);
handler();
}, 100);
}); });
} }
} }

View File

@ -117,10 +117,9 @@
this.$refs.input.select(); this.$refs.input.select();
}, },
resizeTextarea() { resizeTextarea() {
if (this.$isServer) return;
var { autosize, type } = this; var { autosize, type } = this;
if (!autosize || type !== 'textarea') { if (!autosize || type !== 'textarea') return;
return;
}
const minRows = autosize.minRows; const minRows = autosize.minRows;
const maxRows = autosize.maxRows; const maxRows = autosize.maxRows;

View File

@ -3,6 +3,7 @@ import { addClass, removeClass } from 'wind-dom/src/class';
let Mask = Vue.extend(require('./loading.vue')); let Mask = Vue.extend(require('./loading.vue'));
exports.install = Vue => { exports.install = Vue => {
if (Vue.prototype.$isServer) return;
let toggleLoading = (el, binding) => { let toggleLoading = (el, binding) => {
if (binding.value) { if (binding.value) {
Vue.nextTick(() => { Vue.nextTick(() => {

View File

@ -61,6 +61,7 @@ const addStyle = (options, parent, instance) => {
}; };
const Loading = (options = {}) => { const Loading = (options = {}) => {
if (Vue.prototype.$isServer) return;
options = merge({}, defaults, options); options = merge({}, defaults, options);
if (typeof options.target === 'string') { if (typeof options.target === 'string') {
options.target = document.querySelector(options.target); options.target = document.querySelector(options.target);

View File

@ -102,6 +102,7 @@ const showNextMsg = () => {
}; };
const MessageBox = function(options, callback) { const MessageBox = function(options, callback) {
if (Vue.prototype.$isServer) return;
if (typeof options === 'string') { if (typeof options === 'string') {
options = { options = {
message: options message: options

View File

@ -7,6 +7,7 @@ let instances = [];
let seed = 1; let seed = 1;
var Message = function(options) { var Message = function(options) {
if (Vue.prototype.$isServer) return;
options = options || {}; options = options || {};
if (typeof options === 'string') { if (typeof options === 'string') {
options = { options = {

View File

@ -7,6 +7,7 @@ let instances = [];
let seed = 1; let seed = 1;
var Notification = function(options) { var Notification = function(options) {
if (Vue.prototype.$isServer) return;
options = options || {}; options = options || {};
let userOnClose = options.onClose; let userOnClose = options.onClose;
let id = 'notification_' + seed++; let id = 'notification_' + seed++;

View File

@ -299,6 +299,7 @@
}, },
options(val) { options(val) {
if (this.$isServer) return;
this.optionsAllDisabled = val.length === val.filter(item => item.disabled === true).length; this.optionsAllDisabled = val.length === val.filter(item => item.disabled === true).length;
if (this.multiple) { if (this.multiple) {
this.resetInputHeight(); this.resetInputHeight();

View File

@ -1,6 +1,7 @@
import Vue from 'vue';
var dropdowns = []; var dropdowns = [];
document.addEventListener('click', function(event) { !Vue.prototype.$isServer && document.addEventListener('click', function(event) {
dropdowns.forEach(function(dropdown) { dropdowns.forEach(function(dropdown) {
var target = event.target; var target = event.target;
if (!dropdown || !dropdown.$el) return; if (!dropdown || !dropdown.$el) return;

View File

@ -226,7 +226,7 @@ export default {
filterPanel.table = table; filterPanel.table = table;
filterPanel.cell = cell; filterPanel.cell = cell;
filterPanel.column = column; filterPanel.column = column;
filterPanel.$mount(document.createElement('div')); !this.$isServer && filterPanel.$mount(document.createElement('div'));
} }
setTimeout(() => { setTimeout(() => {
@ -239,6 +239,7 @@ export default {
}, },
handleMouseDown(event, column) { handleMouseDown(event, column) {
if (this.$isServer) return;
if (column.children && column.children.length > 0) return; if (column.children && column.children.length > 0) return;
/* istanbul ignore if */ /* istanbul ignore if */
if (this.draggingColumn && this.border) { if (this.draggingColumn && this.border) {
@ -329,6 +330,7 @@ export default {
}, },
handleMouseOut() { handleMouseOut() {
if (this.$isServer) return;
document.body.style.cursor = ''; document.body.style.cursor = '';
}, },

View File

@ -99,7 +99,7 @@ export const getColumnByCell = function(table, cell) {
return null; return null;
}; };
const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1; const isFirefox = typeof navigator !== 'undefined' && navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
export const mousewheel = function(element, callback) { export const mousewheel = function(element, callback) {
if (element && element.addEventListener) { if (element && element.addEventListener) {

View File

@ -113,7 +113,7 @@ export default {
}, },
mounted() { mounted() {
window.addEventListener('message', (event) => { !this.$isServer && window.addEventListener('message', (event) => {
var targetOrigin = new URL(this.action).origin; var targetOrigin = new URL(this.action).origin;
if (event.origin !== targetOrigin) { if (event.origin !== targetOrigin) {
return false; return false;
@ -158,7 +158,7 @@ export default {
on-change={this.handleChange} on-change={this.handleChange}
accept={this.accept}> accept={this.accept}>
</input> </input>
<input type="hidden" name="documentDomain" value={document.domain} /> <input type="hidden" name="documentDomain" value={ this.$isServer ? '' : document.domain } />
<span ref="data"></span> <span ref="data"></span>
</form> </form>
{!this.showCover ? this.$slots.default : cover} {!this.showCover ? this.$slots.default : cover}

View File

@ -209,7 +209,7 @@ export default {
ref: 'upload-inner' ref: 'upload-inner'
}; };
var uploadComponent = typeof FormData !== 'undefined' var uploadComponent = this.$isServer ? '' : typeof FormData !== 'undefined'
? <upload {...props}>{this.$slots.default}</upload> ? <upload {...props}>{this.$slots.default}</upload>
: <iframeUpload {...props}>{this.$slots.default}</iframeUpload>; : <iframeUpload {...props}>{this.$slots.default}</iframeUpload>;

View File

@ -1,9 +1,10 @@
import Vue from 'vue';
import { on } from 'wind-dom/src/event'; import { on } from 'wind-dom/src/event';
const nodeList = []; const nodeList = [];
const ctx = '@@clickoutsideContext'; const ctx = '@@clickoutsideContext';
on(document, 'click', e => { !Vue.prototype.$isServer && on(document, 'click', e => {
nodeList.forEach(node => node[ctx].documentHandler(e)); nodeList.forEach(node => node[ctx].documentHandler(e));
}); });
/** /**

View File

@ -3,9 +3,11 @@
* *
* version: 0.5.3 * version: 0.5.3
**/ **/
const isServer = typeof window === 'undefined';
/* istanbul ignore next */ /* istanbul ignore next */
const requestFrame = (function() { const requestFrame = (function() {
if (isServer) return;
const raf = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || const raf = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame ||
function(fn) { function(fn) {
return window.setTimeout(fn, 20); return window.setTimeout(fn, 20);
@ -17,6 +19,7 @@ const requestFrame = (function() {
/* istanbul ignore next */ /* istanbul ignore next */
const cancelFrame = (function() { const cancelFrame = (function() {
if (isServer) return;
const cancel = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.clearTimeout; const cancel = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.clearTimeout;
return function(id) { return function(id) {
return cancel(id); return cancel(id);
@ -59,7 +62,7 @@ const scrollListener = function(event) {
}; };
/* Detect CSS Animations support to detect element display/re-attach */ /* Detect CSS Animations support to detect element display/re-attach */
const attachEvent = document.attachEvent; const attachEvent = isServer ? {} : document.attachEvent;
const DOM_PREFIXES = 'Webkit Moz O ms'.split(' '); const DOM_PREFIXES = 'Webkit Moz O ms'.split(' ');
const START_EVENTS = 'webkitAnimationStart animationstart oAnimationStart MSAnimationStart'.split(' '); const START_EVENTS = 'webkitAnimationStart animationstart oAnimationStart MSAnimationStart'.split(' ');
const RESIZE_ANIMATION_NAME = 'resizeanim'; const RESIZE_ANIMATION_NAME = 'resizeanim';
@ -68,7 +71,7 @@ let keyFramePrefix = '';
let animationStartEvent = 'animationstart'; let animationStartEvent = 'animationstart';
/* istanbul ignore next */ /* istanbul ignore next */
if (!attachEvent) { if (!attachEvent && !isServer) {
const testElement = document.createElement('fakeelement'); const testElement = document.createElement('fakeelement');
if (testElement.style.animationName !== undefined) { if (testElement.style.animationName !== undefined) {
animation = true; animation = true;
@ -91,7 +94,7 @@ if (!attachEvent) {
let stylesCreated = false; let stylesCreated = false;
/* istanbul ignore next */ /* istanbul ignore next */
const createStyles = function() { const createStyles = function() {
if (!stylesCreated) { if (!stylesCreated && !isServer) {
const animationKeyframes = `@${keyFramePrefix}keyframes ${RESIZE_ANIMATION_NAME} { from { opacity: 0; } to { opacity: 0; } } `; const animationKeyframes = `@${keyFramePrefix}keyframes ${RESIZE_ANIMATION_NAME} { from { opacity: 0; } to { opacity: 0; } } `;
const animationStyle = `${keyFramePrefix}animation: 1ms ${RESIZE_ANIMATION_NAME};`; const animationStyle = `${keyFramePrefix}animation: 1ms ${RESIZE_ANIMATION_NAME};`;
@ -119,6 +122,7 @@ const createStyles = function() {
/* istanbul ignore next */ /* istanbul ignore next */
export const addResizeListener = function(element, fn) { export const addResizeListener = function(element, fn) {
if (isServer) return;
if (attachEvent) { if (attachEvent) {
element.attachEvent('onresize', fn); element.attachEvent('onresize', fn);
} else { } else {
@ -162,4 +166,4 @@ export const removeResizeListener = function(element, fn) {
element.__resizeTrigger__ = !element.removeChild(element.__resizeTrigger__); element.__resizeTrigger__ = !element.removeChild(element.__resizeTrigger__);
} }
} }
}; };

View File

@ -66,6 +66,7 @@ export default {
methods: { methods: {
createPopper() { createPopper() {
if (this.$isServer) return;
if (!/^(top|bottom|left|right)(-start|-end)?$/g.test(this.placement)) { if (!/^(top|bottom|left|right)(-start|-end)?$/g.test(this.placement)) {
return; return;
} }