[uniques] show visited/capture state in portals-list
This commit is contained in:
parent
4644e6ee83
commit
7dc2dfacad
@ -11,3 +11,9 @@
|
|||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.portal-list-uniques input[type='checkbox'] {
|
||||||
|
padding: 0;
|
||||||
|
height: auto;
|
||||||
|
margin-top: -5px;
|
||||||
|
margin-bottom: -5px;
|
||||||
|
}
|
||||||
|
@ -159,6 +159,8 @@ window.plugin.uniques.onPublicChatDataAvailable = function(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.plugin.uniques.updateCheckedAndHighlight = function(guid) {
|
window.plugin.uniques.updateCheckedAndHighlight = function(guid) {
|
||||||
|
runHooks('pluginUniquesUpdateUniques', { guid: guid });
|
||||||
|
|
||||||
if (guid == window.selectedPortal) {
|
if (guid == window.selectedPortal) {
|
||||||
|
|
||||||
var uniqueInfo = plugin.uniques.uniques[guid];
|
var uniqueInfo = plugin.uniques.uniques[guid];
|
||||||
@ -207,8 +209,9 @@ window.plugin.uniques.setPortalCaptured = function(guid) {
|
|||||||
plugin.uniques.sync(guid);
|
plugin.uniques.sync(guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.plugin.uniques.updateVisited = function(visited) {
|
window.plugin.uniques.updateVisited = function(visited, guid) {
|
||||||
var guid = window.selectedPortal;
|
if(guid == undefined) guid = window.selectedPortal;
|
||||||
|
|
||||||
var uniqueInfo = plugin.uniques.uniques[guid];
|
var uniqueInfo = plugin.uniques.uniques[guid];
|
||||||
if (!uniqueInfo) {
|
if (!uniqueInfo) {
|
||||||
plugin.uniques.uniques[guid] = uniqueInfo = {
|
plugin.uniques.uniques[guid] = uniqueInfo = {
|
||||||
@ -228,8 +231,9 @@ window.plugin.uniques.updateVisited = function(visited) {
|
|||||||
plugin.uniques.sync(guid);
|
plugin.uniques.sync(guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.plugin.uniques.updateCaptured = function(captured) {
|
window.plugin.uniques.updateCaptured = function(captured, guid) {
|
||||||
var guid = window.selectedPortal;
|
if(guid == undefined) guid = window.selectedPortal;
|
||||||
|
|
||||||
var uniqueInfo = plugin.uniques.uniques[guid];
|
var uniqueInfo = plugin.uniques.uniques[guid];
|
||||||
if (!uniqueInfo) {
|
if (!uniqueInfo) {
|
||||||
plugin.uniques.uniques[guid] = uniqueInfo = {
|
plugin.uniques.uniques[guid] = uniqueInfo = {
|
||||||
@ -401,6 +405,83 @@ window.plugin.uniques.setupContent = function() {
|
|||||||
plugin.uniques.disabledMessage = '<div id="uniques-container" class="help" title="Your browser does not support localStorage">Plugin Uniques disabled</div>';
|
plugin.uniques.disabledMessage = '<div id="uniques-container" class="help" title="Your browser does not support localStorage">Plugin Uniques disabled</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.plugin.uniques.setupPortalsList = function() {
|
||||||
|
if(!window.plugin.portalslist) return;
|
||||||
|
|
||||||
|
window.addHook('pluginUniquesUpdateUniques', function(data) {
|
||||||
|
var info = plugin.uniques.uniques[data.guid];
|
||||||
|
if(!info) info = { visited: false, captured: false };
|
||||||
|
|
||||||
|
$('[data-list-uniques="'+data.guid+'"].visited').prop('checked', !!info.visited);
|
||||||
|
$('[data-list-uniques="'+data.guid+'"].captured').prop('checked', !!info.captured);
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addHook('pluginUniquesRefreshAll', function() {
|
||||||
|
$('[data-list-uniques]').each(function(i, element) {
|
||||||
|
var guid = element.getAttribute("data-list-uniques");
|
||||||
|
|
||||||
|
var info = plugin.uniques.uniques[guid];
|
||||||
|
if(!info) info = { visited: false, captured: false };
|
||||||
|
|
||||||
|
var e = $(element);
|
||||||
|
if(e.hasClass('visited')) e.prop('checked', !!info.visited);
|
||||||
|
if(e.hasClass('captured')) e.prop('checked', !!info.captured);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function uniqueValue(guid) {
|
||||||
|
var info = plugin.uniques.uniques[guid];
|
||||||
|
if(!info) return 0;
|
||||||
|
|
||||||
|
if(info.visited && info.captured) return 2;
|
||||||
|
if(info.visited) return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.plugin.portalslist.fields.push({
|
||||||
|
title: "Visit",
|
||||||
|
value: function(portal) { return portal.options.guid; }, // we store the guid, but implement a custom comparator so the list does sort properly without closing and reopening the dialog
|
||||||
|
sort: function(guidA, guidB) {
|
||||||
|
return uniqueValue(guidA) - uniqueValue(guidB);
|
||||||
|
},
|
||||||
|
format: function(cell, portal, guid) {
|
||||||
|
var info = plugin.uniques.uniques[guid];
|
||||||
|
if(!info) info = { visited: false, captured: false };
|
||||||
|
|
||||||
|
$(cell).addClass("portal-list-uniques");
|
||||||
|
|
||||||
|
// for some reason, jQuery removes event listeners when the list is sorted. Therefore we use DOM's addEventListener
|
||||||
|
$('<input>')
|
||||||
|
.prop({
|
||||||
|
type: "checkbox",
|
||||||
|
className: "visited",
|
||||||
|
title: "Portal visited?",
|
||||||
|
checked: !!info.visited,
|
||||||
|
})
|
||||||
|
.attr("data-list-uniques", guid)
|
||||||
|
.appendTo(cell)
|
||||||
|
[0].addEventListener("change", function(ev) {
|
||||||
|
window.plugin.uniques.updateVisited(this.checked, guid);
|
||||||
|
ev.preventDefault();
|
||||||
|
return false;
|
||||||
|
}, false);
|
||||||
|
$('<input>')
|
||||||
|
.prop({
|
||||||
|
type: "checkbox",
|
||||||
|
className: "captured",
|
||||||
|
title: "Portal captured?",
|
||||||
|
checked: !!info.captured,
|
||||||
|
})
|
||||||
|
.attr("data-list-uniques", guid)
|
||||||
|
.appendTo(cell)
|
||||||
|
[0].addEventListener("change", function(ev) {
|
||||||
|
window.plugin.uniques.updateCaptured(this.checked, guid);
|
||||||
|
ev.preventDefault();
|
||||||
|
return false;
|
||||||
|
}, false);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var setup = function() {
|
var setup = function() {
|
||||||
if($.inArray('pluginUniquesUpdateUniques', window.VALID_HOOKS) < 0)
|
if($.inArray('pluginUniquesUpdateUniques', window.VALID_HOOKS) < 0)
|
||||||
window.VALID_HOOKS.push('pluginUniquesUpdateUniques');
|
window.VALID_HOOKS.push('pluginUniquesUpdateUniques');
|
||||||
@ -413,6 +494,15 @@ var setup = function() {
|
|||||||
window.addHook('publicChatDataAvailable', window.plugin.uniques.onPublicChatDataAvailable);
|
window.addHook('publicChatDataAvailable', window.plugin.uniques.onPublicChatDataAvailable);
|
||||||
window.addHook('iitcLoaded', window.plugin.uniques.registerFieldForSyncing);
|
window.addHook('iitcLoaded', window.plugin.uniques.registerFieldForSyncing);
|
||||||
window.addPortalHighlighter('Uniques', window.plugin.uniques.highlighter);
|
window.addPortalHighlighter('Uniques', window.plugin.uniques.highlighter);
|
||||||
|
|
||||||
|
if(window.plugin.portalslist) {
|
||||||
|
window.plugin.uniques.setupPortalsList();
|
||||||
|
} else {
|
||||||
|
setTimeout(function() {
|
||||||
|
if(window.plugin.portalslist)
|
||||||
|
window.plugin.uniques.setupPortalsList();
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//PLUGIN END //////////////////////////////////////////////////////////
|
//PLUGIN END //////////////////////////////////////////////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user