d54aa08565
1. 新增单选模式, {radio: true|false} 2. 新增重复选模式, {repeat: true|false} 3. 新增配置, 可以控制是否自动关闭下拉框, {clickClose: true|false} 4. 新增on方法, 可以监听已选择数据, data: {arr, item, selected}
58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
|
|
var htmls = [], js = [];
|
|
data.forEach(function(item){
|
|
htmls.push([
|
|
'<div class="slide">',
|
|
item.html,
|
|
'<div class="dcode mt10"><script type="syntaxhighlighter" class="brush:html"><![CDATA[',
|
|
item.comment ? item.comment.replace(/</g, '<') : item.html.replace(/</g, '<'),
|
|
']]></script></div>',
|
|
item.js && ['<div class="dcode mt10"><script type="syntaxhighlighter" class="brush:js"><![CDATA[',
|
|
item.js.replace(/</g, '<'),
|
|
']]></script></div>'].join(''),
|
|
'</div>',
|
|
].join(''));
|
|
js.push(item.js);
|
|
});
|
|
|
|
var box = $('#content');
|
|
box.append($(htmls.join('')));
|
|
|
|
js.forEach(function(item){
|
|
eval(item);
|
|
});
|
|
|
|
SyntaxHighlighter.defaults["quick-code"] = false;
|
|
SyntaxHighlighter.defaults["gutter"] = false;
|
|
SyntaxHighlighter.all();
|
|
|
|
var ele = new Fathom('#content')
|
|
|
|
xmSelect.render({
|
|
el: '#header',
|
|
data: data.map(function(item, index){
|
|
return {
|
|
name: (index + 1) + '. ' + item.title,
|
|
value: index,
|
|
empty: !!item.title
|
|
}
|
|
}).filter(function(item){
|
|
return item.empty;
|
|
}),
|
|
filterable: true,
|
|
model: {
|
|
label: {
|
|
type: 'text',
|
|
text: {
|
|
left: '',
|
|
right: '',
|
|
separator: ', ',
|
|
},
|
|
},
|
|
},
|
|
radio: true,
|
|
clickClose: true,
|
|
on: function(data){
|
|
data.selected && ele.scrollToSlide($('.slide:nth-child('+(data.item.value + 1)+')'));
|
|
}
|
|
}); |