User:Mopsgamer/global.js

/*DivEditor by Mopsgamer*/ /*Version 1.8*/

$(function {

DivEditor = { AddInside: "#Editor", FontSize: 14 }

if (window.wgUserLanguage == "ru") { DivEditorLang = { ButtonTextOpen: "Открыть", ButtonTextChange: "Сменить редактор", ButtonTextClose: "Закрыть", ButtonTextClear: "Очистить", ButtonTextCopy: "Копировать", ButtonTextSetCSS: "Применить", TextFontSize: "Размер текста", TextAreaTitle: "Код", ViewAreaTitle: "Вид", SettingStyles: "Стили", SettingText: "Текст", SettingColor: "Цвет", SettingFontFamily: "Шрифт", SettingFontSize: "Размер", SettingFontStyle: "Стиль", SettingFontWeight: "Жирность", SettingTextTransform: "Регистр", SettingTextDecoration: "Оформление", SettingWidth: "Ширина", SettingHeight: "Высота", SettingMargin: "Отступ снаружи", SettingPadding: "Отступ внутри", SettingBackground: "Фон", SettingPosition: "Позиция", SettingBorders: "Рамки", SettingBorderWidth: "Ширина", SettingBorderStyle: "Стиль", SettingBorderColor: "Цвет", SettingBorderRadius: "Радиус", SettingBoxShadow: "Тень", SettingTextShadow: "Тень текста", SettingOpacity: "Прозрачность", SettingTransform: "Трансформация", SettingTransformRotate: "Поворот", SettingTransformScale: "Scale", SettingTransformSkew: "Skew", SettingTransformTranslate: "Translate", SettingOverflow: "Переполнение", SettingAttributes: "Атрибуты", SettingClasses: "Классы", SettingId: "ID" }} else { DivEditorLang = { ButtonTextOpen: "Open", ButtonTextChange: "Change editor", ButtonTextClose: "Close", ButtonTextClear: "Clear", ButtonTextCopy: "Copy", ButtonTextSetCSS: "Apply", TextFontSize: "Font size", TextAreaTitle: "Code", ViewAreaTitle: "View", SettingStyles: "Styles", SettingText: "Text", SettingColor: "Color", SettingFontFamily: "Font", SettingFontSize: "Size", SettingFontStyle: "Style", SettingFontWeight: "Weight", SettingTextTransform: "Case", SettingTextDecoration: "Decor", SettingWidth: "Width", SettingHeight: "Height", SettingMargin: "Margin", SettingPadding: "Padding", SettingBackground: "Background", SettingPosition: "Position", SettingBorders: "Borders", SettingBorderWidth: "Width", SettingBorderStyle: "Style", SettingBorderColor: "Color", SettingBorderRadius: "Radius", SettingBoxShadow: "Shadow", SettingTextShadow: "Text shadow", SettingOpacity: "Opacity", SettingTransform: "Transform", SettingTransformRotate: "Rotate", SettingTransformScale: "Scale", SettingTransformSkew: "Skew", SettingTransformTranslate: "Translate", SettingOverflow: "Overflow", SettingAttributes: "Attributes", SettingClasses: "Classes", SettingId: "ID" }} Area = "EditorTextArea"; AreaTitle = DivEditorLang.TextAreaTitle; $(DivEditor.AddInside).append(' '); $('#DivEditor').html('').css("border", "1px solid #90afcc").css("background", "#b4dbff").append(' '); $('#EditorAreas').append(' '); $('#EditorAreas').append('  '); $('#EditorAreas').append(' '); $('#EditorRightArea').append('  + -  Копировать '); $('#EditorRightArea').append(' Очистить Применить  '); $('#EditorHeader').append('Открыть Закрыть '); $('#ViewSettings').append('  : <input type="text" prop="text"></li> : <input type="text" prop="color"></li> : <input type="text" prop="font-family"></li> : <input type="text" prop="font-size"></li> : <select prop="font-style"> inherit initial  italic  normal  oblique  </li> : <select prop="font-weight"> inherit  initial  1  2  3  4  5  6  7  8  9  </li> : <select prop="text-transform"> capitalize  inherit  initial  lowercase  uppercase  </li> : <select prop="text-decoration"> overline <option val="line-through">line-through  underline  </li></ul> : <input type="text" prop="width"></li> : <input type="text" prop="height"></li> : <input type="text" prop="margin"></li> : <input type="text" prop="padding"></li> : <input type="text" prop="background"></li> :  absolute  fixed  inherit  initial <option val="relative" selected>relative  static  sticky  </li> <li> : <input type="text" prop="border-width"></li><li> : <select prop="border-style"> dashed  dotted  double  groove  hidden  inherit  initial  inset  outset  revert  ridge <option val="solid" selected>solid  unset  </li><li> : <input type="text" prop="border-color"></li><li> : <input type="text" prop="border-radius"></li></ul></li><li> : <input type="text" prop="box-shadow"></li><li> : <input type="text" prop="text-shadow"></li><li> : <input type="text" prop="opacity"></li><li> <ul><li> : <input type="text" func="rotate"></li><li> : <input type="text" func="scale"></li><li> : <input type="text" func="skew"></li><li> : <input type="text" func="translate"></li></ul></li><li> :  auto  hidden  inherit  initial  overlay  scroll <option val="visible" selected>visible  </li><li style="list-style-type: none;text-align: center;font-weight: bold;border-bottom: 1px solid #94a6b8;margin-bottom: 5px;"> </li><li> : <input type="text" prop="class"></li><li> : <input type="text" prop="id"></li>');

$('#ChangeEditor').text(DivEditorLang.ButtonTextOpen); $('#Close').text(DivEditorLang.ButtonTextClose); $('#Clear').text(DivEditorLang.ButtonTextClear); $('#Copy').text(DivEditorLang.ButtonTextCopy); $('#SetCSS').text(DivEditorLang.ButtonTextSetCSS); $('#TextFontSize').text(DivEditorLang.TextFontSize + ":"); $('#FontSize').text(DivEditorLang.FontSize); $('#EditorAreaTitle').text(AreaTitle); $('#SettingStyles').text(DivEditorLang.SettingStyles); $('#SettingText').text(DivEditorLang.SettingText); $('#SettingColor').text(DivEditorLang.SettingColor); $('#SettingFontFamily').text(DivEditorLang.SettingFontFamily); $('#SettingFontSize').text(DivEditorLang.SettingFontSize); $('#SettingFontStyle').text(DivEditorLang.SettingFontStyle); $('#SettingFontWeight').text(DivEditorLang.SettingFontWeight); $('#SettingTextTransform').text(DivEditorLang.SettingTextTransform); $('#SettingTextDecoration').text(DivEditorLang.SettingTextDecoration); $('#SettingWidth').text(DivEditorLang.SettingWidth); $('#SettingHeight').text(DivEditorLang.SettingHeight); $('#SettingMargin').text(DivEditorLang.SettingMargin); $('#SettingPadding').text(DivEditorLang.SettingPadding); $('#SettingBackground').text(DivEditorLang.SettingBackground); $('#SettingPosition').text(DivEditorLang.SettingPosition); $('#SettingBorders').text(DivEditorLang.SettingBorders); $('#SettingBorderWidth').text(DivEditorLang.SettingBorderWidth); $('#SettingBorderStyle').text(DivEditorLang.SettingBorderStyle); $('#SettingBorderColor').text(DivEditorLang.SettingBorderColor); $('#SettingBorderRadius').text(DivEditorLang.SettingBorderRadius); $('#SettingBoxShadow').text(DivEditorLang.SettingBoxShadow); $('#SettingTextShadow').text(DivEditorLang.SettingTextShadow); $('#SettingOpacity').text(DivEditorLang.SettingOpacity); $('#SettingTransform').text(DivEditorLang.SettingTransform); $('#SettingTransformRotate').text(DivEditorLang.SettingTransformRotate); $('#SettingTransformScale').text(DivEditorLang.SettingTransformScale); $('#SettingTransformSkew').text(DivEditorLang.SettingTransformSkew); $('#SettingTransformTranslate').text(DivEditorLang.SettingTransformTranslate); $('#SettingOverflow').text(DivEditorLang.SettingOverflow); $('#SettingAttributes').text(DivEditorLang.SettingAttributes); $('#SettingClasses').text(DivEditorLang.SettingClasses); $('#SettingId').text(DivEditorLang.SettingId); $('#EditorRightAreaText').hide; $('#EditorAreaTitle').hide; $('#EditorAreas').hide; $('#Close').hide;

$('#EditorRightArea button').css("width", "auto"); $('#ViewSettings li').css("list-style-type", "none"); $('#ViewSettings input').css("width", "110px"); $('#ViewSettings select').css("width", "118px"); $('#ViewSettings input, #ViewSettings select').css("float", "right") $('#EditorTextArea').css("font-size", DivEditor.FontSize+"px");

var $setcss = function(prop) { $('#EditorViewArea>div') .css(prop, $('#ViewSettings input[prop=' + prop + ']').val); } var $setattr = function(attrib) { $('#EditorViewArea>div') .attr(attrib, $('#ViewSettings input[prop=' + attrib + ']').val); } var $setplhl = function(pl) { $('#ViewSettings input[prop=' + pl + ']') .attr("placeholder", pl); }

$setplhl("color"); $setplhl("font-family"); $setplhl("font-size"); $setplhl("width"); $setplhl("height"); $setplhl("margin"); $setplhl("padding"); $setplhl("background"); $setplhl("position"); $setplhl("border-width"); $setplhl("border-style"); $setplhl("border-color"); $setplhl("border-radius"); $setplhl("box-shadow"); $setplhl("text-shadow"); $setplhl("opacity"); $setplhl("transform"); $setplhl("overflow"); $setplhl("class"); $setplhl("id");

$("#SetCSS").click(function{

var rotate = ($('#ViewSettings input[func="rotate"]').val=="")?$('#ViewSettings input[func="rotate"]').val:"0"; var scale = ($('#ViewSettings input[func="scale"]').val=="")?$('#ViewSettings input[func="scale"]').val:"1"; var skew = ($('#ViewSettings input[func="skew"]').val=="")?$('#ViewSettings input[func="skew"]').val:"0"; var translate = ($('#ViewSettings input[func="translate"]').val=="")?$('#ViewSettings input[func="translate"]').val:"0"; $('#EditorViewArea>div').text($('#ViewSettings input[prop="text"]').val); $setcss("color"); $setcss("font-family"); $setcss("font-size"); $setcss("font-style"); $setcss("font-weight"); $setcss("text-transform"); $setcss("text-decoration"); $setcss("width"); $setcss("height"); $setcss("margin"); $setcss("padding"); $setcss("background"); $setcss("position"); $setcss("border-width"); $setcss("border-style"); $setcss("border-color"); $setcss("border-radius"); $setcss("box-shadow"); $setcss("text-shadow"); $setcss("opacity"); $setcss("transform"); $('#EditorViewArea>div').css("transform", "rotate("+rotate+") "+"scale("+scale+") "+"skew("+skew+") "+"translate("+translate+")"); $setcss("overflow"); $setattr("class"); $setattr("id"); })

$('#Clear').click(function{ $('#EditorViewArea>div').attr("style", "").attr("class", "").attr("id", "").text(""); $('[prop="color"]').val(""); $('[prop="font-family"]').val(""); $('[prop="font-size"]').val(""); $('[prop="width"]').val(""); $('[prop="height"]').val(""); $('[prop="margin"]').val(""); $('[prop="padding"]').val(""); $('[prop="background"]').val(""); $('[prop="border-width"]').val(""); $('[prop="border-color"]').val(""); $('[prop="border-radius"]').val(""); $('[prop="box-shadow"]').val(""); $('[prop="box-shadow"]').val(""); $('[prop="opacity"]').val(""); $('[prop="transform"]').val(""); $('[func="rotate"]').val(""); $('[func="scale"]').val(""); $('[func="skew"]').val(""); $('[func="translate"]').val(""); })

jQuery.fn.selectText = function { var range, selection; return this.each(function {   if (document.body.createTextRange) {      range = document.body.createTextRange;      range.moveToElementText(this);      range.select;    } else if (window.getSelection) {      selection = window.getSelection;      range = document.createRange;      range.selectNodeContents(this);      selection.removeAllRanges;      selection.addRange(range);    }  }); };

$('#Copy').click(function { $('#EditorTextArea').attr("contenteditable", "true");  $('#EditorTextArea').selectText;  document.execCommand("Copy");  document.getSelection.collapseToEnd;  $('#EditorTextArea').attr("contenteditable", "false"); });

$('#FontSizeIncrease').click(function{ if (DivEditor.FontSize < 30) {++DivEditor.FontSize; $('#EditorTextArea').css("font-size", DivEditor.FontSize+"px"); $('#FontSize').text(DivEditor.FontSize);} })

$('#FontSizeDecrease').click(function{ if (DivEditor.FontSize > 1) {--DivEditor.FontSize; $('#EditorTextArea').css("font-size", DivEditor.FontSize+"px"); $('#FontSize').text(DivEditor.FontSize);} })

$('#Close').click(function{ $('#ChangeEditor').text(DivEditorLang.ButtonTextOpen); $('#EditorAreas').hide; $('#EditorAreaTitle').hide; $('#Close').hide; $('#DivEditor').css("height", "unset").css("width", "unset").css("transition", "0.5s").unwrap; $('#HideFront').remove; }) Area = "EditorTextArea"; AreaTitle = DivEditorLang.ViewAreaTitle; $('#EditorViewArea').show; $('#EditorTextArea').hide; $('#ChangeEditor').click(function{ $('#DivEditor').css("height", "500px").css("width", "950px").css("transition", "0"); $('#Close').show; $('#EditorAreas').show; $('#EditorAreaTitle').show;

if( $('#ChangeEditor').text == DivEditorLang.ButtonTextOpen ){ $('#DivEditor').wrap(' '); $('head').append('<style id="HideFront">.avatars, .refpopups-configure-page{z-index: 0} .wds-community-header{z-index: 3} ') }	if( $('#ChangeEditor').text == DivEditorLang.ButtonTextChange ){ switch (Area) { case "EditorViewArea": Area = "EditorTextArea"; AreaTitle = DivEditorLang.ViewAreaTitle; $('#EditorTextArea').hide; $('#EditorViewArea').show; $('#EditorRightAreaView').show; $('#EditorRightAreaText').hide; $('#EditorTextArea').text($('#EditorViewArea').val); break; case "EditorTextArea": Area = "EditorViewArea"; AreaTitle = DivEditorLang.TextAreaTitle; $('#EditorTextArea').show; $('#EditorViewArea').hide; $('#EditorRightAreaView').hide; $('#EditorRightAreaText').show; $('#EditorTextArea').text($('#EditorViewArea').html); }} $('#EditorAreaTitle').text(AreaTitle); $('#ChangeEditor').text(DivEditorLang.ButtonTextChange); }); });