Your IP : 3.144.69.162


Current Path : /home/bitrix/ext_www/klimatlend.ua/bitrix/modules/landing/install/js/landing/ui/field/
Upload File :
Current File : /home/bitrix/ext_www/klimatlend.ua/bitrix/modules/landing/install/js/landing/ui/field/base_field.js

;(function() {
	"use strict";

	BX.namespace("BX.Landing.UI.Field");


	/**
	 * Implements base interface for works with fields
	 *
	 * @param {{selector: string, [content]: ?string, [title]: ?string, [placeholder]: string, [className]: string}} data
	 *
	 * @constructor
	 */
	BX.Landing.UI.Field.BaseField = function(data)
	{
		this.id = "id" in data ? data.id : "";
		this.selector = "selector" in data ? data.selector : "";
		this.content = ("content" in data && !!data.content ? data.content : "").trim();
		this.title = "title" in data && !!data.title ? data.title : "";
		this.placeholder = "placeholder" in data ? data.placeholder : "";
		this.className = "className" in data ? data.className : "";
		this.property = "property" in data ? data.property : "";
		this.layout = BX.Landing.UI.Field.BaseField.createLayout();
		this.header = BX.Landing.UI.Field.BaseField.createHeader();
		this.header.innerHTML = this.title;
		this.layout.appendChild(this.header);
		this.input = this.createInput();
		this.layout.appendChild(this.input);
		this.layout.dataset.selector = this.selector;
		this.input.dataset.placeholder = this.placeholder;

		if (this.className)
		{
			this.layout.classList.add(this.className);
		}

		this.init();
	};


	/**
	 * Creates field layout
	 * @return {HTMLElement}
	 */
	BX.Landing.UI.Field.BaseField.createLayout = function()
	{
		return BX.create("div", {props: {className: "landing-ui-field"}});
	};


	/**
	 * Creates field title
	 * @return {HTMLElement}
	 */
	BX.Landing.UI.Field.BaseField.createHeader = function()
	{
		return BX.create("div", {props: {className: "landing-ui-field-header"}});
	};


	/**
	 * Stores current field instance
	 * @type {?BX.Landing.UI.Field.BaseField}
	 */
	BX.Landing.UI.Field.BaseField.currentField = null;


	BX.Landing.UI.Field.BaseField.prototype = {
		init: function()
		{

		},


		/**
		 * Creates field input
		 * @return {HTMLElement}
		 */
		createInput: function()
		{
			var node = BX.create("div", {props: {className: "landing-ui-field-input"}});
			node.innerHTML = this.content;
			return node;
		},


		/**
		 * Gets field node
		 * @return {HTMLElement}
		 */
		getNode: function()
		{
			return this.layout;
		},


		/**
		 * Checks that this field is changed
		 * @return {boolean}
		 */
		isChanged: function()
		{
			return this.content !== this.getValue();
		},


		/**
		 * Gets field content
		 * @return {*}
		 */
		getValue: function()
		{
			return this.input.innerHTML.trim();
		},


		/**
		 * Sets value
		 * @param {*} value
		 */
		setValue: function(value)
		{
			this.content = value;
			this.input.innerHTML = value.toString().trim();
		}
	}
})();