Skip to content
This repository was archived by the owner on Dec 27, 2021. It is now read-only.

Commit ae264fc

Browse files
committed
1.7.6
1 parent 655fc8a commit ae264fc

File tree

7 files changed

+143
-55
lines changed

7 files changed

+143
-55
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# История изменений
22

3+
## 1.7.6 <sup>05.06.2016</sup>
4+
- Добавлено: поддержка дробных чисел в `<input type="number">`.
5+
- Добавлено: поддержка передаваемых классов и атрибутов в `<input type="number">`.
6+
- Изменено: рефакторинг кода передаваемых классов и атрибутов от оригинальных элементов.
7+
- Изменено: группы радиокнопок (с одинаковым атрибутом `name`) теперь работают и вне тега `<form>`. В связи с этим удалена опция `wrapper`.
8+
- Изменено: подкорректированы стили для `<input type="file">`, чтобы в браузерах на движке Blink `cursor: pointer` срабатывал по всему полю.
9+
- Исправлено: улучшен расчет высоты выпадающего списка в селекте, он мог выходить за пределы экрана ([#93](https://github.com/Dimox/jQueryFormStyler/pull/93)).
10+
- Исправлено: улучшена скорость подсчета ширины селекта на больших списках ([#95](https://github.com/Dimox/jQueryFormStyler/pull/95)).
11+
- Исправлено: плейсхолдер в селекте теперь отображается только в случае, если по умолчанию выбран первый пункт с отсутствующим текстом.
12+
313
## 1.7.5 <sup>29.05.2016</sup>
414
- Добавлено: поддержка события `change` для тега `<input type="number">`.
515
- Исправлено: выпадающий список селекта не раскрывался вверх в тех случаях, когда должен был.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# jQuery Form Styler <sup>[1.7.5](https://github.com/Dimox/jQueryFormStyler/blob/master/CHANGELOG.md)</sup>
1+
# jQuery Form Styler <sup>[1.7.6](https://github.com/Dimox/jQueryFormStyler/blob/master/CHANGELOG.md)</sup>
22

33
jQuery-плагин для стилизации элементов HTML-форм:
44

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-form-styler",
3-
"version": "1.7.5",
3+
"version": "1.7.6",
44
"main": [
55
"jquery.formstyler.min.js",
66
"jquery.formstyler.css"

demo/index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
<h1>Примеры для плагина <a href="http://dimox.name/jquery-form-styler/">jQuery Form Styler</a></h1>
2626

27-
<form method="post">
2827
<div class="wrapper">
2928

3029
<ul class="menu">
@@ -320,7 +319,7 @@ <h2>Одиночные селекты</h2>
320319
<div class="sec">
321320
<p>Селект <strong>с замещающим текстом</strong> (placeholder). Текст "-- Выберите --" задан не через тег <code>option</code>, а через атрибут <code>data-placeholder</code>.</p>
322321
<select data-placeholder="-- Выберите --">
323-
<option label="-"></option>
322+
<option></option>
324323
<option>Пункт 1</option>
325324
<option>Пункт 2</option>
326325
<option>Пункт 3</option>
@@ -504,7 +503,6 @@ <h2>Прочие элементы форм (только CSS)</h2>
504503
</div><!-- .content -->
505504

506505
</div><!-- .wrapper -->
507-
</form>
508506

509507
</body>
510508
</html>

jquery.formstyler.js

Lines changed: 127 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* jQuery Form Styler v1.7.5
2+
* jQuery Form Styler v1.7.6
33
* https://github.com/Dimox/jQueryFormStyler
44
*
55
* Copyright 2012-2016 Dimox (http://dimox.name/)
66
* Released under the MIT license.
77
*
8-
* Date: 2016.05.29
8+
* Date: 2016.06.05
99
*
1010
*/
1111

@@ -25,7 +25,6 @@
2525

2626
var pluginName = 'styler',
2727
defaults = {
28-
wrapper: 'form',
2928
idSuffix: '-styler',
3029
filePlaceholder: 'Файл не выбран',
3130
fileBrowse: 'Обзор...',
@@ -61,21 +60,12 @@
6160
var Android = (navigator.userAgent.match(/Android/i) && !navigator.userAgent.match(/(Windows\sPhone)/i)) ? true : false;
6261

6362
function Attributes() {
64-
var id = '',
65-
title = '',
66-
classes = '',
67-
dataList = '';
68-
if (el.attr('id') !== undefined && el.attr('id') !== '') id = ' id="' + el.attr('id') + opt.idSuffix + '"';
69-
if (el.attr('title') !== undefined && el.attr('title') !== '') title = ' title="' + el.attr('title') + '"';
70-
if (el.attr('class') !== undefined && el.attr('class') !== '') classes = ' ' + el.attr('class');
71-
var data = el.data();
72-
for (var i in data) {
73-
if (data[i] !== '' && i !== '_styler') dataList += ' data-' + i + '="' + data[i] + '"';
63+
if (el.attr('id') !== undefined && el.attr('id') !== '') {
64+
this.id = el.attr('id') + opt.idSuffix;
7465
}
75-
id += dataList;
76-
this.id = id;
77-
this.title = title;
78-
this.classes = classes;
66+
this.title = el.attr('title');
67+
this.classes = el.attr('class');
68+
this.data = el.data();
7969
}
8070

8171
// checkbox
@@ -84,7 +74,14 @@
8474
var checkboxOutput = function() {
8575

8676
var att = new Attributes();
87-
var checkbox = $('<div' + att.id + ' class="jq-checkbox' + att.classes + '"' + att.title + '><div class="jq-checkbox__div"></div></div>');
77+
var checkbox = $('<div class="jq-checkbox"><div class="jq-checkbox__div"></div></div>')
78+
.attr({
79+
id: att.id,
80+
title: att.title
81+
})
82+
.addClass(att.classes)
83+
.data(att.data)
84+
;
8885

8986
// прячем оригинальный чекбокс
9087
el.css({
@@ -165,7 +162,14 @@
165162
var radioOutput = function() {
166163

167164
var att = new Attributes();
168-
var radio = $('<div' + att.id + ' class="jq-radio' + att.classes + '"' + att.title + '><div class="jq-radio__div"></div></div>');
165+
var radio = $('<div class="jq-radio"><div class="jq-radio__div"></div></div>')
166+
.attr({
167+
id: att.id,
168+
title: att.title
169+
})
170+
.addClass(att.classes)
171+
.data(att.data)
172+
;
169173

170174
// прячем оригинальную радиокнопку
171175
el.css({
@@ -189,11 +193,24 @@
189193
if (el.is(':checked')) radio.addClass('checked');
190194
if (el.is(':disabled')) radio.addClass('disabled');
191195

196+
// определяем общего родителя у радиокнопок с одинаковым name
197+
// http://stackoverflow.com/a/27733847
198+
$.fn.commonParents = function (){
199+
var cachedThis = this;
200+
return cachedThis.first().parents().filter(function () {
201+
return $(this).find(cachedThis).length === cachedThis.length;
202+
});
203+
};
204+
$.fn.commonParent = function (){
205+
return $(this).commonParents().first();
206+
};
207+
192208
// клик на псевдорадиокнопке
193209
radio.click(function(e) {
194210
e.preventDefault();
195211
if (!radio.is('.disabled')) {
196-
radio.closest(opt.wrapper).find('input[name="' + el.attr('name') + '"]').prop('checked', false).parent().removeClass('checked');
212+
var inputName = $('input[name="' + el.attr('name') + '"]');
213+
inputName.commonParent().find(inputName).prop('checked', false).parent().removeClass('checked');
197214
el.prop('checked', true).parent().addClass('checked');
198215
el.focus().change();
199216
}
@@ -237,11 +254,10 @@
237254
position: 'absolute',
238255
top: 0,
239256
right: 0,
240-
width: '100%',
241-
height: '100%',
242-
opacity: 0,
243257
margin: 0,
244-
padding: 0
258+
padding: 0,
259+
opacity: 0,
260+
fontSize: '100px'
245261
});
246262

247263
var fileOutput = function() {
@@ -251,15 +267,31 @@
251267
if (placeholder === undefined) placeholder = opt.filePlaceholder;
252268
var browse = el.data('browse');
253269
if (browse === undefined || browse === '') browse = opt.fileBrowse;
254-
var file = $('<div' + att.id + ' class="jq-file' + att.classes + '"' + att.title + ' style="display: inline-block; position: relative; overflow: hidden"></div>');
255-
var name = $('<div class="jq-file__name">' + placeholder + '</div>').appendTo(file);
256-
$('<div class="jq-file__browse">' + browse + '</div>').appendTo(file);
257-
el.after(file).appendTo(file);
258270

271+
var file =
272+
$('<div class="jq-file">' +
273+
'<div class="jq-file__name">' + placeholder + '</div>' +
274+
'<div class="jq-file__browse">' + browse + '</div>' +
275+
'</div>')
276+
.css({
277+
display: 'inline-block',
278+
position: 'relative',
279+
overflow: 'hidden'
280+
})
281+
.attr({
282+
id: att.id,
283+
title: att.title
284+
})
285+
.addClass(att.classes)
286+
.data(att.data)
287+
;
288+
289+
el.after(file).appendTo(file);
259290
if (el.is(':disabled')) file.addClass('disabled');
260291

261292
el.on('change.styler', function() {
262293
var value = el.val();
294+
var name = $('div.jq-file__name', file);
263295
if (el.is('[multiple]')) {
264296
value = '';
265297
var files = el[0].files.length;
@@ -304,9 +336,21 @@
304336

305337
var numberOutput = function() {
306338

307-
var number = $('<div class="jq-number"><div class="jq-number__spin minus"></div><div class="jq-number__spin plus"></div></div>');
308-
el.after(number).prependTo(number).wrap('<div class="jq-number__field"></div>');
339+
var att = new Attributes();
340+
var number =
341+
$('<div class="jq-number">' +
342+
'<div class="jq-number__spin minus"></div>' +
343+
'<div class="jq-number__spin plus"></div>' +
344+
'</div>')
345+
.attr({
346+
id: att.id,
347+
title: att.title
348+
})
349+
.addClass(att.classes)
350+
.data(att.data)
351+
;
309352

353+
el.after(number).prependTo(number).wrap('<div class="jq-number__field"></div>');
310354
if (el.is(':disabled')) number.addClass('disabled');
311355

312356
var min,
@@ -324,17 +368,27 @@
324368
var changeValue = function(spin) {
325369
var value = el.val(),
326370
newValue;
371+
327372
if (!$.isNumeric(value)) {
328373
value = 0;
329374
el.val('0');
330375
}
376+
331377
if (spin.is('.minus')) {
332-
newValue = parseInt(value, 10) - step;
333-
if (step > 0) newValue = Math.ceil(newValue / step) * step;
378+
newValue = Number(value) - step;
334379
} else if (spin.is('.plus')) {
335-
newValue = parseInt(value, 10) + step;
336-
if (step > 0) newValue = Math.floor(newValue / step) * step;
380+
newValue = Number(value) + step;
381+
}
382+
383+
// определяем количество десятичных знаков после запятой в step
384+
var decimals = (step.toString().split('.')[1] || []).length;
385+
if (decimals > 0) {
386+
var multiplier = '1';
387+
while (multiplier.length <= decimals) multiplier = multiplier + '0';
388+
// избегаем появления лишних знаков после запятой
389+
newValue = Math.round(newValue * multiplier) / multiplier;
337390
}
391+
338392
if ($.isNumeric(min) && $.isNumeric(max)) {
339393
if (newValue >= min && newValue <= max) el.val(newValue);
340394
} else if ($.isNumeric(min) && !$.isNumeric(max)) {
@@ -448,8 +502,8 @@
448502

449503
// одиночный селект
450504
function doSelect() {
451-
var att = new Attributes();
452505

506+
var att = new Attributes();
453507
var searchHTML = '';
454508
var selectPlaceholder = el.data('placeholder');
455509
var selectSearch = el.data('search');
@@ -468,12 +522,25 @@
468522
if (selectSmartPositioning === undefined || selectSmartPositioning === '') selectSmartPositioning = opt.selectSmartPositioning;
469523

470524
var selectbox =
471-
$('<div' + att.id + ' class="jq-selectbox jqselect' + att.classes + '" style="display: inline-block; position: relative; z-index:' + singleSelectzIndex + '">' +
472-
'<div class="jq-selectbox__select"' + att.title + ' style="position: relative">' +
525+
$('<div class="jq-selectbox jqselect">' +
526+
'<div class="jq-selectbox__select" style="position: relative">' +
473527
'<div class="jq-selectbox__select-text"></div>' +
474-
'<div class="jq-selectbox__trigger"><div class="jq-selectbox__trigger-arrow"></div></div>' +
528+
'<div class="jq-selectbox__trigger">' +
529+
'<div class="jq-selectbox__trigger-arrow"></div></div>' +
475530
'</div>' +
476-
'</div>');
531+
'</div>')
532+
.css({
533+
display: 'inline-block',
534+
position: 'relative',
535+
zIndex: singleSelectzIndex
536+
})
537+
.attr({
538+
id: att.id,
539+
title: att.title
540+
})
541+
.addClass(att.classes)
542+
.data(att.data)
543+
;
477544

478545
el.css({margin: 0, padding: 0}).after(selectbox).prependTo(selectbox);
479546

@@ -499,8 +566,8 @@
499566
if (li.length < selectSearchLimit) search.parent().hide();
500567

501568
// показываем опцию по умолчанию
502-
// если 1-я опция пустая и выбрана по умолчанию, то показываем плейсхолдер
503-
if (el.val() === '') {
569+
// если у 1-й опции нет текста и она выбрана по умолчанию, то показываем плейсхолдер
570+
if (option.first().text() === '' && option.first().is(':selected')) {
504571
divText.text(selectPlaceholder).addClass('placeholder');
505572
} else {
506573
divText.text(optionSelected.text());
@@ -509,15 +576,15 @@
509576
// определяем самый широкий пункт селекта
510577
var liWidthInner = 0,
511578
liWidth = 0;
579+
li.css({'display': 'inline-block'});
512580
li.each(function() {
513581
var l = $(this);
514-
l.css({'display': 'inline-block'});
515582
if (l.innerWidth() > liWidthInner) {
516583
liWidthInner = l.innerWidth();
517584
liWidth = l.width();
518585
}
519-
l.css({'display': ''});
520586
});
587+
li.css({'display': ''});
521588

522589
// подстраиваем ширину свернутого селекта в зависимости
523590
// от ширины плейсхолдера или самого широкого пункта
@@ -551,8 +618,8 @@
551618
opacity: 0
552619
});
553620

554-
var selectHeight = selectbox.outerHeight();
555-
var searchHeight = search.outerHeight();
621+
var selectHeight = selectbox.outerHeight(true);
622+
var searchHeight = search.parent().outerHeight(true);
556623
var isMaxHeight = ul.css('max-height');
557624
var liSelected = li.filter('.selected');
558625
if (liSelected.length < 1) li.first().addClass('selected sel');
@@ -822,8 +889,21 @@
822889

823890
// мультиселект
824891
function doMultipleSelect() {
892+
825893
var att = new Attributes();
826-
var selectbox = $('<div' + att.id + ' class="jq-select-multiple jqselect' + att.classes + '"' + att.title + ' style="display: inline-block; position: relative"></div>');
894+
var selectbox =
895+
$('<div class="jq-select-multiple jqselect"></div>')
896+
.css({
897+
display: 'inline-block',
898+
position: 'relative'
899+
})
900+
.attr({
901+
id: att.id,
902+
title: att.title
903+
})
904+
.addClass(att.classes)
905+
.data(att.data)
906+
;
827907

828908
el.css({margin: 0, padding: 0}).after(selectbox);
829909

@@ -991,7 +1071,7 @@
9911071
} else if (el.is(':reset')) {
9921072
el.on('click', function() {
9931073
setTimeout(function() {
994-
el.closest(opt.wrapper).find('input, select').trigger('refresh');
1074+
el.closest('form').find('input, select').trigger('refresh');
9951075
}, 1);
9961076
});
9971077
} // end reset

jquery.formstyler.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-form-styler",
3-
"version": "1.7.5",
3+
"version": "1.7.6",
44
"description": "jQuery-плагин для стилизации элементов HTML-форм",
55
"main": [
66
"jquery.formstyler.min.js",

0 commit comments

Comments
 (0)