Sha256: 0b5389ec9fdf7df654822497d73b3c76307bf9ab155625f5485aca76932571dd

Contents?: true

Size: 1.74 KB

Versions: 7

Compression:

Stored size: 1.74 KB

Contents

;jQuery(function($) {	
	$.colorpicker.parts.memory = function (inst) {
		var that		= this,
			container,
			selectNode	= function(node) {
							inst._setColor($(node).css('backgroundColor'));
							inst._change();
						},
			deleteNode	= function(node) {
							node.remove();
						},
			addNode		= function(color) {
							var $node = $('<div/>').addClass('ui-colorpicker-swatch').css('backgroundColor', color);
							$node.mousedown(function(e) {
								e.stopPropagation();
								switch (e.which) {
									case 1:	
										selectNode(this);
										break;
									case 3:
										deleteNode($node);
										setMemory();
										break;
								}
							}).bind('contextmenu', function(e) {
								e.preventDefault();								
							});

							container.append($node);
						},
			getMemory	= function() {
							return (document.cookie.match(/\bcolorpicker-memory=([^;]*)/) || [0, ''])[1].split(',');
						};
			setMemory	= function() {
							var colors = [];
							$('> *', container).each(function() {
								colors.push(escape($(this).css('backgroundColor')));
							});
							var expdate=new Date();
							expdate.setDate(expdate.getDate() + (365 * 10));
							document.cookie = 'colorpicker-memory='+colors.join()+";expires="+expdate.toUTCString();
						};

		this.init = function () {
			container	= $('<div/>')
							.addClass('ui-colorpicker-memory ui-colorpicker-border ui-colorpicker-swatches')
							.css({
								width:		84,
								height:		84,
								cursor:		'crosshair'
							})
							.appendTo($('.ui-colorpicker-memory-container', inst.dialog));

			$.each(getMemory(), function() {
				addNode(unescape(this));
			});

			container.mousedown(function(e) {
				addNode(inst.color.toCSS());
				setMemory();
			});
		};
	};
});

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
jquery-colorpicker-rails-1.0.5.0 vendor/assets/javascripts/parts/jquery.ui.colorpicker-memory.js
jquery-colorpicker-rails-1.0.4.1.2 vendor/assets/javascripts/parts/jquery.ui.colorpicker-memory.js
jquery-colorpicker-rails-1.0.4.1.1 vendor/assets/javascripts/parts/jquery.ui.colorpicker-memory.js
jquery-colorpicker-rails-1.0.4.1 vendor/assets/javascripts/parts/jquery.ui.colorpicker-memory.js
jquery-colorpicker-rails-1.0.4.0 vendor/assets/javascripts/parts/jquery.ui.colorpicker-memory.js
jquery-colorpicker-rails-1.0.3.1 vendor/assets/javascripts/parts/jquery.ui.colorpicker-memory.js
jquery-colorpicker-rails-1.0.3 vendor/assets/javascripts/parts/jquery.ui.colorpicker-memory.js