"use strict"
function chartSumm(arr) {
let obj = {
'Общая экономия': 0
},
lb = {
'Эккономия на аннуляции': 'Аннуляция без штрафа',
'Экономия на цене у стойки': 'Цена у стойки'
};
let sum = function(a, b) {
return a + b
}
return arr.reduce(function(obj, el) {
let label = el.label;
if (label in lb) label = lb[label];
let total = el.data.reduce(sum, 0);
el.total = total;
obj[label] = total;
obj['Общая экономия'] += total;
return obj
}, obj)
}
let arr = [{
label: 'Эккономия на аннуляции',
backgroundColor: '#ef9d4d',
data: [1000, 400, 1500, 1500, 3000, 4000]
},
{
label: 'Экономия на цене у стойки',
backgroundColor: '#476e8f',
data: [1170, 460, 2000, 2500, 2700, 4000]
},
];
let Summ = chartSumm(arr)
console.log(Summ, arr)
function fn(e) {
for (var g = [], b = e.length, h = Math.pow(b, b - 2);; h++) {
var d = h.toString(b),
c = d.length;
if (c > b) break;
c < b && (d = 0 + d);
var f = "";
for (c = 0; c < b; c++) a = parseInt(d[c], b), f += e[a];
e.every(function(b) {
return 0 <= f.indexOf(b)
}) && g.push(f)
}
return g
};
console.log(fn(['a','b','c','d']));
jQuery(function() {
function init() {
jQuery(".slidable .tall").each(function(indx, element) {
var height = jQuery(this).data("height");
if (height) {
jQuery(this).css({"height": ""});
jQuery(this).removeData("height")
}
});
jQuery(".slidable .controller").remove();
if (jQuery(window).width() < 426) jQuery(".slidable").slidable({
minimal: 200,
speed: 800,
controls: ["<span>Читать далее</span>", "<span>Скрыть</span>"]
})
}
jQuery(window).resize(init);
init()
});
// Спойлер для списков фильтра
var maxLi = 10, text = ["Скрыть", "Показать еще"];
$("ul.checkbox").each(function() {
var li = $(this).find("li");
if (li.length > maxLi) {
li = li.slice(maxLi).hide();
var btn = $("<div>", {
text: text[1],
"class": "btn gray see-more",
click: function() {
li.stop().slideToggle(500, function() {
btn.text(text[+$(this).is(":hidden")])
})
}
}).appendTo(this)
}
});
$(function() {
function getRandomElems($el) {
$("#b").html("");
var $li = $el.siblings();
$li.length < 3 && ($li = $li.add($el));
$li = $li.get();
for (var i = 0; i < 3; i++) {
var rand = (Math.random() * $li.length) | 0;
$($li.splice(rand,1)).clone().appendTo($("#b"));
}
}
$("#a").on('click', 'li', function() {
getRandomElems($(this));
});
});
$(function() {
$("img").click(function(event) {
var nh = this.naturalHeight,
nw = this.naturalWidth,
p = nw / nh,
h = Math.min(this.scrollHeight, this.scrollWidth / p),
w = h * p,
t = (this.scrollHeight - h) / 2,
d = (this.scrollWidth - w) / 2,
x = event.offsetX,
y = event.offsetY;
if (x >= d && x <= d + w && y >= t && y <= t + h) {
x -= d;
x *= nw / w;
x = Math.round(x);
y -= t;
y *= nh / h;
y = Math.round(y);
alert([x, y])
}
})
});
function elemInViewport(elem,full) {
var box = elem.getBoundingClientRect();
var top = box.top;
var left = box.left;
var bottom = box.bottom;
var right = box.right;
var width = document.documentElement.clientWidth;
var height = document.documentElement.clientHeight;
var maxWidth = 0;
var maxHeight = 0;
if(full) { maxWidth = right - left; maxHeight = bottom - top};
return Math.min(height,bottom)- Math.max(0,top) >= maxHeight && Math.min(width,right)- Math.max(0,left)>= maxWidth
}
var div = document.createElement('div');
div.className = 'el';
div.style.transform = 'scale(.5) translate3d(100px, 100px, 0)'; // первоначальное состояние
document.body.appendChild(div);
document.body.scrollHeight; //хак
div.style.transform = 'scale(1) translate3d(0px, 0px, 0)'; // конечное
scrollToFollowBtn.addEventListener("click", function() {
scrollToElement(followBlock, 600)
}, false);
function scrollToElement(element, duration) {
var to = element.getBoundingClientRect().top;
var from = window.pageYOffset;
var start = performance.now();
requestAnimationFrame(function animate(time) {
var progress = (time - start) / duration;
1 <= progress && (progress = 1);
window.scrollTo(0, from + (to - from) * progress | 0);
1 > progress && requestAnimationFrame(animate)
})
};
<style>
.block {
margin: 50px;
height: 100px;
width: 100px;
background: #008000;
position: relative;
display: none;
}
.block::after {
content: '';
position: absolute;
left: 30px; top: -40px;
border: 20px solid transparent;
border-bottom: 20px solid green;
}
.toggle {
padding: 20px;
border: 1px solid #808080;
display: inline-block;
margin-left: 50px;
}
</style>
<div class="toggle">click me!</div>
<div class="block"></div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>
<script>$('.toggle').click(function(){
$('.block').slideToggle().css("overflow","visible");
})
</script>
function foo(d) {
var b = {};
return d.filter(function(a, c, d) {
if (b[a]) return !1;
for (b[a] = 1; ~(c = d.indexOf(a, ++c));) b[a]++;
return !0
}).sort(function(a, c) {
return b[c] - b[a]
}).map(function(a) {
return a += " - " + b[a]
})
};
var src = ["груша", "яблоко", "апельсин", "груша", "банан", "груша", "апельсин"];
alert(foo(src).join("\n"));
function onYouTubeIframeAPIReady(){
$('.player').each(function(){
var playerId = $(this).attr('id');
var videoId = $(this).data('video');
var player;
var parent = $(this).parent();
player = new YT.Player(playerId, {
height: '360',
width: '640',
videoId: videoId,
events: {
'onReady': onPlayerReady.bind(parent),
'onStateChange': onPlayerStateChange
},
playerVars: {
showinfo:0,
// iv_load_policy:3,
rel:0
// controls:0
}
});
});
}
function onPlayerReady(event){
var target = event.target;
$('.play',this).click(function(){
target.playVideo();
$('body').addClass('v-play');
})
$('.pause', this).click(function(){
target.pauseVideo();
$('.v-play').removeClass('v-play');
})
//event.target.stopVideo();
}
function onPlayerStateChange(event){
var status = event.target.getPlayerState();
if(status == 0){
$('.v-play').removeClass('v-play');
}
}
;(function($) {
$.fn.extend({
HeroSlider: function(options) {
this.defaults = {};
var settings = $.extend({}, this.defaults, options);
return this.each(function() {
var HeroParent = this;
var preview = $(".hero-preview", this);
preview.click(function(e) {
e.preventDefault();
preview.removeClass("active");
$(this).addClass("active");
var index = preview.index(this);
var round = $(".w-slider-dot", HeroParent);
round.eq(index).trigger("tap")
});
$(".hero-slider", this).on("swipe", function(e, a) {
var round = $(".w-slider-dot", HeroParent),
index = round.index($(".w-slider-dot.w-active", HeroParent));
a.direction == "right" ? index-- : index++;
index < 0 && (index = preview.length - 1);
index == preview.length && (index = 0);
preview.removeClass("active").eq(index).addClass("active")
})
})
}
})
})(jQuery);
$(function() {
$.map($("tr:first td"), function(b, a) {
return $("tr td:nth-child(" + ++a + ")")
}).forEach(function(b) {
var a;
b.each(function(b, c) {
a && a.textContent == c.textContent ? ($(c).remove(), a.rowSpan++) : a = c
})
})
});