diff --git a/ground/classes/Helper.php b/ground/classes/Helper.php index 7859a6f..36ca757 100644 --- a/ground/classes/Helper.php +++ b/ground/classes/Helper.php @@ -53,7 +53,7 @@ class Helper return $string; } - public static function replaceImgs($string, $replaceType = 'clear') + public static function replaceImgs($string, $replaceType = 'clear', $size = 'middle') { preg_match_all("(\[img[\|]#(\d+)\])", $string, $images); $images = isset($images[0]) ? $images[0] : FALSE; @@ -70,7 +70,7 @@ class Helper switch ($replaceType) { case 'html': $imgObj->caption = $linkTitle = str_replace('"', 'ʺ', $imgObj->caption); - $imgTag = '
'; + $imgTag = '
'; $string = str_replace($img, $imgTag, $string); break; default: diff --git a/ground/controllers/ArticlesController.php b/ground/controllers/ArticlesController.php index d317ea3..1b83f32 100644 --- a/ground/controllers/ArticlesController.php +++ b/ground/controllers/ArticlesController.php @@ -36,17 +36,19 @@ class ArticlesController extends Controller $articleId = (int) App::getParam('id'); - self::$layout = 'layoutPage.php'; + self::$layout = 'layoutClear.php'; self::addScript('/js/jquery-2.1.0.min.js'); self::addScript('/js/jquery-ui-1.10.4.custom.min.js'); self::addScript('/js/bootstrap.min.js'); self::addScript('/js/app.js?ver=' . App::getConfig('version')); + self::addScript('/js/articleEdit.js?ver=' . App::getConfig('version')); self::addScript('http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.3/fotorama.js'); self::addStyle('/css/style.css?ver=' . App::getConfig('version')); self::addStyle('/css/pageStyle.css?ver=' . App::getConfig('version')); self::addStyle('/css/bootstrap.min.css'); self::addStyle('/css/bootstrap-theme.min.css'); self::addStyle('http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.3/fotorama.css'); + self::addStyle('/css/articleEdit.css?ver=' . App::getConfig('version')); $article = Article::model()->getByPK($articleId); @@ -120,7 +122,7 @@ class ArticlesController extends Controller } } - App::redirect('/articles'); + App::redirect('/articles/edit/id/'.$article->id); } static function actionMarkdown() @@ -131,7 +133,7 @@ class ArticlesController extends Controller $html = Markdown::processing($html); $html = nl2br($html); $html = Helper::replaceLinks($html, 'html'); - $html = Helper::replaceImgs($html, 'html'); + $html = Helper::replaceImgs($html, 'html', 'small'); print $html; } diff --git a/ground/views/articles/edit.php b/ground/views/articles/edit.php index 6cf3e52..874d6dd 100644 --- a/ground/views/articles/edit.php +++ b/ground/views/articles/edit.php @@ -1,142 +1,67 @@ - -
- -
-
-
-

Редактирование статьи

-
- Вернуться: к списку статей / на карту. -
-
-
- - -
- - + + + + + + + + + + + +
+
+
+
+
+
+ +
+ +
+
+ + + + + +
+
+ +
+ -
- - - - - -
- - - - -
-
- - *текст* **текст** ***текст*** http://ссылка.ру # заголвок1 ## заголовк2 ### заголовк3 [#512|ссылка на точку 512] -
- -
- -
- - - -
+
+
+
+ +
+
-
- - -
- - -
-
- -
-
- -
- +
+
+
-
- -
+
+ +
+
+ +
+
- +
+
+ + diff --git a/ground/views/layoutClear.php b/ground/views/layoutClear.php new file mode 100644 index 0000000..56a1137 --- /dev/null +++ b/ground/views/layoutClear.php @@ -0,0 +1,60 @@ + + + + <?= App::getConfig('title') ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ground/views/modals/articleInfo.php b/ground/views/modals/articleInfo.php new file mode 100644 index 0000000..ced4ba4 --- /dev/null +++ b/ground/views/modals/articleInfo.php @@ -0,0 +1,77 @@ + \ No newline at end of file diff --git a/public/css/articleEdit.css b/public/css/articleEdit.css new file mode 100644 index 0000000..7c18e8c --- /dev/null +++ b/public/css/articleEdit.css @@ -0,0 +1,21 @@ +/*body {overflow-y: scroll;}*/ +#inputHeader {width: 100%;} +#inputHeader div.form-group {width: 100%;} +input#articleTitle {font-size: 30px;font-weight: 600;height: 45px; border-radius: 0;} +#submitButton {} + +.nopaddingx {padding-left: 0;padding-right: 0;} +.nopaddingy {padding-bottom: 0;padding-top: 0;} + +#articleText {border-radius:0;} +#articleText { + width: 100%; + -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */ + -moz-box-sizing: border-box; /* Firefox, other Gecko */ + box-sizing: border-box; /* Opera/IE 8+ */ +} +/*#monitor {background-color: white; overflow-y: scroll; padding: 5px 10px; border: solid 1px #ccc; border-radius: 0px;}*/ +#monitor {height: 100%; width: 100%; background-color: white; overflow-y: scroll; padding: 5px 10px; border: solid 1px #ccc; border-radius: 0px;} + +#photobankContainer {position: absolute; top: 0; right: 0px; width: 675px; background-color: rgba(55,55,55, 0.8); overflow-y: scroll; height: 100%;} +#photobankContainer {display: none;} \ No newline at end of file diff --git a/public/js/articleEdit.js b/public/js/articleEdit.js new file mode 100644 index 0000000..ed421cb --- /dev/null +++ b/public/js/articleEdit.js @@ -0,0 +1,115 @@ +/* + * + */ + +var monitorTimeout; + +function updatePhotobank() { + if (document.getElementById("hiddenframe").contentWindow.document.body.innerText == 'error') { + alert('Ошибка при загрузке.'); + return false; + } + + $('#photo').val(''); + $('#caption').val(''); + $.getJSON("/json/getmyartphotos", function (data) { + $('#photobank').html(''); + $.each(data, function (key, val) { + $(" ", { + "class": "my-new-list", + src: '/photos/articles/small/' + val.name, + title: 'img #' + val.id + ' :: ' + val.caption, + photoId: val.id + }).appendTo('#photobank'); + }); + + $("#photobank img").on("click", function () { + imgText = '\n[img|#' + $(this).attr('photoid') + ']\n'; + insertAtCursor('articleText', imgText); + markdown(); + togglePhotobank(); + }); + }); +} + +function markBold() +{ + wrapText('articleText', '**', '**'); + markdown(); +} + +function markItalic() +{ + wrapText('articleText', '*', '*'); + markdown(); +} + +function insertPoint() +{ + insertAtCursor('articleText', '[#' + prompt('Укажите номер точки', '') + '|ссылка на точку]'); + markdown(); +} + +function insertAtCursor(myFieldId, myValue) { + myField = document.getElementById(myFieldId); + + //IE support + if (document.selection) { + myField.focus(); + sel = document.selection.createRange(); + sel.text = myValue; + } + //MOZILLA and others + else if (myField.selectionStart || myField.selectionStart == '0') { + var startPos = myField.selectionStart; + var endPos = myField.selectionEnd; + myField.value = myField.value.substring(0, startPos) + + myValue + + myField.value.substring(endPos, myField.value.length); + } else { + myField.value += myValue; + } +} + +function wrapText(elementID, openTag, closeTag) { + var textArea = $('#' + elementID); + var len = textArea.val().length; + var start = textArea[0].selectionStart; + var end = textArea[0].selectionEnd; + var selectedText = textArea.val().substring(start, end); + var replacement = openTag + selectedText + closeTag; + textArea.val(textArea.val().substring(0, start) + replacement + textArea.val().substring(end, len)); +} + +function markdown() +{ + $.post('/articles/markdown', {text: $('#articleText').val()}, function (data) { + $('#monitor').html(data); + }); +} + +$('#articleText').keyup(function () { + clearTimeout(monitorTimeout); + monitorTimeout = setTimeout(function () { + $('#submitButton').addClass('btn-info'); + markdown(); + }, 200); +}).keydown(function () { + clearTimeout(monitorTimeout) +}).scroll(function () { + monH = document.getElementById('monitor').scrollHeight - document.getElementById('monitor').clientHeight; + areH = document.getElementById('articleText').scrollHeight - document.getElementById('articleText').clientHeight; + areS = $('#articleText').scrollTop(); + monS = Math.round((areS / areH) * monH); + $('#monitor').scrollTop(monS); +}); + +$(document).ready(function () { + markdown(); + $('#articleText').focus(); +}); + +function togglePhotobank() +{ + $('#photobankContainer').slideToggle(200); +}