2
2
* @fileOverview Contains the IconPicker class definition.
3
* @author <a href="mailto:vincent.k.hughitt@nasa.gov">Keith Hughitt</a>
3
* Syntax: Prototype, jQuery
4
* @author <a href="mailto:keith.hughitt@gmail.com">Keith Hughitt</a>
5
/*jslint browser: true, white: true, onevar: true, undef: true, nomen: false, eqeqeq: true, plusplus: true,
6
bitwise: true, regexp: true, strict: true, newcap: true, immed: true, maxlen: 120, sub: true */
9
var IconPicker = Class.extend(
10
/** @lends IconPicker.prototype */
14
* @description Creates a new IconPicker
15
* @param {String} id The identifier to use for the icon-picker dom-node
20
// Available Icon options
21
this.AVAILABLE_ICON_SHAPES = ["circle", "square", "diamond"];
22
this.AVAILABLE_ICON_COLORS = ["red", "orange", "green", "yellow", "blue", "lightblue"];
24
// Keep track of which event-layer is being targeted.
27
// Don't build until requested
33
* @description Sets up the list of available icons to chose from
35
_buildIconList: function () {
36
var i, closeBtn, menu, self = this;
37
menu = $("<div id='" + this.id + "' class='ui-widget ui-widget-content" +
38
"ui-corner-all' style='display: none;'></div>");
39
menu.append('<div id=event-icon-menu-title><span style="vertical-align: middle">Chose an icon:</span>' +
40
'</div><div id="event-icon-menu-body">');
6
/*global IconPicker, Class, $, $A, jQuery*/
7
var IconPicker = Class.create(
8
/** @lends IconPicker.prototype */
12
* @description Creates a new IconPicker
13
* @param {String} id The identifier to use for the icon-picker dom-node
15
initialize: function (id) {
18
// Available Icon options
19
this.AVAILABLE_ICON_SHAPES = $A(["circle", "square", "diamond"]);
20
this.AVAILABLE_ICON_COLORS = $A(["red", "orange", "green", "yellow", "blue", "lightblue"]);
22
// Keep track of which event-layer is being targeted.
26
this._buildIconList();
31
* @description Sets up the list of available icons to chose from
33
_buildIconList: function () {
34
var i, closeBtn, menu, self = this;
35
menu = jQuery("<div id='" + this.id + "' style='display: none;'></div>");
36
menu.append(jQuery('<div id=event-icon-menu-title><span style="vertical-align: middle">Chose an icon:</span></div><div id="event-icon-menu-body">'));
43
$.each(this.AVAILABLE_ICON_COLORS, function () {
45
$.each(self.AVAILABLE_ICON_SHAPES, function () {
46
var icon, shape = this;
48
icon = $('<img class="event-icon-menu-icon" src="images/events/small-' + color + "-" + shape +
49
'.png" alt="' + color + '-' + shape + '">');
50
icon.click(function () {
51
self.focus.updateIcon(this.alt);
52
$('#event-icon-menu').fadeOut();
62
closeBtn = $('<br><div style="text-align: right">' +
63
'<a class="light" href="#" style="margin-right: 2px;">[Close]</a></div>').click(function () {
64
$('#event-icon-menu').fadeOut();
66
menu.append(closeBtn);
67
menu.append("</div>");
69
$('body').append(menu);
73
* @description Toggle IconPicker visibility
74
* @param {Object} layer The EventLayer icon picker is associated with.
75
* @param {Object} pos The mouse-click position
77
toggle: function (layer, pos) {
79
this._buildIconList();
83
$('#' + this.id).css({'left': pos.left + 16, 'top': pos.top + 16}).slideToggle();
39
this.AVAILABLE_ICON_COLORS.each(function (color) {
40
self.AVAILABLE_ICON_SHAPES.each(function (shape) {
41
var icon = jQuery('<img class="event-icon-menu-icon" src="images/events/small-' + color + "-" + shape + '.png" alt="' + color + '-' + shape + '">');
42
icon.click(function () {
43
self.focus.updateIcon(this.alt);
44
jQuery('#event-icon-menu').fadeOut();
48
menu.append(jQuery("<br>"));
54
closeBtn = jQuery('<br><div style="text-align: right"><a class="event-url" href="#" style="margin-right: 2px;">[Close]</a></div>').click(function () {
55
jQuery('#event-icon-menu').fadeOut();
57
menu.append(closeBtn);
58
menu.append("</div>");
60
jQuery('body').append(menu);
64
* @description Toggle IconPicker visibility
65
* @param {Object} layer The EventLayer icon picker is associated with.
66
* @param {Object} pos The mouse-click position
68
toggle: function (layer, pos) {
70
jQuery('#' + this.id).css({'left': pos.left + 16, 'top': pos.top + 16}).slideToggle();