jquery.jNice_wev8.js
16.9 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
/*单选框、多选框美化组件*/
/*
* jNice
* version: 1.0 (11.26.08)
* by Sean Mooney (sean@whitespace-creative.com)
* Examples at: http://www.whitespace-creative.com/jquery/jnice/
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* To Use: place in the head
* <link href="inc/style/jNice_wev8.css" rel="stylesheet" type="text/css" />
* <script type="text/javascript" src="inc/js/jquery.jNice_wev8.js"></script>
*
* And apply the jNice class to the form you want to style
*
* To Do: Add textareas, Add File upload
*
******************************************** */
(function($){
$.fn.jNice = function(options){
/*if(window.location.href.indexOf("AddRequest")!=-1 ||window.location.href.indexOf("ManageRequest")!=-1||window.location.href.indexOf("ViewRequest")!=-1){
return;
}*/
var isNewPlugisCheckbox = jQuery("#isNewPlugisCheckbox");
if(isNewPlugisCheckbox.length>0&&isNewPlugisCheckbox.val()!="1"){
return;
}
var self = this;
var safari = $.browser.safari; /* We need to check for safari to fix the input:text problem */
/* Apply document listener */
$(document).mousedown(checkExternalClick);
/* each form */
return this.each(function(){
//$('input:submit, input:reset, input:button', this).each(ButtonAdd);
//$('button').focus(function(){ $(this).addClass('jNiceFocus')}).blur(function(){ $(this).removeClass('jNiceFocus')});
//$('input:text:visible, input:password', this).each(TextAdd);
/* If this is safari we need to add an extra class */
//if (safari){$('.jNiceInputWrapper').each(function(){$(this).addClass('jNiceSafari').find('input').css('width', $(this).width()+11);});}
$('input:checkbox', this).each(CheckAdd);
$('input:radio', this).each(RadioAdd);
//$('select', this).each(function(index){ SelectAdd(this, index); });
/* Add a new handler for the reset action */
//$(this).bind('reset',function(){var action = function(){ Reset(this); }; window.setTimeout(action, 10); });
$('.jNiceHidden').css({opacity:0});
});
};/* End the Plugin */
var Reset = function(form){
var sel;
$('.jNiceSelectWrapper select', form).each(function(){sel = (this.selectedIndex<0) ? 0 : this.selectedIndex; $('ul', $(this).parent()).each(function(){$('a:eq('+ sel +')', this).click();});});
$('a.jNiceCheckbox, a.jNiceRadio', form).removeClass('jNiceChecked');
$('input:checkbox, input:radio', form).each(function(){if(this.checked){$('a', $(this).parent()).addClass('jNiceChecked');}});
};
var RadioAdd = function(){
var $this = jQuery(this);
if($this.css("display")=="none" || $this.hasClass("jNiceHidden") || $this.attr("tzCheckbox")=="true" || $this.attr("notBeauty")){
return;
}
$this.bind("display",function(e,display){
toggleBeautyRadio.call(this,display);
}).bind("checked",function(e,checked){
changeRadioStatus.call(this,checked);
}).bind("disabled",function(e,disabled){
disOrEnableRadio.call(this,disabled);
}).bind("rbeauty",function(e){
removeBeatyRadio.call(this);
});
var $input = $this.addClass('jNiceHidden').wrap('<span class="jRadioWrapper jNiceWrapper"></span>');
var $wrapper = null;
if($this.attr("disabled")||$this.attr("readonly")){
$wrapper = $input.parent().append('<span class="jNiceRadio_disabled"></span>');
}else{
$wrapper = $input.parent().append('<span class="jNiceRadio"></span>');
}
/* Click Handler */
$a= $wrapper.find('.jNiceRadio,.jNiceRadio_disabled').click(function(){
var $a = $(this);
var input = $a.siblings('input')[0];
if(jQuery(input).attr("disabled")||jQuery(input).attr("readonly")){
return;
}
if (input.checked===true){
//input.checked = false;
//$a.removeClass('jNiceChecked');
}
else {
input.checked = true;
$a.addClass('jNiceChecked');
}
jQuery(input).trigger("click");
//input.checked = !input.checked;
//var $input = $(this).addClass('jNiceChecked').siblings('input').attr('checked',true);
/* uncheck all others of same name */
$('input:radio[name="'+ $input.attr('name') +'"]').not($input).each(function(){
$(this).attr('checked',false).siblings('.jNiceRadio').removeClass('jNiceChecked');
});
//console.log(input.checked);
return false;
});
/*$input.click(function(){
if(this.checked){
var $input = $(this).siblings('.jNiceRadio').addClass('jNiceChecked').end();
// uncheck all others of same name
$('input:radio[name="'+ $input.attr('name') +'"]').not($input).each(function(){
$(this).attr('checked',false).siblings('.jNiceRadio').removeClass('jNiceChecked');
});
}
}).focus(function(){ $a.addClass('jNiceFocus'); }).blur(function(){ $a.removeClass('jNiceFocus'); });*/
$input.focus(function(){ $a.addClass('jNiceFocus'); }).blur(function(){ $a.removeClass('jNiceFocus'); });
/* set the default state */
if (this.checked){
if($this.attr("disabled")||$this.attr("readonly")){
$('.jNiceRadio_disabled', $wrapper).addClass('jNiceChecked_disabled');
}else{
$('.jNiceRadio', $wrapper).addClass('jNiceChecked');
}
}
};
var CheckAdd = function(){
var $this = jQuery(this);
if($this.css("display")=="none" || $this.hasClass("jNiceHidden") || $this.attr("tzCheckbox")=="true" || $this.attr("notBeauty")){
return;
}
$this.bind("display",function(e,display){
toggleBeautyCheckbox.call(this,display);
}).bind("checked",function(e,checked){
changeCheckboxStatus.call(this,checked);
}).bind("disabled",function(e,disabled){
disOrEnableCheckbox.call(this,disabled);
}).bind("rbeauty",function(e){
removeBeatyCheckbox.call(this);
});
var $input = $this.addClass('jNiceHidden').wrap('<span class="jNiceWrapper"></span>');
var $wrapper = null;
if($this.attr("disabled")||$this.attr("readonly")){
$wrapper = $input.parent().append('<span class="jNiceCheckbox_disabled"></span>');
$input.hide();
}else{
$wrapper = $input.parent().append('<span class="jNiceCheckbox"></span>');
}
/* Click Handler */
var $a = $wrapper.find('.jNiceCheckbox,.jNiceCheckbox_disabled').click(function(){
var $a = $(this);
var input = $a.siblings('input')[0];
if(jQuery(input).attr("disabled")||jQuery(input).attr("readonly")==true){
jQuery(input).hide();
return;
}
if (input.checked===true){
input.checked = false;
$a.removeClass('jNiceChecked');
}
else {
input.checked = true;
$a.addClass('jNiceChecked');
}
jQuery(input).trigger("click");
input.checked = !input.checked;
return false;
});
$input.focus(function(){ $a.addClass('jNiceFocus'); }).blur(function(){ $a.removeClass('jNiceFocus'); });
/* set the default state */
if (this.checked){
if($this.attr("disabled")||$this.attr("readonly")){
$('.jNiceCheckbox_disabled', $wrapper).addClass('jNiceChecked_disabled');
}else{
$('.jNiceCheckbox', $wrapper).addClass('jNiceChecked');
}
}
};
var TextAdd = function(){
var $input = $(this).addClass('jNiceInput').wrap('<div class="jNiceInputWrapper"><div class="jNiceInputInner"></div></div>');
var $wrapper = $input.parents('.jNiceInputWrapper');
$input.focus(function(){
$wrapper.addClass('jNiceInputWrapper_hover');
}).blur(function(){
$wrapper.removeClass('jNiceInputWrapper_hover');
});
};
var ButtonAdd = function(){
var value = $(this).attr('value');
$(this).replaceWith('<button id="'+ this.id +'" name="'+ this.name +'" type="'+ this.type +'" class="'+ this.className +'" value="'+ value +'"><span><span>'+ value +'</span></span>');
};
/* Hide all open selects */
var SelectHide = function(){
$('.jNiceSelectWrapper ul:visible').hide();
};
/* Check for an external click */
var checkExternalClick = function(event) {
if ($(event.target).parents('.jNiceSelectWrapper').length === 0) { SelectHide(); }
};
var SelectAdd = function(element, index){
var $select = $(element);
index = index || $select.css('zIndex')*1;
index = (index) ? index : 0;
/* First thing we do is Wrap it */
$select.wrap($('<div class="jNiceWrapper"></div>').css({zIndex: 100-index}));
var width = $select.width();
$select.addClass('jNiceHidden').after('<div class="jNiceSelectWrapper"><div><span class="jNiceSelectText"></span><span class="jNiceSelectOpen"></span></div><ul></ul></div>');
var $wrapper = $(element).siblings('.jNiceSelectWrapper').css({width: width +'px'});
$('.jNiceSelectText, .jNiceSelectWrapper ul', $wrapper).width( width - $('.jNiceSelectOpen', $wrapper).width());
/* IF IE 6 */
if ($.browser.msie && jQuery.browser.version < 7) {
$select.after($('<iframe src="javascript:\'\';" marginwidth="0" marginheight="0" align="bottom" scrolling="no" tabIndex="-1" frameborder="0"></iframe>').css({ height: $select.height()+4 +'px' }));
}
/* Now we add the options */
SelectUpdate(element);
/* Apply the click handler to the Open */
$('div', $wrapper).click(function(){
var $ul = $(this).siblings('ul');
if ($ul.css('display')=='none'){ SelectHide(); } /* Check if box is already open to still allow toggle, but close all other selects */
$ul.slideToggle();
var offSet = ($('a.selected', $ul).offset().top - $ul.offset().top);
$ul.animate({scrollTop: offSet});
return false;
});
/* Add the key listener */
$select.keydown(function(e){
var selectedIndex = this.selectedIndex;
switch(e.keyCode){
case 40: /* Down */
if (selectedIndex < this.options.length - 1){ selectedIndex+=1; }
break;
case 38: /* Up */
if (selectedIndex > 0){ selectedIndex-=1; }
break;
default:
return;
break;
}
$('ul a', $wrapper).removeClass('selected').eq(selectedIndex).addClass('selected');
$('span:eq(0)', $wrapper).html($('option:eq('+ selectedIndex +')', $select).attr('selected', 'selected').text());
return false;
}).focus(function(){ $wrapper.addClass('jNiceFocus'); }).blur(function(){ $wrapper.removeClass('jNiceFocus'); });
};
var SelectUpdate = function(element){
var $select = $(element);
var $wrapper = $select.siblings('.jNiceSelectWrapper');
var $ul = $wrapper.find('ul').find('li').remove().end().hide();
$('option', $select).each(function(i){
$ul.append('<li><a href="#" index="'+ i +'">'+ this.text +'</a></li>');
});
/* Add click handler to the a */
$ul.find('a').click(function(){
$('a.selected', $wrapper).removeClass('selected');
$(this).addClass('selected');
/* Fire the onchange event */
if ($select[0].selectedIndex != $(this).attr('index') && $select[0].onchange) { $select[0].selectedIndex = $(this).attr('index'); $select[0].onchange(); }
$select[0].selectedIndex = $(this).attr('index');
$('span:eq(0)', $wrapper).html($(this).html());
$ul.hide();
return false;
});
/* Set the defalut */
$('a:eq('+ $select[0].selectedIndex +')', $ul).click();
};
var SelectRemove = function(element){
var zIndex = $(element).siblings('.jNiceSelectWrapper').css('zIndex');
$(element).css({zIndex: zIndex}).removeClass('jNiceHidden');
$(element).siblings('.jNiceSelectWrapper').remove();
};
//功能:显示/隐藏checkbox
//事件名:display
//params:display,取值同css的display
//调用方式:jQuery("#box").trigger("display","none")
var toggleBeautyCheckbox = function(display){
jQuery(this).next("span.jNiceCheckbox").css("display",display);
}
//功能:修改checkbox选中状态
//事件名:checked
//params:checked,取值true|false
//调用方式:jQuery("#box").trigger("checked",true)
var changeCheckboxStatus = function(checked){
if(jQuery(this).attr("disabled")||jQuery(this).attr("readonly"))return;
if(checked==true||checked==false){
jQuery(this).attr("checked",checked);
}
if(checked){
jQuery(this).next("span.jNiceCheckbox").addClass("jNiceChecked");
}else{
jQuery(this).next("span.jNiceCheckbox").removeClass("jNiceChecked");
}
}
//功能:修改checkbox禁用状态
//事件名:disabled
//params:disabled,取值true|false
//调用方式:jQuery("#box").trigger("disabled",true)
var disOrEnableCheckbox = function(disabled){
var obj = this;
if(disabled==true||disabled==false){
jQuery(obj).attr("disabled",disabled);
}
if(disabled){
if(obj.checked){
jQuery(obj).next("span.jNiceCheckbox").removeClass("jNiceCheckbox").removeClass("jNiceChecked").addClass("jNiceCheckbox_disabled").addClass("jNiceChecked_disabled");
}else{
jQuery(obj).next("span.jNiceCheckbox").removeClass("jNiceCheckbox").removeClass("jNiceChecked").addClass("jNiceCheckbox_disabled").removeClass("jNiceChecked_disabled");
}
}else{
if(obj.checked){
jQuery(obj).next("span.jNiceCheckbox_disabled").removeClass("jNiceCheckbox_disabled").removeClass("jNiceChecked_disabled").addClass("jNiceCheckbox").addClass("jNiceChecked");
}else{
jQuery(obj).next("span.jNiceCheckbox_disabled").removeClass("jNiceCheckbox_disabled").removeClass("jNiceChecked_disabled").addClass("jNiceCheckbox").removeClass("jNiceChecked");
}
}
}
//功能:解除美化
//事件名:rbeauty
//调用方式:jQuery("#box").trigger("rbeauty")
var removeBeatyCheckbox = function(){
var $obj = jQuery(this);
var $jNiceWrapper = $obj.closest("span.jNiceWrapper")
if($jNiceWrapper.length==0)return;
var container =$jNiceWrapper.parent();
var newObj =$obj.clone().removeClass("jNiceHidden");
$jNiceWrapper.remove();
newObj.css("opacity","1").show();
container.append(newObj);
}
//功能:显示/隐藏radio
//事件名:display
//params:display,取值同css的display
//调用方式:jQuery("#box").trigger("display","none")
var toggleBeautyRadio = function(display){
jQuery(this).next("span.jNiceRadio").css("display",display);
}
//功能:修改radio选中状态
//事件名:checked
//params:checked,取值true|false
//调用方式:jQuery("#box").trigger("checked",true)
var changeRadioStatus = function(checked){
var $input = jQuery(this);
if($input.attr("disabled")||$input.attr("readonly"))return;
if(checked==true||checked==false){
jQuery(this).attr("checked",checked);
}
if(checked){
jQuery(this).next("span.jNiceRadio").addClass("jNiceChecked");
}else{
jQuery(this).next("span.jNiceRadio").removeClass("jNiceChecked");
}
$('input:radio[name="'+ $input.attr('name') +'"]').not($input).each(function(){
$(this).attr('checked',false).siblings('.jNiceRadio').removeClass('jNiceChecked');
});
}
//功能:修改radio禁用状态
//事件名:disabled
//params:disabled,取值true|false
//调用方式:jQuery("#box").trigger("disabled",true)
var disOrEnableRadio = function(disabled){
var obj = this;
if(disabled==true||disabled==false){
jQuery(obj).attr("disabled",disabled);
}
if(disabled){
if(obj.checked){
jQuery(obj).next("span.jNiceRadio").removeClass("jNiceRadio").removeClass("jNiceChecked").addClass("jNiceRadio_disabled").addClass("jNiceChecked_disabled");
}else{
jQuery(obj).next("span.jNiceRadio").removeClass("jNiceRadio").removeClass("jNiceChecked").addClass("jNiceRadio_disabled").removeClass("jNiceChecked_disabled");
}
}else{
if(obj.checked){
jQuery(obj).next("span.jNiceRadio_disabled").removeClass("jNiceRadio_disabled").removeClass("jNiceChecked_disabled").addClass("jNiceRadio").addClass("jNiceChecked");
}else{
jQuery(obj).next("span.jNiceRadio_disabled").removeClass("jNiceRadio_disabled").removeClass("jNiceChecked_disabled").addClass("jNiceRadio").removeClass("jNiceChecked");
}
}
}
//功能:解除美化
//事件名:rbeauty
//调用方式:jQuery("#box").trigger("rbeauty")
var removeBeatyRadio = function(){
var $obj = jQuery(this);
var $jNiceWrapper = $obj.closest("span.jNiceWrapper")
if($jNiceWrapper.length==0)return;
var container =$jNiceWrapper.parent();
var newObj =$obj.clone().removeClass("jNiceHidden");
$jNiceWrapper.remove();
newObj.css("opacity","1").show();
container.append(newObj);
}
/* Utilities */
$.jNice = {
SelectAdd : function(element, index){ SelectAdd(element, index); },
SelectRemove : function(element){ SelectRemove(element); },
SelectUpdate : function(element){ SelectUpdate(element); },
CheckAdd: function(){CheckAdd();},
RadioAdd: function(){RadioAdd();}
};/* End Utilities */
/* Automatically apply to any forms with class jNice */
//$(function(){$('body').jNice(); });
})(jQuery);
//@deprecated
function toggleBeautyCheckbox(obj,display){
jQuery(obj).trigger("display",display);
}
//@deprecated
function changeCheckboxStatus(obj,checked){
jQuery(obj).trigger("checked",checked);
}
//@deprecated
function disOrEnableCheckbox(obj,disabled){
jQuery(obj).trigger("disabled",disabled);
}
//@deprecated
function removeBeatyCheckbox(obj){
jQuery(obj).trigger("rbeauty");
}
//@deprecated
function toggleBeautyRadio(obj,display){
//jQuery(obj).next("span.jNiceRadio").css("display",display);
jQuery(obj).trigger("display",display);
}
//@deprecated
function changeRadioStatus(obj,checked){
jQuery(obj).trigger("checked",checked);
}
//@deprecated
function disOrEnableRadio(obj,disabled){
jQuery(obj).trigger("disabled",disabled);
}
//@deprecated
function removeBeatyRadio(obj){
jQuery(obj).trigger("rbeauty");
}