parent
2af3afe7a2
commit
b6f805f37c
@ -0,0 +1,52 @@
|
||||
.Form-tags {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
min-height: 38px;
|
||||
padding: 0;
|
||||
outline: none;
|
||||
border: 1px solid #CCC;
|
||||
border-radius: 4px;
|
||||
background: white;
|
||||
z-index: 2;
|
||||
}
|
||||
.Form-tagsList.tagit { padding: 0 5px 5px 5px }
|
||||
.Form-tagsList.tagit .tagit-choice {
|
||||
padding: 0 30px 0 11px;
|
||||
margin: 5px 5px 0 0;
|
||||
line-height: 28px;
|
||||
background: #EFF8FF;
|
||||
color: #746E76;
|
||||
border-radius: 2px;
|
||||
}
|
||||
.Form-tagsList.tagit .tagit-choice .tagit-close {
|
||||
line-height: normal;
|
||||
right: 10px;
|
||||
}
|
||||
.Form-tagsList.tagit .tagit-choice .tagit-close .text-icon {
|
||||
display: inline-block;
|
||||
color: #C5CCD1;
|
||||
&:hover { color: #AAA }
|
||||
}
|
||||
.Form-tagsList.tagit li.tagit-new { padding: 7px 4px 2px 7px }
|
||||
.Form-tagsList.tagit .ui-autocomplete-input::-webkit-input-placeholder {
|
||||
font-weight: $sFontWeight-normal;
|
||||
font-style: italic;
|
||||
color: #AAA
|
||||
}
|
||||
.Form-tagsList.tagit .ui-autocomplete-input::-moz-placeholder {
|
||||
font-weight: $sFontWeight-normal;
|
||||
font-style: italic;
|
||||
color: #AAA
|
||||
}
|
||||
.Form-tagsList.tagit .ui-autocomplete-input:-ms-placeholder {
|
||||
font-weight: $sFontWeight-normal;
|
||||
font-style: italic;
|
||||
color: #AAA
|
||||
}
|
||||
.Form-tags.is-focus { border-color: #999 }
|
||||
.Form-tags.is-disabled {
|
||||
background: $cStructure-grayBkg;
|
||||
|
||||
.tagit-choice { padding: 0 11px }
|
||||
.tagit-choice .tagit-close { display: none }
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
ul.tagit {
|
||||
padding: 1px 5px;
|
||||
overflow: auto;
|
||||
margin-left: inherit; /* usually we don't want the regular ul margins. */
|
||||
margin-right: inherit;
|
||||
}
|
||||
ul.tagit li {
|
||||
display: block;
|
||||
float: left;
|
||||
margin: 2px 5px 2px 0;
|
||||
}
|
||||
ul.tagit li.tagit-choice {
|
||||
padding: .2em 18px .2em .5em;
|
||||
position: relative;
|
||||
line-height: inherit;
|
||||
}
|
||||
ul.tagit li.tagit-new {
|
||||
padding: .25em 4px .25em 0;
|
||||
}
|
||||
|
||||
ul.tagit li.tagit-choice a.tagit-label {
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
}
|
||||
ul.tagit li.tagit-choice .tagit-close {
|
||||
cursor: pointer;
|
||||
position: absolute;
|
||||
right: .1em;
|
||||
top: 50%;
|
||||
margin-top: -8px;
|
||||
}
|
||||
|
||||
/* used for some custom themes that don't need image icons */
|
||||
ul.tagit li.tagit-choice .tagit-close .text-icon {
|
||||
display: none;
|
||||
}
|
||||
|
||||
ul.tagit li.tagit-choice input {
|
||||
display: block;
|
||||
float: left;
|
||||
margin: 2px 5px 2px 0;
|
||||
}
|
||||
ul.tagit input[type="text"] {
|
||||
-moz-box-sizing: border-box;
|
||||
-webkit-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
|
||||
border: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: inherit;
|
||||
background-color: inherit;
|
||||
outline: none;
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
var Backbone = require('backbone');
|
||||
|
||||
module.exports = Backbone.Collection.extend({
|
||||
|
||||
model: function (attrs, opts) {
|
||||
return new Backbone.Model(attrs, {
|
||||
label: attrs
|
||||
});
|
||||
}
|
||||
});
|
@ -0,0 +1,23 @@
|
||||
var CoreView = require('backbone/core-view');
|
||||
var _ = require('underscore');
|
||||
|
||||
var REQUIRED_OPTS = [
|
||||
'label'
|
||||
];
|
||||
|
||||
module.exports = CoreView.extend({
|
||||
tagName: 'li',
|
||||
|
||||
initialize: function (opts) {
|
||||
_.each(REQUIRED_OPTS, function (item) {
|
||||
if (!opts[item]) throw new Error(item + ' is required');
|
||||
this['_' + item] = opts[item];
|
||||
}, this);
|
||||
},
|
||||
|
||||
render: function () {
|
||||
this.clearSubViews();
|
||||
this.$el.html(this._label);
|
||||
return this;
|
||||
}
|
||||
});
|
@ -0,0 +1,112 @@
|
||||
var Backbone = require('backbone');
|
||||
var template = require('./number.tpl');
|
||||
var _ = require('underscore');
|
||||
require('jquery');
|
||||
require('jquery-ui');
|
||||
require('tagit');
|
||||
|
||||
Backbone.Form.editors.Taglist = Backbone.Form.editors.Base.extend({
|
||||
className: 'Form-tags',
|
||||
|
||||
initialize: function (opts) {
|
||||
this.options = _.extend(
|
||||
{},
|
||||
this.options,
|
||||
opts.schema.options
|
||||
);
|
||||
Backbone.Form.editors.Base.prototype.initialize.call(this, opts);
|
||||
this._initViews();
|
||||
},
|
||||
|
||||
_initViews: function () {
|
||||
this.$el.html(
|
||||
template({
|
||||
value: this.value
|
||||
})
|
||||
);
|
||||
|
||||
this.$('.js-slider').slider({
|
||||
range: 'min',
|
||||
value: this.value,
|
||||
min: this.options.min,
|
||||
max: this.options.max,
|
||||
step: this.options.step,
|
||||
orientation: 'horizontal',
|
||||
slide: this._onSlideChange.bind(this),
|
||||
stop: this._onSlideStop.bind(this)
|
||||
});
|
||||
},
|
||||
|
||||
_onSlideChange: function (ev, ui) {
|
||||
this.value = ui.value;
|
||||
this.$('.js-input').val(this.value);
|
||||
},
|
||||
|
||||
_onSlideStop: function (ev, ui) {
|
||||
this.trigger('change', this);
|
||||
},
|
||||
|
||||
_onInputKeyDown: function (e) {
|
||||
if (e.shiftKey === true) {
|
||||
if (e.which !== TAB_KEY_CODE && e.which !== LEFT_ARROW_KEY_CODE && e.which !== RIGHT_ARROW_KEY_CODE) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (e.which > NUMBER_NINE_KEY_CODE && e.which !== POINT_KEY_CODE) {
|
||||
return false;
|
||||
}
|
||||
if (e.which === SPACE_KEY_CODE) {
|
||||
return false;
|
||||
}
|
||||
if (e.which === ENTER_KEY_CODE) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_onInputKeyUp: function () {
|
||||
var value = this.$('.js-input').val();
|
||||
var isFloatNotCompleted = new RegExp(/\d+\.$/);
|
||||
var isDifferent = parseFloat(value) !== parseFloat(this.value);
|
||||
if (!isFloatNotCompleted.test(value) && isDifferent) {
|
||||
this.$('.js-slider').slider('value', value);
|
||||
this.value = value;
|
||||
this.trigger('change', this);
|
||||
}
|
||||
},
|
||||
|
||||
focus: function () {
|
||||
if (this.hasFocus) return;
|
||||
this.$('.js-input').focus();
|
||||
},
|
||||
|
||||
blur: function () {
|
||||
if (!this.hasFocus) return;
|
||||
this.$('.js-input').blur();
|
||||
},
|
||||
|
||||
getValue: function () {
|
||||
return this.$('.js-input').val();
|
||||
},
|
||||
|
||||
setValue: function (value) {
|
||||
this.$('.js-slider').slider('value', value);
|
||||
this.$('.js-input').val(value);
|
||||
this.value = value;
|
||||
},
|
||||
|
||||
_destroySlider: function () {
|
||||
if (this.$('.js-slider').data('ui-slider')) {
|
||||
this.$('.js-slider').slider('destroy');
|
||||
}
|
||||
},
|
||||
|
||||
remove: function () {
|
||||
this._destroySlider();
|
||||
Backbone.Form.editors.Base.prototype.remove.apply(this);
|
||||
},
|
||||
|
||||
clean: function () {
|
||||
this.$el.remove();
|
||||
}
|
||||
});
|
@ -0,0 +1 @@
|
||||
<ul class="Form-tagsList js-tagsList"></ul>
|
Loading…
Reference in new issue