Sha256: 0f3b9fd555fa606f967d057b1637dff790ec16e078c0c0978b0c2846396b39c4

Contents?: true

Size: 1.93 KB

Versions: 1

Compression:

Stored size: 1.93 KB

Contents

var WhowishWordElementCreator = WhowishWordCreator.extend({
  
	makeEditIcon: function(){
		
		var attrs = this.getRelevantAttributes();
		
		for (var i=0;i<attrs.length;i++) {
			
			var editIcon = document.createElement('span');
			$w(editIcon).addClass('whowishWordEditIcon');
			$w(editIcon).attr('id', this.getEditIconId(attrs[i]));
			$w(editIcon).attr('title', attrs[i]);
			
			var whowishWordIdPackage = whowishWordHelper.extractWhowishWordIdFromText($w(this.element).attr(attrs[i]));
			var idPackage = whowishWordHelper.parseWhowishWordIdPackage(whowishWordIdPackage);
			
			editIcon.whowishWord = {};
			editIcon.whowishWord.contentHandler = new WhowishWordAttributeHandler(this.element, attrs[i]);
			
			editIcon.whowishWord.id = idPackage.id;
			editIcon.whowishWord.variables = idPackage.variables;
			editIcon.whowishWord.attributeName = attrs[i];
			
			this.addEditIcon(editIcon);
		}
		
	},
  
  
	sanitize: function(){
		
		var attrs = this.getRelevantAttributes();
		
		for (var i=0;i<attrs.length;i++) {
			
			var newValue = $w(this.element).attr(attrs[i]).replace(whowishWordVariables.attributeValuePattern,"$2");
			
			try {
				this.element[attrs[i]] = newValue;
			} catch(e) {}
			
			try {
				this.element.attributes[attrs[i]].value = newValue;
			} catch (e) {}
			
			$w(this.element).attr(attrs[i], newValue);
			
		}
	
	},
	
	getEditIconId: function(attributeName) {
	
		return this.element.id + 
				whowishWordVariables.separator + 
				attributeName;
	},
	

	
	getRelevantAttributes: function() {
	
		var attrs = [];
		
		for (var i = 0; i < this.element.attributes.length; i++) {
			
			if (this.element.attributes[i].name.toLowerCase() == "id") continue;
			if (this.element.attributes[i].name.toLowerCase() == "value") continue;
			
			if (this.element.attributes[i].value.match(whowishWordVariables.attributeValuePattern) != null) {
				attrs.push(this.element.attributes[i].name);
			}
		  
		}
		
		return attrs;
		
	}


  
});

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
whowish_word-0.1.3 lib/whowish_word/rails/public/javascripts/6_whowish_word_element_creator.js