easyui-rtl.js
7.83 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
(function($){
$.map(['validatebox','textbox','filebox','searchbox',
'combo','combobox','combogrid','combotree',
'datebox','datetimebox','numberbox',
'spinner','numberspinner','timespinner','datetimespinner'], function(plugin){
if ($.fn[plugin]){
$.extend($.fn[plugin].defaults, {
iconAlign: 'left',
buttonAlign: 'left',
tipPosition: 'left',
panelAlign: 'right',
deltaX: -19
});
}
});
$.map(['linkbutton','menubutton','splitbutton'], function(plugin){
if ($.fn[plugin]){
$.extend($.fn[plugin].defaults, {
iconAlign: 'right',
menuAlign: 'right'
});
}
});
$.map(['datagrid','propertygrid','treegrid','combogrid'], function(plugin){
if ($.fn[plugin]){
$.extend($.fn[plugin].defaults, {
resizeHandle: 'left'
});
}
});
$.fn.searchbox.defaults.buttonAlign = 'right';
$.fn.menu.defaults.align = 'right';
$.fn.tabs.defaults.toolPosition = 'left';
$.fn.pagination.defaults.nav.first.iconCls = 'pagination-last';
$.fn.pagination.defaults.nav.prev.iconCls = 'pagination-next';
$.fn.pagination.defaults.nav.next.iconCls = 'pagination-prev';
$.fn.pagination.defaults.nav.last.iconCls = 'pagination-first';
$.fn.slider.defaults.reversed = true;
var datagrid_freezeRow = $.fn.datagrid.methods.freezeRow;
$.fn.datagrid.methods.freezeRow = function(jq, index){
return jq.each(function(){
datagrid_freezeRow.call(this, jq, index);
var state = $.data(this, 'datagrid');
if (!state.rtlscroll){
state.rtlscroll = true;
var dc = state.dc;
dc.body2.bind('scroll', function(){
var ftable = $(this).children('table.datagrid-btable-frozen');
ftable.css('left', $(this)._outerWidth() + $(this)._scrollLeft() - ftable._outerWidth());
});
}
});
}
var tabs_update = $.fn.tabs.methods.update;
$.fn.tabs.methods.update = function(jq, options){
return jq.each(function(){
tabs_update.call(this, jq, options);
var wrap = $(this).find('>div.tabs-header>div.tabs.wrap');
var opts = options.tab.panel('options');
var tab = opts.tab;
var tool = tab.find('.tabs-p-tool');
if (tool.length){
var pos = tool.css('right');
tool.css({
left: pos,
right: 'auto'
});
var title = tab.find('.tabs-title');
var pos = title.css('padding-right');
title.css({
paddingLeft: pos,
paddingRight: ''
});
}
});
}
function checkScrollLeftType(){
var tmp = $('<div dir="rtl" style="font-size: 14px; width: 1px; height: 1px; position: absolute; top: -1000px; overflow: scroll">test</div>').appendTo('body');
if (tmp.scrollLeft() > 0){
$._rtlScrollType = 'default'; // chrome
} else {
tmp.scrollLeft(1);
if (tmp.scrollLeft() == 0){
$._rtlScrollType = 'negative'; // firefox
} else {
$._rtlScrollType = 'reverse'; // ie
}
}
tmp.remove();
}
$.fn._scrollLeft = function(left){
if ($._rtlScrollType == undefined){checkScrollLeftType();}
if (left == undefined){
if ($._rtlScrollType == 'reverse'){
return this.scrollLeft();
} else if ($._rtlScrollType == 'negative'){
return -this.scrollLeft();
} else {
return this[0].scrollWidth - this[0].clientWidth - this.scrollLeft();
}
}
return this.each(function(){
if ($._rtlScrollType == 'reverse'){
$(this).scrollLeft(left);
} else if ($._rtlScrollType == 'negative'){
$(this).scrollLeft(-left);
} else {
$(this).scrollLeft(this.scrollWidth - this.clientWidth - left);
}
});
}
$.fn.tabs.methods.scrollBy = function(jq, deltaX){
if ($._rtlScrollType == undefined){checkScrollLeftType();}
return jq.each(function(){
var opts = $(this).tabs('options');
var wrap = $(this).find('>div.tabs-header>div.tabs-wrap');
var pos = Math.min(wrap._scrollLeft() - deltaX, getMaxScrollWidth());
// if ($.browser.msie){
// wrap.animate({scrollLeft: pos}, opts.scrollDuration);
// } else if ($.browser.mozilla){
// wrap.animate({scrollLeft: -pos}, opts.scrollDuration);
// } else {
// wrap.animate({scrollLeft: wrap[0].scrollWidth - wrap[0].clientWidth - pos}, opts.scrollDuration);
// }
if ($._rtlScrollType == 'reverse'){
wrap.animate({scrollLeft: pos}, opts.scrollDuration);
} else if ($._rtlScrollType == 'negative'){
wrap.animate({scrollLeft: -pos}, opts.scrollDuration);
} else {
wrap.animate({scrollLeft: wrap[0].scrollWidth - wrap[0].clientWidth - pos}, opts.scrollDuration);
}
function getMaxScrollWidth(){
var w = 0;
var ul = wrap.children('ul');
ul.children('li').each(function(){
w += $(this).outerWidth(true);
});
return w - wrap.width() + (ul.outerWidth() - ul.width());
}
});
}
$.fn.combo.methods.showPanel = function(jq){
return jq.each(function(){
var target = this;
var state = $.data(target, 'combo');
var combo = state.combo;
var panel = state.panel;
var opts = $(target).combo('options');
var palOpts = panel.panel('options');
palOpts.comboTarget = target; // store the target combo element
if ($.fn.window){
panel.panel('panel').css('z-index', $.fn.window.defaults.zIndex++);
}
panel.panel('move', {
right:combo.offset().left+combo._outerWidth(),
top:getTop()
});
if (panel.panel('options').closed){
panel.panel('open').panel('resize', {
width: (opts.panelWidth ? opts.panelWidth : combo._outerWidth()),
height: opts.panelHeight
});
opts.onShowPanel.call(this);
}
(function(){
if (panel.is(':visible')){
panel.panel('move', {
left:getLeft(),
top:getTop()
});
setTimeout(arguments.callee, 200);
}
})();
function getLeft(){
var left = combo.offset().left;
if (opts.panelAlign == 'right'){
left += combo._outerWidth() - panel._outerWidth();
}
return left;
}
function getTop(){
var top = combo.offset().top + combo._outerHeight();
if (top + panel._outerHeight() > $(window)._outerHeight() + $(document).scrollTop()){
top = combo.offset().top - panel._outerHeight();
}
if (top < $(document).scrollTop()){
top = combo.offset().top + combo._outerHeight();
}
return top;
}
});
}
$.fn.menu.methods.show = function(jq, param){
return jq.each(function(){
var target = this;
var left,top;
param = param || {};
var menu = $(param.menu || target);
if (menu.hasClass('menu-top')){
var opts = $.data(target, 'menu').options;
$.extend(opts, param);
left = opts.left - menu.outerWidth();
top = opts.top;
if (opts.alignTo){
var at = $(opts.alignTo);
left = at.offset().left;
top = at.offset().top + at._outerHeight();
if (opts.align == 'right'){
left += at.outerWidth() - menu.outerWidth();
}
}
top = _fixTop(top, opts.alignTo);
} else {
var parent = param.parent; // the parent menu item
left = parent.offset().left - menu.outerWidth() + 2;
top = _fixTop(parent.offset().top - 3);
}
function _fixTop(top, alignTo){
if (top + menu.outerHeight() > $(window)._outerHeight() + $(document).scrollTop()){
if (alignTo){
var at = $(alignTo);
top = at.offset().top - menu._outerHeight();
if (top < $(document).scrollTop()){
top = at.offset().top + at._outerHeight();
}
} else {
top = $(window)._outerHeight() + $(document).scrollTop() - menu.outerHeight() - 5;
}
}
if (top < 0){top = 0;}
return top;
}
menu.css({left:left,top:top});
menu.show(0, function(){
if (!menu[0].shadow){
menu[0].shadow = $('<div class="menu-shadow"></div>').insertAfter(menu);
}
menu[0].shadow.css({
display:'block',
zIndex:$.fn.menu.defaults.zIndex++,
left:menu.css('left'),
top:menu.css('top'),
width:menu.outerWidth(),
height:menu.outerHeight()
});
menu.css('z-index', $.fn.menu.defaults.zIndex++);
if (menu.hasClass('menu-top')){
$.data(menu[0], 'menu').options.onShow.call(menu[0]);
}
});
});
}
})(jQuery);