Versões comparadas

Chave

  • Esta linha foi adicionada.
  • Esta linha foi removida.
  • A formatação mudou.

...

HTML
<div id="keyWordContainerDiv"></div>


<style>
	.Keyword-Container-Wrapper{
		width: 100%;
		height: auto;
		min-height: 30px;
	}


	.Keyword-Container-Wrapper-Span{
		padding: 5px;
		background-color: #3572b0;
		color: #fff;
	}
</style>


<script>


TOTVS_Keywords = {
	Id: 'KeyWord1',
	Container: null,
	Tags: [],
	Init: function(id, nameOfContainer, tags){
		this.Id = id;
		this.Container = (typeof nameOfContainer === "string") ? document.getElementById(nameOfContainer) : nameOfContainer; 
		this.Tags = tags;{
	},
	Build			Length: function(id, nameOfContainer, tags){tags) ? tags.length: 0,
			this.Init(id, nameOfContainer, tags);
			this.Container = (typeof this.Container === "string") ? document.getElementById(this.Container) : this.Container; 	Items: [],
				Add: function(item){
					if(!this.Exists(item)){
						this.Tags.Items[this.Tags.Length]['Value'] = item;
						this.Tags.Items[this.Tags.Length]['Index'] = this.Tags.Length;
						this.Tags.Items[item]['Value'] = item;
						this.Tags.Items[item]['Index'] = this.Tags.Length;
						this.Tags.Length += 1;
					}
				},
				AddRange: function(rangeOfItems){
					for(var i = 0; i < rangeOfItems.length; i++){
						if(!this.Exists(rangeOfItems[i])){
							this.Tags.Items[this.Tags.Length]['Value'] = rangeOfItems[i];
							this.Tags.Items[this.Tags.Length]['Index'] = this.Tags.Length;
							this.Tags.Items[rangeOfItems[i]]['Value'] = rangeOfItems[i];
							this.Tags.Items[rangeOfItems[i]]['Index'] = this.Tags.Length;
							this.Tags.Length += 1;
						}
					}
				},
				Exists: function(item){
					for(var att in this.Tags.Items){
						if(att == item)
							return true;
					}
					return false;
				},
				Find: function(item){
					for(var att in this.Tags.Items){
						if(att == item)
							return this.Tags.Items[item];
					}
					return null;
				},
				IndexOf: function(item){
					var _item = this.Find(item);
					
					if(_item != null)
						return _item.Index;
					return null;
				}
		}


		this.Tags.Add(tags);
	},
	Build: function(id, nameOfContainer, tags){
			this.Init(id, nameOfContainer, tags);
			var _keyWordContainerWrapper = document.createElement('div');		
			_keyWordContainerWrapper.id = this.Id + "_ContainerWrapper";
			_keyWordContainerWrapper.className = "Keyword-Container-Wrapper";


			var _keyWordContainerWrapperkeyWordContainerWrapperInput = document.createElement('divinput');		
			_keyWordContainerWrapperkeyWordContainerWrapperInput.id = this_keyWordContainerWrapper.Idid + "_Input"_ContainerWrapper;
			_keyWordContainerWrapperInput.name = _keyWordContainerWrapperInput.id;
			_keyWordContainerWrapperInput.type = "text";
			_keyWordContainerWrapper.className = "Keyword-Container-Wrapper";


keyWordContainerWrapperInput.className = 'Keyword-Container-Wrapper-Input';
			_keyWordContainerWrapperInput.onkeypress = function(e){
				var _keyWordContainerWrapperInputevt = document.createElement('input');		
			_keyWordContainerWrapperInput.id = _keyWordContainerWrapper.id + "_Input";
			_keyWordContainerWrapperInput.name = _keyWordContainerWrapperInput.id;
			_keyWordContainerWrapperInput.type = "text";
			_keyWordContainerWrapperInput.onkeypress = function(e){
				var _evt = e || window.event;
				if (event.which == 13 || event.keyCode == 13) {
        			TOTVS_Keywords.Tags.push(this.value);
					
					var _span = document.createElement('span')e || window.event;
				if (event.which == 13 || event.keyCode == 13) {
        			TOTVS_Keywords.Tags.Add(this.value);
					
					var _index = TOTVS_Keywords.Tags.IndexOf(this.Value);


					var _span = document.createElement('span');
					_span.id = this.id + "_" + (_index != null) ? _index : this.value;
					_span.name = _span.id;
					_span.className = 'Keyword-Container-Wrapper-Span';
					_span.innerHTML = this.value;
					
					this.parentNode.insertBefore(_span, this);
        			return false;
    			}
			}


			_keyWordContainerWrapper.appendChild(_keyWordContainerWrapperInput);

			this.Container.appendChild(_keyWordContainerWrapper);
	}
}


TOTVS_Keywords.Build('TOTVS_KeyWord', 'keyWordContainerDiv', [])


</script>