var td = $('#timeGrid td'),
selection = {
single: function(el) {
td.not(el).removeClass(this.cl);
this.ctrl(el);
},
shift: function(el) {
if (typeof this.last !== 'number') {
return this.single(el);
}
var till = $(el).index(this.slcr),
from = this.last;
if (from > till) till = [from, from = till][0];
td.not(td.eq(this.last)).removeClass(this.cl);
td.slice(from, till).add(el).addClass(this.cl);
},
ctrl: function(el) {
$(el).addClass(this.cl);
this.last = $(el).index(this.slcr);
console.log(this.last);
},
slcr: '#timeGrid td',
cl: 'pressedTime',
last: null
};
td.on('click', function(e) {
method = !e.shiftKey && !e.ctrlKey ? 'single' : (e.shiftKey ? 'shift' : 'ctrl');
selection[method](this);
});
var table = $('#timeGrid'),
td = $('td', table),
selection = {
single: function(el) {
td.not(el).removeClass(this.cl);
this.ctrl(el);
},
shift: function(el) {
if (typeof this.last !== 'number') {
return this.single(el);
}
var till = $(el).index(this.slcr),
from = this.last;
if (from > till) till = [from, from = till][0];
td.not(td.eq(this.last)).removeClass(this.cl);
td.slice(from, till).add(el).addClass(this.cl);
},
ctrl: function(el) {
$(el).addClass(this.cl);
this.last = $(el).index(this.slcr);
},
slcr: '#timeGrid td',
cl: 'pressedTime',
last: null
};
var pressed = false;
td.on({
mousedown: function(e) {
method = !e.shiftKey && !e.ctrlKey ? 'single' : (e.shiftKey ? 'shift' : 'ctrl');
selection[method](this);
pressed = true;
},
mouseenter: function() {
if (pressed) {
selection.shift(this);
}
}
});
$(document).on('mouseup', '*', function(e) {
pressed = false;
});
[
'content' => '
<div class="checkbox">
<label>
<input type="checkbox" id="isownonly" class="" ' . ($searchModel->is_own == '1' ? 'checked' : '') . '>
Только наши
</label>
</div>
<input type="hidden" class="grid-filter" name="SetsSearch[is_own]" value="' . ($searchModel->is_own == '1' ? '1' : '0') . '">
',
],
$(document).on('change', '#isownonly', function (e) {
$('[name*=is_own]').val(
$(this).is(':checked') ? 1 : 0
).trigger('change');
});
$menu = Array( // Предполагалось, что он SQL SELECT
Array('id'=>1,'title'=>'Menu 1', 'parent_id'=>null),
Array('id'=>2,'title'=>'Sub 1.1', 'parent_id'=>1),
Array('id'=>3,'title'=>'Sub 1.2', 'parent_id'=>1),
Array('id'=>4,'title'=>'Sub 1.3', 'parent_id'=>1),
Array('id'=>5,'title'=>'Menu 2', 'parent_id'=>null),
Array('id'=>6,'title'=>'Sub 2.1', 'parent_id'=>5),
Array('id'=>7,'title'=>'Sub Sub 2.1.1', 'parent_id'=>6),
Array('id'=>8,'title'=>'Sub 2.2', 'parent_id'=>5),
Array('id'=>9,'title'=>'Menu 3', 'parent_id'=>null),
);
function has_children($rows,$id) {
foreach ($rows as $row) {
if ($row['parent_id'] == $id)
return true;
}
return false;
}
function build_menu($rows,$parent=0)
{
$result = "<ul>";
foreach ($rows as $row)
{
if ($row['parent_id'] == $parent){
$result.= "<li>{$row[title]}";
if (has_children($rows,$row['id']))
$result.= build_menu($rows,$row['id']);
$result.= "</li>";
}
}
$result.= "</ul>";
return $result;
}
echo build_menu($menu);
<ul>
<li>Menu 1<ul>
<li>Sub 1.1</li>
<li>Sub 1.2</li>
<li>Sub 1.3</li>
</ul></li>
<li>Menu 2<ul>
<li>Sub 2.1<ul>
<li>Sub Sub 2.1.1</li>
</ul></li>
<li>Sub 2.2</li>
</ul></li>
<li>Menu 3</li>
</ul>