これを行うために、最終的に次の JavaScript を作成しました。基本的に、2 つの異なるセクション (クラス .oneup と .twoup) をレンダリングし、.oneup が表示される場合は「プレビュー」を追加します。
<script type="text/javascript">
var chartBar = $('#chart-bar');
function chartPreview(firstChart) {
var chartBarWidth = chartBar.width();
if (chartBarWidth > 600) {
var currentChart = $('.carousel-inner:visible .active');
// append the next widget to the current item
var chartToCheck = (firstChart) ? currentChart : currentChart.next();
if (chartToCheck.next()) {
chartToCheck.next().find('.widget').clone().appendTo(chartToCheck);
$('.carousel-inner').css({'margin-left': '10px', 'width': '98.8%'})
}
} else if (chartBarWidth > 1040) {
$('.carousel-inner').css({'margin-left': '0', 'width': '100%'})
}
}
$(document).ready(function() {
$('.widgets').sortable({
cursor: "move",
handle: ".heading"
}).disableSelection();
$('.boxes,.tasks').sortable();
var carousel = $('.carousel');
$(carousel).carousel({
interval: 0
});
if (chartBar.width() < 1040) {
chartBar.find('.oneup').show();
chartPreview(true);
carousel.bind('slide', function() {
chartPreview(false);
});
} else {
chartBar.find('.twoup').show();
}
});
oneup と twoup の両方をレンダリングする必要がなければいいのですが、AngularJS でそれを行う方法がわかりません。これが私のoneup ng-repeatです:
<div class="carousel-inner">
<div class="item chart"
ng-repeat="widget in widgets | filter: {type: 'chart'} | orderBy: 'order'"
ng-class="{active: $index == 0}">
<chart class="widget" value="{{widget}}" type="{{widget.chartType}}"></chart>
</div>
</div>
twoup ng-repeat との比較:
<div class="carousel-inner">
<div class="item chart"
ng-repeat="widget in widgets | filter: {type: 'chart'} | chunk: 2 | orderBy: 'order'"
ng-class="{active: $index == 0}">
<chart class="widget" value="{{widget[0]}}" type="{{widget[0].chartType}}"></chart>
<chart class="widget" value="{{widget[1]}}" type="{{widget[1].chartType}}"></chart>
</div>
</div>