私はここに別のウェブサイトへのショートカット(「タイル」)があるサイトを持っていました。
これで、「タイル」の位置をCookieに保存できるようにするスクリプトができました。これにより、ユーザーが後日Webサイトに戻ったときに、タイルの配置が保存されます。
そのスクリプトは次のとおりです。
$(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');
});
});
これで、以前にアクセスせずに最初にWebサイトをロードすると、タイルはすべて、幅5タイル、高さ2タイルのグリッドに配置されます。
ボタンをクリックするEdit
と、タイルはドラッグ可能でサイズ変更可能になります。
したがって、新しいDone
ボタンをクリックしてブラウザウィンドウを終了し、新しいブラウザウィンドウでWebサイトに戻ると、位置は保存されますが(これも混乱することがあります)、ある種の「非表示」リンクがあります。残ったタイルの元のグリッドを形成します。
なぜこうなった。たとえば、元の編集で、左上のGoogleタイルを元の位置から移動し、YouTubeタイルの下に配置したとします。
次に、戻ってきて、Googleタイルがあったブラウザウィンドウ上の位置にマウスを合わせると、まだそこにあるかのようにクリックできます。pointer
編集モードでないときにリンクにカーソルを合わせるとカーソルが表示されるようにCSSを設定しているので、これは簡単にわかります。
リンクを元の位置から削除する方法はありますか?