У меня был сайт с ярлыками ("тайлами") для разных сайтов здесь .
Теперь у меня есть скрипт, который позволяет сохранять позицию для "плитки »в файл cookie, чтобы при последующем возвращении пользователя на веб-сайт их расположение плиток сохранялось.
Вот этот сценарий:
$(document).ready(function () {
//we have a hidden field which knows if the tiles are editable (1) or not (2) now just
// let's make sure it is initiated with zero value because the startup state of
// button will be "Edit"
$("#editable").val('0');
// loop through the tiles by class
$('.tile').each(function () {
// get the positions from cookies
var toppos = $.cookie('uiposy' + $(this).attr('id'));
var leftpos = $.cookie('uiposx' + $(this).attr('id'));
// apply saved positions
$(this).css('top', toppos + 'px');
$(this).css('left', leftpos + 'px');
// get the sizes from cookies
var sizew = $.cookie('uisizew' + $(this).attr('id'));
var sizeh = $.cookie('uisizeh' + $(this).attr('id'));
// apply saved sizes
$(this).css('width', sizew + 'px');
$(this).css('height', sizeh + 'px');
});
// set the tiles as draggable
$('.tile').
draggable({
containment: '#content',
scroll: false,
// watch out for drag action
stop: function (event, ui) {
// store x/y positions in a cookie when they're dragged
$.cookie('uiposx' + $(this).attr('id'), ui.position.left, {
path: '/',
expires: 7
});
$.cookie('uiposy' + $(this).attr('id'), ui.position.top, {
path: '/',
expires: 7
});
}
});
// set the tiles as resizable
$('.tile').resizable({
maxHeight: 200,
maxWidth: 200,
minHeight: 100,
minWidth: 100,
// watch out for resize action
stop: function (event, ui) {
// store width/height values in a cookie when they're resized
$.cookie('uisizew' + $(this).attr('id'), ui.size.width, {
path: '/',
expires: 7
});
$.cookie('uisizeh' + $(this).attr('id'), ui.size.height, {
path: '/',
expires: 7
});
}
});
// make resiable and draggable disabled on start
$(".tile").resizable("option", "disabled", true).removeClass('ui-state-disabled');
$(".tile").draggable("option", "disabled", true).removeClass('ui-state-disabled');
// function to run when the editButton is clicked
$('#editButton').click(function () {
// store our "state" in boolean form.
var state = ($("#editable").val() == 0) ? false : true;
// state is true, this means we will disable the tiles.
// make the button text "edit" and change the hidden #editable field value to "0"
if (state) {
$("#editable").val('0');
$(this).val('Edit');
$('.tile').css('cursor', 'pointer');
}
// state is true, this means we will enable the tiles.
// make the button text "Done" and change the hidden #editable field value to "1"
else {
$("#editable").val('1');
$(this).val('Done');
$('.tile').css('cursor', 'move');
}
// apply the state to tiles. also remove the ui-state-disabled class to make sure they're not faded.
$(".tile").resizable("option", "disabled", state).removeClass('ui-state-disabled');
$(".tile").draggable("option", "disabled", state).removeClass('ui-state-disabled');
});
});
Теперь, во-первыхзагружая веб-сайт без предварительного посещения, все плитки выровнены в сетку шириной 5 плиток и высотой 2 плитки.
При нажатии кнопки Edit
плитки становятся перетаскиваемыми и изменяющими размеры.
Итак, после нажатия новой кнопки Done
и выхода из окна браузера, а затем возврата на веб-сайт в новом окне браузера позиция сохраняется (иногда это также портится), но есть «невидимые»своего рода ссылки, оставленные в оригинальной сетке тайлов.
Почему это происходит.Например, допустим, что при исходном редактировании вы переместили верхнюю левую плитку Google из ее исходного положения и поместили ее под плитку YouTube.
Затем, когда вы вернетесь, наведите курсор мыши на позицию в окне браузера.там, где раньше была плитка Google, вы все равно можете переходить по ней, как будто она все еще там.Вы можете легко сказать это, потому что у меня установлен CSS для показа курсора pointer
при наведении курсора на ссылки, когда он не находится в режиме редактирования.
Есть ли способ, чтобы ссылки могли быть удалены с их первоначальных позиций?