You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
8.2 KiB

function camelize(str) {
9 years ago
return str.replace(/(?:^|[-_])(\w)/g, function (_, c) {
return c ? c.toUpperCase() : '';
});
9 years ago
}
window.require = function (path) {
var result = window;
var namespaces = path.split('/');
namespaces.forEach(function (key, i) {
if (i === 2) {
key = camelize(key);
9 years ago
}
if (key !== 'lib') {
if (result[key]) {
result = result[key];
} else {
throw 'There should not have modules here: ' + path;
}
}
});
return result;
9 years ago
};
9 years ago
require('../style/index.less');
window['css-animation'] = require('css-animation');
window['react-router'] = require('react-router');
window['rc-form'] = require('rc-form');
window.CopyToClipboard = require('react-copy-to-clipboard');
9 years ago
var antd = require('../index');
10 years ago
var React = require('react');
9 years ago
var ReactDOM = require('react-dom');
var semver = require('semver');
9 years ago
window.antd = antd;
9 years ago
window.React = window.react = React;
9 years ago
window.ReactDOM = ReactDOM;
9 years ago
window['object-assign'] = require('object-assign');
window['classnames'] = require('classnames');
window['reqwest'] = require('reqwest');
window['Values'] = require('values.js');
var InstantClick = require('instantclick');
window['InstantClick'] = InstantClick;
require('./home')();
10 years ago
antd.DatePicker.locale = {
en_US: require('../components/date-picker/locale/en_US'),
zh_CN: require('../components/date-picker/locale/zh_CN'),
};
antd.Calendar.locale = {
en_US: require('../components/calendar/locale/en_US'),
zh_CN: require('../components/calendar/locale/zh_CN'),
};
antd.Pagination.locale = {
en_US: require('../components/pagination/locale/en_US'),
zh_CN: require('../components/pagination/locale/zh_CN'),
};
InstantClickChangeFns.push(function () {
// auto complete for components
10 years ago
var Select = antd.Select;
var Option = Select.Option;
// 获取搜索数据
9 years ago
var searchData = window.ANT_COMPONENTS.sort(function (a, b) {
return a.title.localeCompare(b.title);
});
10 years ago
var AutoComplete = React.createClass({
getOptions() {
return searchData.map(function (s) {
return <Option sData={s} key={s.title} text={'跳转到 ' + s.title}>
10 years ago
<strong>{s.title}</strong>
9 years ago
&nbsp;
<span className="ant-component-decs">{s.desc}</span>
10 years ago
</Option>;
});
},
handleSelect(value) {
9 years ago
location.href = rootUrl + '/components/' + value.replace(/([a-z])([A-Z])/g, function (m, m1, m2) {
9 years ago
return m1 + '-' + m2;
}).toLowerCase() + '/';
10 years ago
},
filterOption(input, option) {
return option.props.sData.title.toLowerCase().indexOf(input.toLowerCase()) !== -1 || option.props.sData.desc.indexOf(input) !== -1;
},
render() {
return <Select combobox style={{width: '100%'}}
9 years ago
onSelect={this.handleSelect}
optionLabelProp="text"
dropdownClassName="autoComplete"
searchPlaceholder="搜索组件..."
filterOption={this.filterOption}>{this.getOptions()}</Select>;
10 years ago
}
});
9 years ago
ReactDOM.render(<AutoComplete/>, document.getElementById('autoComplete'));
10 years ago
});
InstantClickChangeFns.push(function () {
9 years ago
var Select = antd.Select;
var Option = Select.Option;
var versionsHistory = {
'0.9.2': '09x.ant.design',
'0.10.4': '010x.ant.design'
};
versionsHistory[antdVersion.latest] =
9 years ago
versionsHistory[antdVersion.latest] || 'ant.design';
9 years ago
var versions = Object.keys(versionsHistory).sort(function (a, b) {
return semver.lt(a, b);
});
9 years ago
var options = versions.map(function (version) {
var link = versionsHistory[version];
9 years ago
return <Option key={version} value={version}>{version}</Option>;
});
9 years ago
9 years ago
function onChange(value) {
if (versionsHistory[value]) {
location.href = location.href.replace(location.host, versionsHistory[value]);
}
}
9 years ago
9 years ago
ReactDOM.render(
<Select defaultValue={antdVersion.latest} size="small"
dropdownMatchSelectWidth={false}
9 years ago
onChange={onChange}>{options}</Select>
9 years ago
, document.getElementById('versions-select'));
});
window.BrowserDemo = React.createClass({
render() {
return (
<article className="window-frame focus">
<header className="top-bar">
<div className="controls">
<div className="control close"></div>
<div className="control minify"></div>
<div className="control expand"></div>
</div>
9 years ago
<input className="address-bar" defaultValue="http://www.example.com"/>
</header>
<section className="window-content">
{this.props.children}
</section>
</article>
);
}
});
const { Modal, Carousel } = antd;
const PriviewImg = React.createClass({
getInitialState() {
return {
visible: false,
current: 0,
};
},
showImageModal() {
this.setState({
visible: true
});
},
handleCancel() {
this.setState({
visible: false
});
},
handleImgChange(current) {
9 years ago
this.setState({current});
},
render() {
const goodCls = this.props.good ? 'good' : '';
const badCls = this.props.bad ? 'bad' : '';
const imgsPack = this.props.imgsPack || [{
9 years ago
src: this.props.src,
alt: this.props.alt,
}];
9 years ago
const imgStyle = {};
if (this.props.noPadding) {
imgStyle.padding = '0';
imgStyle.background = 'none';
}
const current = this.state.current;
const arrows = imgsPack.length > 1;
9 years ago
const createMarkup = () => {
return {__html: this.props.description}
};
return (
9 years ago
<div className="preview-image-box" style={{ width: this.props.width }}>
<div className={`preview-image-wrapper ${goodCls} ${badCls}`}>
9 years ago
<img src={this.props.src} onClick={this.showImageModal} style={imgStyle} alt="Sample Picture"/>
</div>
<div className="preview-image-title">{this.props.alt}</div>
9 years ago
<div className="preview-image-description" dangerouslySetInnerHTML={createMarkup()}/>
<Modal className="image-modal" width="960" visible={this.state.visible} onCancel={this.handleCancel} footer=""
title="">
<Carousel afterChange={this.handleImgChange} adaptiveHeight arrows={arrows}>
{
imgsPack.map((img, i) =>
<div key={i}>
<div className="image-modal-container">
9 years ago
<img src={img.src}/>
</div>
</div>
)
}
</Carousel>
<div className="preview-image-title">{imgsPack[current].alt}</div>
</Modal>
</div>
);
}
});
9 years ago
InstantClickChangeFns.push(function () {
const previewImageBoxes = $('.preview-img').parent();
9 years ago
previewImageBoxes.each(function (i, box) {
box = $(box);
let priviewImgs = [];
9 years ago
const priviewImgNodes = box.find('.preview-img');
// 判断是否要做成图片集合
// 指定了封面图片就是
let coverImg;
9 years ago
priviewImgNodes.each(function (i, img) {
if (img.hasAttribute('as-cover')) {
coverImg = img;
return false;
9 years ago
}
});
if (coverImg) {
const imgs = [];
priviewImgNodes.each((i, img) => imgs.push(img));
9 years ago
priviewImgs = <PriviewImg src={coverImg.src} alt={coverImg.alt} imgsPack={imgs}/>;
} else {
9 years ago
priviewImgNodes.each(function (i, img) {
priviewImgs.push(
9 years ago
<PriviewImg key={i} src={img.src} width={100.0/priviewImgNodes.length + '%'} alt={img.alt}
9 years ago
noPadding={img.hasAttribute('noPadding')} description={img.getAttribute('description')}
good={!!img.hasAttribute('good')} bad={!!img.hasAttribute('bad')}/>
);
});
}
// 计算宽度
9 years ago
let width = '';
if (priviewImgs.length === 1) {
width = priviewImgNodes[0].getAttribute('width') || '';
} else if (coverImg) {
width = coverImg.getAttribute('width');
}
if (width && width.indexOf('%') < 0 && width !== 'auto') {
width += 'px';
}
let mountNode = $('<div class="preview-image-boxes cleafix ' + (coverImg ? 'pack' : '') + '" style="width: ' + width + '"></div>')[0];
box.replaceWith(mountNode);
ReactDOM.render(<span>{priviewImgs}</span>, mountNode);
});
});
antd.version = require('../package.json').version;
9 years ago
module.exports = antd;