Your IP : 3.147.42.199


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

;(function() {
	"use strict";

	BX.namespace("BX.Landing.Block");


	/**
	 * Implements base interface for works with block node
	 * @param {nodeOptions} options
	 * @constructor
	 */
	BX.Landing.Block.Node = function(options)
	{
		this.node = options.node;
		this.manifest = typeof options.manifest === "object" ? options.manifest : {};
		this.selector = typeof options.selector === "string" ? options.selector : "";
		this.onChangeHandler = typeof options.onChange === "function" ? options.onChange : (function() {});
		this.isSavePreventedValue = false;

		// Make manifest as reed only
		Object.freeze(this.manifest);

		// Add selector attribute
		this.node.dataset.selector = this.selector;
	};


	BX.Landing.Block.Node.prototype = {
		/**
		 * Gets field for editor form
		 * @abstract
		 * @return {?BX.Landing.UI.Field.BaseField}
		 */
		getField: function() {
			throw new Error("Must be implemented by subclass");
		},


		/**
		 * Sets node value
		 * @abstract
		 * @param {*} value
		 * @param {?boolean} [preventSave = false]
		 */
		setValue: function(value, preventSave) {
			throw new Error("Must be implemented by subclass");
		},


		/**
		 * Gets value
		 * @abstract
		 * @return {string|object}
		 */
		getValue: function() {
			throw new Error("Must be implemented by subclass");
		},


		/**
		 * Handles content change event and calls external onChange handler
		 */
		onChange: function()
		{
			this.onChangeHandler.apply(null, [this]);
		},


		/**
		 * Gets node index
		 * @return {int}
		 */
		getIndex: function()
		{
			var index = parseInt(this.selector.split("@")[1]);
			index = BX.type.isNumber(index) ? index : 0;
			return index;
		},

		preventSave: function(value)
		{
			this.isSavePreventedValue = value;
		},


		isSavePrevented: function()
		{
			return this.isSavePreventedValue;
		}
	};
})();