Skip to content

Commit

Permalink
Implemented notifications for new suggestions and comments, new edito…
Browse files Browse the repository at this point in the history
…r, code highlighting, rollbar handler for errors
  • Loading branch information
samdark committed Aug 16, 2016
1 parent 7ab66d2 commit bd2889d
Show file tree
Hide file tree
Showing 61 changed files with 962 additions and 947 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ phpunit.phar
/config/key.php
/config/db.php
/config/authclients.php
/config/rollbar.php

# rbac items
/rbac
3 changes: 3 additions & 0 deletions assets/AppAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ class AppAsset extends AssetBundle
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/prism.css',
'css/site.css',
];
public $js = [
'js/prism.js',
'js/site.js',
];
public $depends = [
'yii\web\YiiAsset',
Expand Down
53 changes: 53 additions & 0 deletions assets/CodeMirrorAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php


namespace app\assets;


use yii\web\AssetBundle;

/**
* CodeMirrorAsset groups assets for code editing areas
*/
class CodeMirrorAsset extends AssetBundle
{
public $sourcePath = '@bower/codemirror';

public $js = [
'lib/codemirror.js',

// langs to highlight in markdown blocks
'mode/shell/shell.js',
'mode/clike/clike.js',
'mode/css/css.js',
'mode/javascript/javascript.js',
'mode/php/php.js',
'mode/sass/sass.js',
'mode/sql/sql.js',
'mode/twig/twig.js',
'mode/xml/xml.js',
'mode/yaml/yaml.js',
'mode/htmlmixed/htmlmixed.js',

// markdown and gfm
'mode/meta.js',
'mode/markdown/markdown.js',
'addon/mode/overlay.js',
'mode/gfm/gfm.js',
'addon/edit/continuelist.js',


// code editing goods
'addon/fold/xml-fold.js',
'addon/edit/matchbrackets.js',
'addon/edit/closebrackets.js',
'addon/edit/closetag.js',

// for controls
'addon/display/panel.js',
];

public $css = [
'lib/codemirror.css',
];
}
14 changes: 14 additions & 0 deletions assets/CodeMirrorButtonsAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace app\assets;

use yii\web\AssetBundle;

class CodeMirrorButtonsAsset extends AssetBundle
{
public $sourcePath = '@bower/codemirror-buttons';

public $js = [
'buttons.js',
];
}
20 changes: 20 additions & 0 deletions assets/MarkdownEditorAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace app\assets;

use yii\web\AssetBundle;

/**
* MarkdownEditorAsset groups assets for markdown editor
*/
class MarkdownEditorAsset extends AssetBundle
{
public $sourcePath = '@app/assets/markdown';
public $js = [
'editor.js',
];
public $depends = [
'yii\web\JqueryAsset',
'app\assets\CodeMirrorAsset',
'app\assets\CodeMirrorButtonsAsset',
];
}
125 changes: 125 additions & 0 deletions assets/markdown/editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
jQuery(function ($) {
CodeMirror.findModeByName('php').mime = 'text/x-php';
});

function initEditor(el) {
el = $(el)[0];
var editor = CodeMirror.fromTextArea(el, {
mode: 'gfm',
theme: 'default',
extraKeys: {
"Enter": 'newlineAndIndentContinueMarkdownList',
},
lineWrapping: true,
lineNumbers: false,
matchBrackets: true,
autoCloseBrackets: true,
autoCloseTags: true,
buttons: [
{
hotkey: 'Ctrl-B',
class: 'bold btn btn-default',
label: '<i class="glyphicon glyphicon-bold"></i>',
callback: function (cm) {
var selection = cm.getSelection();
cm.replaceSelection('**' + selection + '**');
if (!selection) {
var cursorPos = cm.getCursor();
cm.setCursor(cursorPos.line, cursorPos.ch - 2);
}
}
},
{
hotkey: 'Ctrl-I',
class: 'italic btn btn-default',
label: '<i class="glyphicon glyphicon-italic"></i>',
callback: function (cm) {
var selection = cm.getSelection();
cm.replaceSelection('*' + selection + '*');
if (!selection) {
var cursorPos = cm.getCursor();
cm.setCursor(cursorPos.line, cursorPos.ch - 1);
}
}
},
{
class: 'block-code btn btn-default',
label: 'CODE',
callback: function (cm) {
var language = prompt('Language') || '';

var selection = cm.getSelection();
cm.replaceSelection("```" + language + "\n" + selection + "\n```\n");
if (!selection) {
var cursorPos = cm.getCursor();
cm.setCursor(cursorPos.line - 2, 0);
}
}
},
{
class: 'quote btn btn-default',
label: '<i class="glyphicon glyphicon-menu-right"></i>',
callback: function (cm) {
cm.replaceSelection("> " + cm.getSelection());
}
},
{
class: 'ul btn btn-default',
label: 'UL',
callback: function (cm) {
cm.replaceSelection("- " + cm.getSelection());
}
},
{
class: 'ol btn btn-default',
label: 'OL',
callback: function (cm) {
cm.replaceSelection("1. " + cm.getSelection());
}
},
{
class: 'a btn btn-default',
label: '<i class="glyphicon glyphicon-link"></i>',
callback: function (cm) {
var selection = cm.getSelection();
var text = '';
var link = '';

if (selection.match(/^https?:\/\//)) {
link = selection;
} else {
text = selection;
}
cm.replaceSelection('[' + text + '](' + link + ')');

var cursorPos = cm.getCursor();
if (!selection) {
cm.setCursor(cursorPos.line, cursorPos.ch - 3);
} else if (link) {
cm.setCursor(cursorPos.line, cursorPos.ch - (3 + link.length));
} else {
cm.setCursor(cursorPos.line, cursorPos.ch - 1);
}
}
},
{
class: 'img btn btn-default',
label: '<i class="glyphicon glyphicon-picture"></i>',
callback: function (cm) {
var url = prompt('Add image url') || '';

var selection = cm.getSelection();
cm.replaceSelection('<img src="' + url + '"' + selection + ' />');

}
},
{
class: 'img btn btn-default',
label: '<i class="glyphicon glyphicon-resize-small"></i>',
callback: function (cm) {
$('.CodeMirror').css('height', 'auto');
}
},
]
});
};
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
"minimum-stability": "stable",
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": "~2.0.6",
"yiisoft/yii2-bootstrap": "~2.0.5",
"yiisoft/yii2-swiftmailer": "~2.0.4",
"ijackua/yii2-lepture-markdown-editor-widget": "~1.0.0",
"yiisoft/yii2": "~2.0.9",
"yiisoft/yii2-bootstrap": "~2.0.6",
"yiisoft/yii2-swiftmailer": "~2.0.5",
"yiisoft/yii2-authclient": "~2.0.5",
"cebe/yii2-gravatar": "~1.1"
"cebe/yii2-gravatar": "~1.1",
"baibaratsky/yii2-rollbar": "1.2.*",
"bower-asset/codemirror": "~5.9.0",
"bower-asset/codemirror-buttons": "~1.0.0"
},
"require-dev": {
"yiisoft/yii2-codeception": "~2.0.4",
"yiisoft/yii2-debug": "~2.0.5",
"yiisoft/yii2-gii": "~2.0.4",
"yiisoft/yii2-faker": "~2.0.3"
"yiisoft/yii2-debug": "~2.0.6",
"yiisoft/yii2-gii": "~2.0.5"
},
"config": {
"process-timeout": 1800
Expand Down
Loading

0 comments on commit bd2889d

Please sign in to comment.