| Current Path : /var/www/element/data/www/greenpr.ru/bitrix3/js/fileman/light_editor/ |
| Current File : /var/www/element/data/www/greenpr.ru/bitrix3/js/fileman/light_editor/le_toolbarbuttons.js |
if (!window.LHEButtons)
LHEButtons = {};
LHEButtons['Source'] = {
id : 'Source',
codeEditorMode : true,
name : LHE_MESS.Source,
handler : function(pBut)
{
var bHtml = pBut.pLEditor.sEditorMode == 'html';
pBut.pLEditor.SetView(bHtml ? 'code' : 'html');
pBut.Check(bHtml);
}
};
// BASE
LHEButtons['Anchor'] = {
id : 'Anchor',
name: LHE_MESS.Anchor,
bBBHide: true,
handler: function(pBut)
{
var p = pBut.pLEditor.GetSelectionObject();
if(!p || !p.getAttribute || p.getAttribute("__bxtagname") != "anchor")
p = false;
pBut.pLEditor.OpenDialog({id : 'Anchor', obj: p});
}
};
LHEButtons['CreateLink'] = {
id : 'CreateLink',
name : LHE_MESS.CreateLink,
name_edit : LHE_MESS.EditLink,
handler : function (pBut)
{
var p = (pBut.arSelectedElement && pBut.arSelectedElement['A']) ? pBut.arSelectedElement['IMG'] : pBut.pLEditor.GetSelectionObject();
if (!p || p.tagName != 'A')
p = false;
pBut.pLEditor.OpenDialog({id : 'Link', obj: p});
}
};
LHEButtons['DeleteLink'] = {
id : 'DeleteLink',
name : LHE_MESS.DeleteLink,
cmd : 'Unlink',
handler : function(pBut)
{
var p = (pBut.arSelectedElement && pBut.arSelectedElement['A']) ? pBut.arSelectedElement['IMG'] : pBut.pLEditor.GetSelectionObject();
if(!p) return;
if (p.tagName != 'A')
p = jsUtils.FindParentObject(pBut.pLEditor.GetSelectionObject(), 'A');
if(!p) return;
if (!jsUtils.bIsIE)
pBut.pLEditor.SelectElement(p);
pBut.pLEditor.executeCommand('Unlink');
}
};
LHEButtons['Image'] = {
id : 'Image',
name : LHE_MESS.Image,
name_edit : LHE_MESS.EditImage,
handler : function (pBut)
{
var p = (pBut.arSelectedElement && pBut.arSelectedElement['IMG']) ? pBut.arSelectedElement['IMG'] : pBut.pLEditor.GetSelectionObject();
if (!p || p.tagName != 'IMG')
p = false;
pBut.pLEditor.OpenDialog({id : 'Image', obj: p});
}
};
//LHEButtons['SpecialChar'] = {
// id : 'SpecialChar',
// name : LHE_MESS.SpecialChar,
// handler : function (pBut) {pBut.pLEditor.OpenDialog({id : 'SpecialChar'});}
//};
LHEButtons['Bold'] = {id : 'Bold', name : LHE_MESS.Bold, cmd : 'Bold'};
LHEButtons['Italic'] = {id : 'Italic', name : LHE_MESS.Italic, cmd : 'Italic'};
LHEButtons['Underline'] = {id : 'Underline', name : LHE_MESS.Underline, cmd : 'Underline'};
LHEButtons['RemoveFormat'] = {id : 'RemoveFormat', name : LHE_MESS.RemoveFormat, cmd : 'RemoveFormat'};
LHEButtons['JustifyLeft'] = {id : 'JustifyLeft', name : LHE_MESS.JustifyLeft, cmd : 'JustifyLeft'};
LHEButtons['JustifyCenter'] = {id : 'JustifyCenter', name : LHE_MESS.JustifyCenter, cmd : 'JustifyCenter'};
LHEButtons['JustifyRight'] = {id : 'JustifyRight', name : LHE_MESS.JustifyRight, cmd : 'JustifyRight'};
LHEButtons['JustifyFull'] = {id : 'JustifyFull', name : LHE_MESS.JustifyFull, cmd : 'JustifyFull'};
LHEButtons['InsertOrderedList'] = {id : 'InsertOrderedList', name : LHE_MESS.OrderedList, cmd : 'InsertOrderedList', bBBHide: true};
LHEButtons['InsertUnorderedList'] = {id : 'InsertUnorderedList', name : LHE_MESS.UnorderedList, cmd : 'InsertUnorderedList'};
LHEButtons['Outdent'] = {id : 'Outdent', name : LHE_MESS.Outdent, cmd : 'Outdent', bBBHide: true};
LHEButtons['Indent'] = {id : 'Indent', name : LHE_MESS.Indent, cmd : 'Indent', bBBHide: true};
LHEButtons['Video'] = {
id : 'Video',
name : LHE_MESS.InsertVideo,
name_edit : LHE_MESS.EditVideo,
handler : function (pBut)
{
var p = pBut.pLEditor.GetSelectionObject();
if(!p || !p.getAttribute || p.getAttribute("__bxtagname") != "video")
p = false;
pBut.pLEditor.OpenDialog({id : 'Video', obj: p});
}
};
LHEButtons['SmileList'] = {
id : 'SmileList',
name : LHE_MESS.SmileList,
bBBShow: true,
type: 'List',
handler: function() {},
OnCreate: function(pList)
{
var
arSmiles = pList.pLEditor.arConfig.arSmiles,
pImg, pSmile, i, oSmile, k;
pList.pValuesCont.style.width = '100px';
pList.oSmiles = {};
for (i in arSmiles)
{
oSmile = arSmiles[i];
if (typeof oSmile != 'object' || !oSmile.path || !oSmile.code)
continue;
k = 'smile_' + Math.random().toString().substring(4) + '_' + pList.pLEditor.id;
pSmile = jsUtils.CreateElement("DIV", {className: 'lhe-smile-cont', title: oSmile.name, id: k});
pImg = pSmile.appendChild(jsUtils.CreateElement("IMG", {src: oSmile.path, className: 'lhe-smile'}));
pImg.onerror = function(){var d = this.parentNode; d.parentNode.removeChild(d);};
pList.oSmiles[k] = oSmile;
pSmile.onclick = function(){pList.oBut.SetSmile(this.id, pList);};
pSmile.onmouseover = function(){this.className = 'lhe-smile-cont lhe-smile-cont-over';};
pSmile.onmouseout = function(){this.className = 'lhe-smile-cont';};
pList.pValuesCont.appendChild(pSmile);
}
},
SetSmile: function(k, pList)
{
pList.pLEditor.SelectRange(pList.pLEditor.oPrevRange);
var oSmile = pList.oSmiles[k];
pList.pLEditor.InsertHTML('<img __bxtagname="smile" id="' + k + '" src="' + oSmile.path + '" title="' + oSmile.name + '"/>');
pList.Close();
}
};
LHEButtons['HeaderList'] = {
id : 'HeaderList',
name : LHE_MESS.HeaderList,
bBBHide: true,
type: 'List',
handler: function() {},
OnCreate: function(pList)
{
var
pIt, pItem, i, oItem;
pList.arItems = [
{value: 'p', name: LHE_MESS.Normal},
{value: 'h1', name: LHE_MESS.Heading + ' 1'},
{value: 'h2', name: LHE_MESS.Heading + ' 2'},
{value: 'h3', name: LHE_MESS.Heading + ' 3'},
{value: 'h4', name: LHE_MESS.Heading + ' 4'},
{value: 'h5', name: LHE_MESS.Heading + ' 5'},
{value: 'h6', name: LHE_MESS.Heading + ' 6'},
{value: 'pre', name: LHE_MESS.Preformatted}
];
var innerCont = jsUtils.CreateElement("DIV", {className: 'lhe-header-innercont'});
for (i = 0; i < pList.arItems.length; i++)
{
oItem = pList.arItems[i];
if (typeof oItem != 'object' || !oItem.name)
continue;
pItem = jsUtils.CreateElement("DIV", {className: 'lhe-header-cont', title: oItem.name, id: 'lhe_header__' + i});
pIt = pItem.appendChild(jsUtils.CreateElement(oItem.value.toUpperCase()));
pIt.innerHTML = oItem.name;
oItem.pWnd = pItem;
pItem.onclick = function(){pList.oBut.Select(pList.arItems[this.id.substring('lhe_header__'.length)], pList);};
pItem.onmouseover = function(){this.className = 'lhe-header-cont lhe-header-cont-over';};
pItem.onmouseout = function(){this.className = 'lhe-header-cont';};
innerCont.appendChild(pItem);
}
pList.pValuesCont.appendChild(innerCont);
},
OnOpen: function(pList)
{
var
frm = pList.pLEditor.queryCommand('FormatBlock'),
i, v;
if (pList.pSelectedItemId >= 0)
pList.SelectItem(false);
if (!frm)
frm = 'p';
for (i = 0; i < pList.arItems.length; i++)
{
v = pList.arItems[i];
if (v.value == frm)
{
pList.pSelectedItemId = i;
pList.SelectItem(true);
}
}
},
Select: function(oItem, pList)
{
pList.pLEditor.SelectRange(pList.pLEditor.oPrevRange);
pList.pLEditor.executeCommand('FormatBlock', '<' + oItem.value + '>');
pList.Close();
}
};
LHEButtons['FontList'] = {
id : 'FontList',
name : LHE_MESS.FontList,
//bBBHide: true,
type: 'List',
handler: function() {},
OnCreate: function(pList)
{
var
pIt, pItem, i, oItem, font;
pList.arItems = [];
for (i in pList.pLEditor.arConfig.arFonts)
{
font = pList.pLEditor.arConfig.arFonts[i];
if (typeof font == 'string')
pList.arItems.push({value: font, name: font});
}
for (i = 0; i < pList.arItems.length; i++)
{
oItem = pList.arItems[i];
if (typeof oItem != 'object' || !oItem.name)
continue;
pItem = jsUtils.CreateElement("DIV", {className: 'lhe-list-item-cont', title: oItem.name, id: 'lhe_font__' + i});
pIt = pItem.appendChild(jsUtils.CreateElement('SPAN', {className: 'lhe-list-font-span'}, {fontFamily: oItem.value}));
pIt.innerHTML = oItem.name;
oItem.pWnd = pItem;
pItem.onclick = function(){pList.oBut.Select(pList.arItems[this.id.substring('lhe_font__'.length)], pList);};
pItem.onmouseover = function(){this.className = 'lhe-list-item-cont lhe-list-item-cont-over';};
pItem.onmouseout = function(){this.className = 'lhe-list-item-cont';};
pList.pValuesCont.appendChild(pItem);
}
},
OnOpen: function(pList)
{
var
frm = pList.pLEditor.queryCommand('FontName'),
i, v;
if (pList.pSelectedItemId >= 0)
pList.SelectItem(false);
if (!frm)
frm = 'p';
for (i = 0; i < pList.arItems.length; i++)
{
v = pList.arItems[i];
if (v.value.toLowerCase() == frm.toLowerCase())
{
pList.pSelectedItemId = i;
pList.SelectItem(true);
}
}
},
Select: function(oItem, pList)
{
pList.pLEditor.SelectRange(pList.pLEditor.oPrevRange);
pList.pLEditor.executeCommand('FontName', oItem.value);
pList.Close();
}
};
LHEButtons['FontSizeList'] = {
id : 'FontSizeList',
name : LHE_MESS.FontSizeList,
type: 'List',
handler: function() {},
OnCreate: function(pList)
{
var
pIt, pItem, i, oItem, fontSize;
pList.arItems = [];
for (i in pList.pLEditor.arConfig.arFontSizes)
{
fontSize = pList.pLEditor.arConfig.arFontSizes[i];
if (typeof fontSize == 'string')
pList.arItems.push({value: parseInt(i), name: fontSize});
}
for (i = 0; i < pList.arItems.length; i++)
{
oItem = pList.arItems[i];
if (typeof oItem != 'object' || !oItem.name)
continue;
pItem = jsUtils.CreateElement("DIV", {className: 'lhe-list-item-cont', title: oItem.name, id: 'lhe_font_size__' + i});
pIt = pItem.appendChild(jsUtils.CreateElement('SPAN', {className: 'lhe-list-font-span'}, {fontSize: oItem.name}));
pIt.innerHTML = oItem.name;
oItem.pWnd = pItem;
pItem.onclick = function(){pList.oBut.Select(pList.arItems[this.id.substring('lhe_font_size__'.length)], pList);};
pItem.onmouseover = function(){this.className = 'lhe-list-item-cont lhe-list-item-cont-over';};
pItem.onmouseout = function(){this.className = 'lhe-list-item-cont';};
pList.pValuesCont.appendChild(pItem);
}
},
OnOpen: function(pList)
{
var
frm = pList.pLEditor.queryCommand('FontSize'),
i, v;
if (pList.pSelectedItemId >= 0)
pList.SelectItem(false);
if (!frm)
frm = 'p';
frm = frm.toString().toLowerCase();
for (i = 0; i < pList.arItems.length; i++)
{
v = pList.arItems[i];
if (v.value.toString().toLowerCase() == frm)
{
pList.pSelectedItemId = i;
pList.SelectItem(true);
}
}
},
Select: function(oItem, pList)
{
pList.pLEditor.SelectRange(pList.pLEditor.oPrevRange);
pList.pLEditor.executeCommand('FontSize', oItem.value);
pList.Close();
}
};
LHEButtons['BackColor'] = {
id : 'BackColor',
name : LHE_MESS.BackColor,
type: 'Colorpicker',
OnSelect: function(color, pCol)
{
if(jsUtils.bIsIE)
{
pCol.pLEditor.executeCommand('BackColor', color || '');
}
else
{
//try{
pCol.pLEditor.pEditorDocument.execCommand("styleWithCSS", false, true);
if (!color)
pCol.pLEditor.executeCommand('removeFormat');
else
pCol.pLEditor.executeCommand('hilitecolor', color);
pCol.pLEditor.pEditorDocument.execCommand("styleWithCSS", false, false);
//}catch(e){}
}
}
};
LHEButtons['ForeColor'] = {
id : 'ForeColor',
name : LHE_MESS.ForeColor,
type: 'Colorpicker',
OnSelect: function(color, pCol)
{
if (!color && !jsUtils.bIsIE)
pCol.pLEditor.executeCommand('removeFormat');
else
pCol.pLEditor.executeCommand('ForeColor', color || '');
}
};
/* CONTEXT MENU*/
var LHEContMenu = {};
LHEContMenu["A"] = [LHEButtons['CreateLink'], LHEButtons['DeleteLink']];
LHEContMenu["IMG"] = [LHEButtons['Image']];
LHEContMenu["VIDEO"] = [LHEButtons['Video']];