2016-04-01 13:17:09 +00:00
|
|
|
/*
|
|
|
|
*
|
2019-01-17 13:05:03 +00:00
|
|
|
* (c) Copyright Ascensio System SIA 2010-2019
|
2016-04-01 13:17:09 +00:00
|
|
|
*
|
|
|
|
* This program is a free software product. You can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
|
|
|
* version 3 as published by the Free Software Foundation. In accordance with
|
|
|
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
|
|
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
|
|
|
* of any third-party rights.
|
|
|
|
*
|
|
|
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
|
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
|
|
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
|
|
|
*
|
2019-01-17 13:00:34 +00:00
|
|
|
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
|
|
|
* street, Riga, Latvia, EU, LV-1050.
|
2016-04-01 13:17:09 +00:00
|
|
|
*
|
|
|
|
* The interactive user interfaces in modified source and object code versions
|
|
|
|
* of the Program must display Appropriate Legal Notices, as required under
|
|
|
|
* Section 5 of the GNU AGPL version 3.
|
|
|
|
*
|
|
|
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
|
|
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
|
|
|
* grant you any rights under trademark law for use of our trademarks.
|
|
|
|
*
|
|
|
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
|
|
|
* well as technical writing content are licensed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
|
|
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
|
|
*
|
|
|
|
*/
|
2016-03-11 00:48:53 +00:00
|
|
|
/**
|
|
|
|
* MultiSliderGradient.js
|
|
|
|
*
|
|
|
|
* Created by Julia Radzhabova on 2/19/14
|
2018-03-01 12:16:38 +00:00
|
|
|
* Copyright (c) 2018 Ascensio System SIA. All rights reserved.
|
2016-03-11 00:48:53 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (Common === undefined)
|
|
|
|
var Common = {};
|
|
|
|
define([
|
|
|
|
'common/main/lib/component/Slider',
|
|
|
|
'underscore'
|
|
|
|
], function (base, _) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Common.UI.MultiSliderGradient = Common.UI.MultiSlider.extend({
|
|
|
|
|
|
|
|
options : {
|
|
|
|
width: 100,
|
|
|
|
minValue: 0,
|
|
|
|
maxValue: 100,
|
|
|
|
values: [0, 100],
|
|
|
|
colorValues: ['#000000', '#ffffff'],
|
2019-06-06 12:03:38 +00:00
|
|
|
currentThumb: 0,
|
|
|
|
thumbTemplate: '<div class="thumb img-commonctrl" style="">' +
|
|
|
|
'<div class="thumb-top"></div>' +
|
|
|
|
'<div class="thumb-bottom"></div>' +
|
|
|
|
'</div>'
|
2016-03-11 00:48:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
disabled: false,
|
|
|
|
|
|
|
|
template : _.template([
|
|
|
|
'<div class="slider multi-slider-gradient">',
|
|
|
|
'<div class="track"></div>',
|
|
|
|
'<% _.each(items, function(item) { %>',
|
2019-06-06 12:03:38 +00:00
|
|
|
'<%= thumbTemplate %>',
|
2016-03-11 00:48:53 +00:00
|
|
|
'<% }); %>',
|
|
|
|
'</div>'
|
|
|
|
].join('')),
|
|
|
|
|
|
|
|
initialize : function(options) {
|
2019-06-06 12:03:38 +00:00
|
|
|
this.styleStr = {};
|
2016-03-11 00:48:53 +00:00
|
|
|
Common.UI.MultiSlider.prototype.initialize.call(this, options);
|
|
|
|
},
|
|
|
|
|
|
|
|
render : function(parentEl) {
|
|
|
|
Common.UI.MultiSlider.prototype.render.call(this, parentEl);
|
|
|
|
|
2019-06-06 12:03:38 +00:00
|
|
|
var me = this;
|
2016-03-11 00:48:53 +00:00
|
|
|
me.trackEl = me.cmpEl.find('.track');
|
|
|
|
|
|
|
|
for (var i=0; i<me.thumbs.length; i++) {
|
|
|
|
me.thumbs[i].thumb.on('dblclick', null, function() {
|
|
|
|
me.trigger('thumbdblclick', me);
|
|
|
|
});
|
2017-04-11 14:01:34 +00:00
|
|
|
me.thumbs[i].thumbcolor = me.thumbs[i].thumb.find('> div');
|
2019-06-06 12:03:38 +00:00
|
|
|
me.setColorValue(me.options.colorValues[i], i);
|
2016-03-11 00:48:53 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 12:03:38 +00:00
|
|
|
me.changeSliderStyle();
|
|
|
|
me.changeGradientStyle();
|
2016-03-11 00:48:53 +00:00
|
|
|
me.on('change', _.bind(me.changeGradientStyle, me));
|
|
|
|
},
|
|
|
|
|
|
|
|
setColorValue: function(color, index) {
|
|
|
|
var ind = (index!==undefined) ? index : this.currentThumb;
|
2019-06-06 12:03:38 +00:00
|
|
|
this.thumbs[ind].colorValue = color;
|
2017-04-11 14:01:34 +00:00
|
|
|
this.thumbs[ind].thumbcolor.css('background-color', color);
|
2016-03-11 00:48:53 +00:00
|
|
|
this.changeGradientStyle();
|
|
|
|
},
|
|
|
|
|
|
|
|
getColorValue: function(index) {
|
|
|
|
var ind = (index!==undefined) ? index : this.currentThumb;
|
2019-06-06 12:03:38 +00:00
|
|
|
return this.thumbs[ind].colorValue;
|
2016-03-11 00:48:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setValue: function(index, value) {
|
|
|
|
Common.UI.MultiSlider.prototype.setValue.call(this, index, value);
|
|
|
|
this.changeGradientStyle();
|
|
|
|
},
|
|
|
|
|
2019-06-06 12:03:38 +00:00
|
|
|
getColorValues: function() {
|
|
|
|
var values = [];
|
|
|
|
_.each (this.thumbs, function(thumb) {
|
|
|
|
values.push(thumb.colorValue);
|
|
|
|
});
|
|
|
|
|
|
|
|
return values;
|
|
|
|
},
|
|
|
|
|
2016-03-11 00:48:53 +00:00
|
|
|
changeGradientStyle: function() {
|
|
|
|
if (!this.rendered) return;
|
|
|
|
var style;
|
2019-06-06 12:03:38 +00:00
|
|
|
if (this.styleStr.specific) {
|
|
|
|
style = Common.Utils.String.format(this.styleStr.specific, this.getColorValues().concat(this.getValues()));
|
2016-03-11 00:48:53 +00:00
|
|
|
this.trackEl.css('background', style);
|
|
|
|
}
|
|
|
|
if (Common.Utils.isIE) {
|
|
|
|
style = Common.Utils.String.format('progid:DXImageTransform.Microsoft.gradient( startColorstr={0}, endColorstr={1},GradientType=1 )',
|
2019-06-06 12:03:38 +00:00
|
|
|
this.getColorValue(0), this.getColorValue(this.thumbs.length-1));
|
2016-03-11 00:48:53 +00:00
|
|
|
this.trackEl.css('filter', style);
|
|
|
|
}
|
2019-06-06 12:03:38 +00:00
|
|
|
if (this.styleStr.common) {
|
|
|
|
style = Common.Utils.String.format(this.styleStr.common, this.getColorValues().concat(this.getValues()));
|
|
|
|
this.trackEl.css('background', style);
|
|
|
|
}
|
2017-04-12 09:57:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sortThumbs: function() {
|
2019-06-06 12:03:38 +00:00
|
|
|
var recalc_indexes = Common.UI.MultiSlider.prototype.sortThumbs.call(this);
|
|
|
|
this.trigger('sortthumbs', this, recalc_indexes);
|
2017-04-12 09:57:15 +00:00
|
|
|
return recalc_indexes;
|
2019-06-06 12:03:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
addThumb: function() {
|
|
|
|
Common.UI.MultiSlider.prototype.addThumb.call(this);
|
|
|
|
|
|
|
|
var me = this,
|
|
|
|
index = me.thumbs.length-1;
|
|
|
|
me.thumbs[index].thumb.on('dblclick', null, function() {
|
|
|
|
me.trigger('thumbdblclick', me);
|
|
|
|
});
|
|
|
|
me.thumbs[index].thumbcolor = me.thumbs[index].thumb.find('> div');
|
|
|
|
(index>0) && this.setColorValue(this.getColorValue(index-1), index);
|
|
|
|
me.changeSliderStyle();
|
|
|
|
},
|
|
|
|
|
|
|
|
removeThumb: function(index) {
|
|
|
|
if (index===undefined) index = this.thumbs.length-1;
|
|
|
|
if (index>0) {
|
|
|
|
this.thumbs[index].thumb.remove();
|
|
|
|
this.thumbs.splice(index, 1);
|
|
|
|
this.changeSliderStyle();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
changeSliderStyle: function() {
|
|
|
|
this.styleStr = {
|
|
|
|
specific: '',
|
|
|
|
common: 'linear-gradient(to right'
|
|
|
|
};
|
|
|
|
|
|
|
|
if (Common.Utils.isChrome && Common.Utils.chromeVersion<10 || Common.Utils.isSafari && Common.Utils.safariVersion<5.1)
|
|
|
|
this.styleStr.specific = '-webkit-gradient(linear, left top, right top'; /* Chrome,Safari4+ */
|
|
|
|
else if (Common.Utils.isChrome || Common.Utils.isSafari)
|
|
|
|
this.styleStr.specific = '-webkit-linear-gradient(left';
|
|
|
|
else if (Common.Utils.isGecko)
|
|
|
|
this.styleStr.specific = '-moz-linear-gradient(left';
|
|
|
|
else if (Common.Utils.isOpera && Common.Utils.operaVersion>11.0)
|
|
|
|
this.styleStr.specific = '-o-linear-gradient(left';
|
|
|
|
else if (Common.Utils.isIE)
|
|
|
|
this.styleStr.specific = '-ms-linear-gradient(left';
|
|
|
|
|
|
|
|
for (var i=0; i<this.thumbs.length; i++) {
|
|
|
|
this.styleStr.common += ', {' + i + '} {' + (this.thumbs.length + i) + '}%';
|
|
|
|
if (Common.Utils.isChrome && Common.Utils.chromeVersion<10 || Common.Utils.isSafari && Common.Utils.safariVersion<5.1)
|
|
|
|
this.styleStr.specific += ', color-stop({' + (this.thumbs.length + i) + '}%,{' + i + '})';
|
|
|
|
else
|
|
|
|
this.styleStr.specific += ', {' + i + '} {' + (this.thumbs.length + i) + '}%';
|
|
|
|
|
|
|
|
}
|
|
|
|
this.styleStr.specific += ')';
|
|
|
|
this.styleStr.common += ')';
|
2016-03-11 00:48:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|