Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
K
kpp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexandr Veselov
kpp
Commits
696a4643
Commit
696a4643
authored
Feb 21, 2016
by
Nikolay Gromov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nice field file
parent
55d549d4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
8 deletions
+90
-8
_blocks_library.html
src/_blocks_library.html
+7
-7
script.js
src/js/script.js
+39
-0
field-file.less
src/less/blocks/field-file.less
+44
-1
No files found.
src/_blocks_library.html
View file @
696a4643
...
...
@@ -371,14 +371,14 @@
<small
class=
"field-select__help-text"
>
Обёртка —
<code>
<
label
>
</code>
.
</small>
</div>
</label>
<
label
class=
"field-file"
>
<
div
class=
"field-file"
>
<div
class=
"field-file__name"
>
Название поля
</div>
<
div
class=
"field-file__input-wrap"
>
<input
class=
"field-file__input"
type=
"file"
>
<div
class=
"field-file__
help-text"
>
Обёртка —
<code>
<
label
>
</code>
.
</div>
</div>
</label>
<
label
class=
"field-file__input-wrap"
>
<input
class=
"field-file__input"
type=
"file"
data-multiple-caption=
"файлов выбрано: {count}"
multiple
>
<div
class=
"field-file__
name-text"
data-button-text=
"Выбрать файл"
>
Файлы не выбраны
</div>
<div
class=
"field-file__help-text"
>
Работа этого стилизованного поля требует Javascript-а.
</div>
</label>
</div>
<div
class=
"field-actions"
>
<button
class=
"btn"
>
Отправить
</button>
</div>
...
...
src/js/script.js
View file @
696a4643
'use strict'
;
/*
Форма: работа стилизованного input[type="file"]
Автор: Osvaldas Valutis, www.osvaldas.info
Available for use under the MIT License
*/
;(
function
(
document
,
window
,
index
)
{
var
inputs
=
document
.
querySelectorAll
(
'.field-file__input'
);
Array
.
prototype
.
forEach
.
call
(
inputs
,
function
(
input
)
{
var
label
=
input
.
nextElementSibling
,
labelVal
=
label
.
innerHTML
;
input
.
addEventListener
(
'change'
,
function
(
e
)
{
var
fileName
=
''
;
if
(
this
.
files
&&
this
.
files
.
length
>
1
)
{
fileName
=
(
this
.
getAttribute
(
'data-multiple-caption'
)
||
''
).
replace
(
'{count}'
,
this
.
files
.
length
);
}
else
{
fileName
=
e
.
target
.
value
.
split
(
'
\
\'
).pop();
}
if( fileName ) {
label.innerHTML = fileName;
}
else {
label.innerHTML = labelVal;
}
});
});
}( document, window, 0 ));
// $(document).ready(function() {
// alert('
fuck
jQuery
');
// });
src/less/blocks/field-file.less
View file @
696a4643
...
...
@@ -8,10 +8,53 @@
margin-bottom: round(@line-height / 4, 2);
}
&__input-wrap {}
&__input-wrap {
display: block;
position: relative;
}
&__input {
position: absolute;
width: 1px;
height: 1px;
opacity: 0;
}
&__name-text {
position: relative;
background-color: #fff;
border: 1px solid @border-color;
border-radius: @border-radius;
display: inline-block;
vertical-align: middle;
width: 100%;
height: 2.125em; // 16 × 2.125 = 34
line-height: @line-height;
padding-right: @field-padding-horizontal;
margin-bottom: round(@line-height / 3, 2);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
&:before {
content: attr(data-button-text);
display: inline-block;
vertical-align: middle;
background-color: @gray-lighter;
border: 1px solid @border-color;
margin-right: @field-padding-horizontal;
height: 2.125em;
line-height: @line-height;
padding: @field-padding-top @field-padding-horizontal @field-padding-bottom;
transform: translateX(-1px) translateY(-1px);
border-top-left-radius: @border-radius;
border-bottom-left-radius: @border-radius;
}
.field-file__input:focus ~ & {
.focus();
}
}
&__help-text {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment