Sha256: c3b98a729c020651c182c14086728605ae0839c652c5cb8ae41944d703c1d9ce

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

// Concrete Model Editor
//
// Copyright (c) 2010 Martin Thiede
//
// Concrete is freely distributable under the terms of an MIT-style license.

Concrete.Clipboard = Class.create({

	// if a storageElement is specified, the data is stored as textContent of this element	
	initialize: function(storageElement) {
		this.element = storageElement;
		this.kind = undefined;
	},
	
	read: function() {
		var data = this._readRaw();
		if (data && Object.isString(data) && data.isJSON()) {
			return data.evalJSON();
		}
		else {
			return data;
		}
	},
	
	write: function(data) {
		if (data instanceof Object) {
			this._writeRaw(Concrete.Helper.prettyPrintJSON(Object.toJSON(data)));
		}
		else {
			this._writeRaw(data);
		}
	},
	
	containsElement: function() {
		var data = this._readRaw();
		return data && Object.isString(data) && data.isJSON();
	},
	
	containsValue: function() {
		var data = this._readRaw();
		return data && Object.isString(data) && !data.isJSON();
	},
	
	_readRaw: function() {
		if (this.element) {
			if (this.element.tagName == "TEXTAREA") {
				return this.element.value;
			}
			else {
				return this.element.innerHTML;	
			}
		}
		else {
			return this.data;		
		}		
	},

	_writeRaw: function(data) {
		if (this.element) {
			if (this.element.tagName == "TEXTAREA") {
				this.element.value = data;
			}
			else {
				this.element.innerHTML = data;
			}
		}
		else {
			this.data = data;
		}		
	}
		
});

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
concrete-0.2.1 concrete/clipboard.js
concrete-0.2.0 concrete/clipboard.js