pageLinksPicker.js
5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
define('pageLinksPicker', ['dataModel', 'components/common'], function(dataModel, common) {
var template = '\
<div class="link-container">\
<div class="link-search"> <input placeholder="'+ SystemEnv.getHtmlNoteName(4748) /* 请输入检索项 */ +'" type="text" class="form-control"> </div>\
<ul class="link-list u-list">\
</ul>\
</div>';
var cssText = '\
.link-container { position: fixed; z-index: 99999999; width: 370px; background: #fff; border: 1px solid rgba(0, 0, 0, 0.15); border-radius:3px; box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.35); }\
.link-container:after { content: " "; height: 100%; width: 100%; position: fixed; top: 0; left: 0; z-index: -1; display: none; }\
.link-container.fadeOut:after { display: block; }\
.link-container.fadeOut { animation: fadeOut .3s; animation-fill-mode: forwards; }\
.link-container.fadeIn { animation: fadeIn .3s; animation-fill-mode: forwards; }\
.link-container .link-search { padding: 7px 5px;}\
.link-container .form-control { padding: 2px; text-indent: .3em; }\
.link-container.fadeOut .link-list { height: 220px; opacity: 1; transition: height .3s, opacity .1s; }\
.link-list { margin: 0; width: 100%; height: 0px; overflow-y: auto; box-shadow: none; border: none; border-top: 1px solid #dfdfdf; padding-bottom: 5px; box-sizing: content-box; box-shadow: 3px -3px 15px -8px rgba(0, 0, 0, .5) inset; opacity: 0.6; transition: height .3s, opacity .1s; }\
.link-list li:after { content: ""; display: table; clear: both; }\
.link-list .uiname { font-size: 13px; color: #333; }\
.link-list .link-type { font-size: 12px; float: right; color: #777; }\
@keyframes fadeIn { from { opacity: 1; } to { opacity: 0.5; visibility: hidden; } } \
@keyframes fadeOut { from { opacity: 0.5; } to { opacity: 1; visibility: visible; } } \
';
common.importCssText('pageLinksPicker', cssText);
var Picker = {
el: null,
container: $('body'),
getNavsModel: function() {
return dataModel.get('navsModel');
},
render: function(navsModel) {
var linkTemp = '<li uiid="{{uiid}}"><span class="uiname"> {{uiname}} </span><span class="link-type"> {{type}} </span></li>',
linkList = "", items;
for (itemname in navsModel) {
match = itemname.match(/homepage|layout|list.*?/g);
if(!match) continue;
items = navsModel[itemname].filter(function(item) {
switch(match[0]) {
case 'homepage':
item.type = SystemEnv.getHtmlNoteName(4106); // "自定义页面"
break;
case 'layout':
item.type = SystemEnv.getHtmlNoteName(5180); //"布局页面"
break;
case 'list':
item.type = SystemEnv.getHtmlNoteName(5181); // "列表页面"
}
return item;
});
linkList += common.tempEngine(linkTemp, items);
}
Picker.el = $(template);
Picker.el.find('.link-list').append(linkList);
Picker.container.append(Picker.el);
return this;
},
position: function () {
common.position( Picker.activeElement, Picker.el, 'left' );
return Picker;
},
globalEvents: function() {
Picker.container.one('click.linkPicker', function () {
Picker.hide();
});
return this;
},
bindEvents: function () { // 只在初始化调用一次
Picker.el.off('click.linkPicker')
.on('click.linkPicker', function (e) {
e.target == this && Picker.hide();
e.stopPropagation()
})
.off('click.linkPicker', 'li')
.on('click.linkPicker', 'li', function(e) {
var curr = $(e.currentTarget),
link = "/mobilemode/appHomepageView.jsp?",
uiid = curr.attr('uiid'),
idType = common.isNumber(uiid) ? "uiid=" : "appHomepageId=",
activeElement = Picker.activeElement;
link += idType + common.toInt(uiid);
Picker.setValue(link).hide();
})
.find('.form-control')
.off('input.search')
.on('input.search', function(e) {
var keyValue = e.currentTarget.value || '',
ele, linkTag;
Picker.el.find('.link-list li').each(function(index, linkEle) {
ele = $(linkEle),
linkTag = ele.text();
ele.toggle( linkTag.indexOf(keyValue) != -1 );
})
});
return this;
},
show: function() {
return Picker.el.removeClass('fadeIn').addClass('fadeOut');
},
hide: function () {
Picker.el.removeClass('fadeOut').addClass('fadeIn')
.find('.form-control').val('').trigger('input');
},
isFormControl: function(el) {
if($(el).parent('.link-search').length > 0) return false; // 排出自身search框的影响
return ['input', 'textarea'].indexOf( el.tagName.toLowerCase() ) != -1;
},
setValue: function(value) {
var activeElement = Picker.activeElement,
classStr = activeElement.attr('class') || "";
if(classStr.indexOf('ace') != -1) { // 针对ace编辑器
var editor = activeElement.parent()[0].env.editor;
value = editor.getValue() + value;
editor.setValue(value, true);
editor.focus();
} else {
activeElement.val( activeElement.val() + value )
.trigger('input');
}
return this;
}
};
return {
show: function() {
Picker.activeElement = $(document.activeElement);
if(!Picker.isFormControl( Picker.activeElement[0]) ) return; // 非表单输入型元素 则不弹出
if(Picker.el) return Picker.globalEvents().position().show().find('.form-control').focus(); // 单例
Picker.getNavsModel()
.then(function(navsModel) {
Picker.render(navsModel).globalEvents().bindEvents().position().show();
});
}
}
});