PageSourceSearch

https://voenchast.ru/bitrix/js/fileman/html_editor/html-components.js

js voenchast.ru collected 2026-10-09 22:40:48 UTC 12,580 bytes, 480 lines download raw bytes

1/**
2 * Bitrix HTML Editor 3.0
3 * Date: 24.04.13
4 * Time: 4:23
5 *
6 * Components class
7 */
8(function()
9{
10	function BXEditorComponents(editor)
11	{
12		this.editor = editor;
13		this.phpParser = this.editor.phpParser;
14		this.listLoaded = false;
15		this.components = this.editor.config.components;
16		this.compNameIndex = {};
17		this.componentIncludeMethod = '$APPLICATION->IncludeComponent';
18
19		this.requestUrl = '/bitrix/admin/fileman_component_params.php';
20		this.HandleList();
21
22		this.Init();
23	}
24
25	BXEditorComponents.prototype = {
26		Init: function()
27		{
28			BX.addCustomEvent(this.editor, "OnSurrogateDblClick", BX.proxy(this.OnComponentDoubleClick, this));
29		},
30
31		GetList: function()
32		{
33			return this.components;
34		},
35
36		HandleList: function()
37		{
38			if (this.components && this.components.items)
39			{
40				for(var i = 0; i < this.components.items.length; i++)
41					this.compNameIndex[this.components.items[i].name] = i;
42			}
43		},
44
45		IsComponent: function(code)
46		{
47			code = this.phpParser.TrimPhpBrackets(code);
48			code = this.phpParser.CleanCode(code);
49
50			var oFunction = this.phpParser.ParseFunction(code);
51			if (oFunction && oFunction.name.toUpperCase() == this.componentIncludeMethod.toUpperCase())
52			{
53				var componentParams = this.phpParser.ParseParameters(oFunction.params);
54				return {
55					name: componentParams[0],
56					template: componentParams[1] || "",
57					params: componentParams[2] || {},
58					parentComponent: (componentParams[3] && componentParams[3] != '={false}') ? componentParams[3] : false,
59					exParams: componentParams[4] || false
60				};
61			}
62			return false;
63		},
64
65		IsReady: function()
66		{
67			return this.listLoaded;
68		},
69
70		GetSource: function(params, bxid)
71		{
72			if (!this.arVA)
73			{
74				this.arVA = {};
75			}
76
77			var
78				res = "<?" + this.componentIncludeMethod + "(\n" +
79					"\t\"" + params.name + "\",\n" +
80					"\t\"" + (params.template || "") + "\",\n";
81
82			if (params.params && !this.editor.util.IsEmptyObject(params.params))
83			{
84				res += "\tArray(\n";
85
86				var
87					propValues = params.params,
88					keysSorted = Object.keys(propValues).sort(),
89					i, k, arVal, arLen, j,
90					_len1 = "SEF_URL_TEMPLATES_".length,
91					_len2 = "VARIABLE_ALIASES_".length,
92					SUT, VA, lio, templ_key,
93					params_exist = false;
94
95				for (k = 0; k < keysSorted.length; k++)
96				{
97					i = keysSorted[k];
98					if (!propValues.hasOwnProperty(i))
99						continue;
100
101					//try{
102						if (!params_exist)
103							params_exist = true;
104
105						if (typeof(propValues[i]) == 'string')
106						{
107							propValues[i] = this.editor.util.stripslashes(propValues[i]);
108						}
109						else if (typeof(propValues[i]) == 'object')
110						{
111							arVal = 'array(';
112							arLen = 0;
113							for (j in propValues[i])
114							{
115								if (propValues[i].hasOwnProperty(j) && typeof(propValues[i][j]) == 'string')
116								{
117									arLen++;
118									arVal += '"' + this.editor.util.stripslashes(propValues[i][j]) + '",';
119								}
120							}
121							if (arLen > 0)
122								arVal = arVal.substr(0, arVal.length - 1) + ')';
123							else
124								arVal += ')';
125
126							propValues[i] = arVal;
127						}
128						else
129						{
130							continue;
131						}
132
133						if (propValues["SEF_MODE"] && propValues["SEF_MODE"].toUpperCase() == "Y")
134						{
135							//*** Handling SEF_URL_TEMPLATES in SEF = ON***
136							if(i.substr(0, _len1) == "SEF_URL_TEMPLATES_")
137							{
138								templ_key = i.substr(_len1);
139								this.arVA[templ_key] = this.CatchVariableAliases(propValues[i]);
140
141								if (!SUT)
142								{
143									res += "\t\t\"" + i.substr(0, _len1 - 1) + "\" => Array(\n"
144									SUT = true;
145								}
146								res += "\t\t\t\"" + i.substr(_len1) + "\" => ";
147								if (this.IsPHPBracket(propValues[i]))
148									res += this.TrimPHPBracket(propValues[i]);
149								else
150									res += "\"" + this.editor.util.addslashes(propValues[i])+"\"";
151
152								res += ",\n";
153								continue;
154							}
155							else if (SUT)
156							{
157								lio = res.lastIndexOf(",");
158								res = res.substr(0,lio)+res.substr(lio+1);
159								SUT = false;
160								res += "\t\t),\n";
161							}
162
163							//*** Handling  VARIABLE_ALIASES  in SEF = ON***
164							if(i.substr(0, _len2) == "VARIABLE_ALIASES_")
165								continue;
166						}
167						else if(propValues["SEF_MODE"] == "N")
168						{
169							//*** Handling SEF_URL_TEMPLATES in SEF = OFF ***
170							if (i.substr(0, _len1)=="SEF_URL_TEMPLATES_" || i == "SEF_FOLDER")
171								continue;
172
173							//*** Handling VARIABLE_ALIASES  in SEF = OFF ***
174							if(i.substr(0, _len2) == "VARIABLE_ALIASES_")
175							{
176								if (!VA)
177								{
178									res += "\t\t\"" + i.substr(0, _len2 - 1) + "\" => Array(\n";
179									VA = true;
180								}
181								res += "\t\t\t\"" + i.substr(_len2) + "\" => \"" + this.editor.util.addslashes(propValues[i]) + "\",\n";
182								continue;
183							}
184							else if (VA)
185							{
186								lio = res.lastIndexOf(",");
187								res = res.substr(0, lio) + res.substr(lio + 1);
188								VA = false;
189								res += "\t\t),\n";
190							}
191						}
192
193						res += "\t\t\"" + i + "\" => ";
194						if (this.IsPHPBracket(propValues[i]))
195							res += this.TrimPHPBracket(propValues[i]);
196						else if (propValues[i].substr(0, 6).toLowerCase() == 'array(')
197							res += propValues[i];
198						else
199							res += '"' + this.editor.util.addslashes(propValues[i]) + '"';
200						res += ",\n";
201
202					//}catch(e){continue;}
203				}
204
205				if (VA || SUT)
206				{
207					lio = res.lastIndexOf(",");
208					res = res.substr(0, lio) + res.substr(lio + 1);
209					res += "\t\t),\n";
210				}
211
212				if (params_exist)
213				{
214					lio = res.lastIndexOf(",");
215					res = res.substr(0, lio) + res.substr(lio + 1);
216				}
217				res += "\t)";
218			}
219			else
220			{
221				res += "Array()";
222
223				if (this.lastDroppedName == params.name && bxid)
224				{
225					var bxTag = this.editor.GetBxTag(bxid);
226					if (bxTag && bxTag.surrogateId)
227					{
228						this.ShowPropertiesDialog(bxTag.params, this.editor.GetBxTag(bxTag.surrogateId));
229					}
230				}
231			}
232
233			if (params.parentComponent !== false || params.exParams !== false)
234			{
235				var pc = params.parentComponent;
236				if (!pc || pc.toLowerCase() == '={false}')
237				{
238					res += ",\nfalse";
239				}
240				else
241				{
242					if (this.IsPHPBracket(pc))
243						res += ",\n" + this.TrimPHPBracket(pc);
244					else
245						res += ",\n'" + pc + "'";
246				}
247
248				if (params.exParams !== false && typeof params.exParams == 'object')
249				{
250					res += ",\nArray(";
251					for (i in params.exParams)
252					{
253						if (params.exParams.hasOwnProperty(i) && typeof(params.exParams[i]) == 'string')
254						{
255							res += "\n\t'" + i + "' => '" + this.editor.util.stripslashes(params.exParams[i]) + "',";
256						}
257					}
258					if (res.substr(res.length - 1) == ',')
259						res = res.substr(0, res.length - 1) + "\n";
260					res += ")";
261				}
262			}
263			res += "\n);?>";
264
265			return res;
266		},
267
268		GetOnDropHtml: function(params)
269		{
270			var _params = {
271				name: params.name
272			};
273			this.lastDroppedName = params.name;
274			return this.GetSource(_params);
275		},
276
277		CatchVariableAliases: function(str)
278		{
279			var
280				arRes = [], i, matchRes,
281				res = str.match(/(\?|&)(.+?)=#([^#]+?)#/ig);
282
283			if (!res)
284				return arRes;
285
286			for (i = 0; i < res.length; i++)
287			{
288				matchRes = res[i].match(/(\?|&)(.+?)=#([^#]+?)#/i);
289				arRes[matchRes[3]] = matchRes[2];
290			}
291			return arRes;
292		},
293
294		LoadParamsList: function(params)
295		{
296			oBXComponentParamsManager.LoadComponentParams(
297				{
298					name: params.name,
299					parent: false,
300					template: '',
301					exParams: false,
302					currentValues: {}
303				}
304			);
305		},
306
307		GetComponentData: function(name)
308		{
309			var item = this.components.items[this.compNameIndex[name]];
310			return item || {};
311		},
312
313		IsPHPBracket: function(str)
314		{
315			return str.substr(0, 2) =='={';
316		},
317
318		TrimPHPBracket: function(str)
319		{
320			return str.substr(2, str.length - 3);
321		},
322
323		OnComponentDoubleClick: function(bxTag, origTag, target, e)
324		{
325			if (origTag && origTag.tag == 'component')
326			{
327				// Show dialog
328				this.ShowPropertiesDialog(origTag.params, bxTag);
329			}
330		},
331
332		ShowPropertiesDialog: function(component, bxTag)
333		{
334			// Used to prevent influence of oBXComponentParamsManager to this array...
335			var comp = BX.clone(component, 1);
336			if (!this.oPropertiesDialog)
337			{
338				//PropertiesDialog
339				this.oPropertiesDialog = this.editor.GetDialog('componentProperties', {oBXComponentParamsManager: oBXComponentParamsManager});
340
341				BX.addCustomEvent(this.oPropertiesDialog, "OnDialogSave", BX.proxy(this.SavePropertiesDialog, this));
342				BX.addCustomEvent(this.oPropertiesDialog.oDialog, "onWindowUnRegister",BX.proxy(this.OnDialogClose, this));
343			}
344
345			this.currentViewedComponentTag = bxTag;
346			this.oPropertiesDialog.SetTitle(BX.message('ComponentPropsTitle').replace('#COMPONENT_NAME#', comp.name));
347
348			this.oPropertiesDialog.SetContent('<span class="bxcompprop-wait-notice">' + BX.message('ComponentPropsWait') + '</span>');
349			this.oPropertiesDialog.Show();
350			if (this.oPropertiesDialog.oDialog.PARTS.CONTENT_DATA)
351			{
352				BX.addClass(this.oPropertiesDialog.oDialog.PARTS.CONTENT_DATA, 'bxcompprop-outer-wrap');
353			}
354
355			var _this = this;
356			var pParamsContainer = BX.create("DIV");
357
358			BX.onCustomEvent(oBXComponentParamsManager, 'OnComponentParamsDisplay',
359			[{
360				name: comp.name,
361				parent: !!comp.parentComponent,
362				template: comp.template,
363				exParams: comp.exParams,
364				currentValues: comp.params,
365				container: pParamsContainer,
366				siteTemplate: this.editor.GetTemplateId(),
367				relPath: this.editor.config.relPath,
368				callback: function(params, container){
369					_this.PropertiesDialogCallback(params, container);
370				}
371			}]);
372		},
373
374		PropertiesDialogCallback: function(params, container)
375		{
376			if (this.oPropertiesDialog.oDialog.PARTS.CONTENT_DATA)
377				BX.addClass(this.oPropertiesDialog.oDialog.PARTS.CONTENT_DATA, 'bxcompprop-outer-wrap');
378			this.oPropertiesDialog.SetContent(container);
379
380			var size = this.oPropertiesDialog.GetContentSize();
381			BX.onCustomEvent(oBXComponentParamsManager, 'OnComponentParamsResize', [
382				size.width,
383				size.height
384			]);
385		},
386
387		SavePropertiesDialog: function()
388		{
389			var
390				ddBxTag = this.currentViewedComponentTag,
391				compBxTag = this.editor.GetBxTag(ddBxTag.params.origId),
392				currentValues = oBXComponentParamsManager.GetParamsValues(),
393				template = oBXComponentParamsManager.GetTemplateValue();
394
395			ddBxTag.params.origParams.params = compBxTag.params.params = currentValues;
396			ddBxTag.params.origParams.template = compBxTag.params.template = template;
397
398			this.editor.synchro.FullSyncFromIframe();
399			this.lastDroppedName = '';
400		},
401
402		OnDialogClose: function()
403		{
404			if (this.editor.util.IsEmptyObject(this.currentViewedComponentTag.params.origParams.params) && this.lastDroppedName)
405			{
406				this.SavePropertiesDialog();
407			}
408		},
409
410		ReloadList: function()
411		{
412			var _this = this;
413			this.editor.Request({
414				getData: this.editor.GetReqData('load_components_list',
415					{
416						site_template: this.editor.GetTemplateId(),
417						componentFilter: this.editor.GetComponentFilter(),
418						site: this.editor.GetSiteId()
419					}
420				),
421				handler: function(res)
422				{
423					_this.components = _this.editor.config.components = res;
424					_this.HandleList();
425					_this.editor.componentsTaskbar.BuildTree(_this.components.groups, _this.components.items);
426				}
427			});
428		},
429
430		SetComponentIcludeMethod: function(method)
431		{
432			this.componentIncludeMethod = method;
433		}
434	};
435
436	function __runcomp()
437	{
438		window.BXHtmlEditor.BXEditorComponents = BXEditorComponents;
439
440		function PropertiesDialog(editor, params)
441		{
442			params = params || {};
443			params.id = 'bx_component_properties';
444			params.height = 600;
445			params.width =  800;
446			params.resizable = true;
447			this.oBXComponentParamsManager = params.oBXComponentParamsManager;
448
449			this.id = 'components_properties';
450
451			// Call parrent constructor
452			PropertiesDialog.superclass.constructor.apply(this, [editor, params]);
453
454			BX.addClass(this.oDialog.DIV, "bxcompprop-dialog");
455			BX.addCustomEvent(this, "OnDialogSave", BX.proxy(this.Save, this));
456		}
457		BX.extend(PropertiesDialog, window.BXHtmlEditor.Dialog);
458
459		PropertiesDialog.prototype.OnResize = function()
460		{
461			var
462				w = this.oDialog.PARTS.CONTENT_DATA.offsetWidth,
463				h = this.oDialog.PARTS.CONTENT_DATA.offsetHeight;
464
465			BX.onCustomEvent(this.oBXComponentParamsManager, 'OnComponentParamsResize', [w, h]);
466		};
467
468		PropertiesDialog.prototype.OnResizeFinished = function()
469		{
470		};
471
472		window.BXHtmlEditor.dialogs.componentProperties = PropertiesDialog;
473	}
474
475	if (window.BXHtmlEditor && window.BXHtmlEditor.dialogs)
476		__runcomp();
477	else
478		BX.addCustomEvent(window, "OnEditorBaseControlsDefined", __runcomp);
479
480})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.