Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
whackashoe committed Jan 11, 2015
1 parent be3d96d commit b21e362
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 38 deletions.
3 changes: 2 additions & 1 deletion app/controllers/PasteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function create()
{
$cmdline = false;
if(Input::has('code')) {
$input = Input::only('code');
$input = Input::only('code', 'parent_slug');
} else {
$input = [];
$req = Request::instance();
Expand All @@ -53,6 +53,7 @@ public function create()
$paste->ip = $input['ip'];
$paste->code = $input['code'];
$paste->slug = $slug;
$paste->parent_slug = Input::get('parent_slug', '');
$paste->save();

if($cmdline) {
Expand Down
7 changes: 4 additions & 3 deletions app/models/Paste.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ class Paste extends Eloquent {
use SoftDeletingTrait;

protected $table = 'pastes';
protected $fillable = ['ip', 'code', 'slug', 'views'];
protected $fillable = ['ip', 'code', 'slug', 'parent_slug', 'views'];
protected $dates = ['deleted_at'];


public static $rules = [
'code' => 'required|max:64000',
'ip' => 'required|ip'
'code' => 'required|max:64000',
'ip' => 'required|ip',
'parent_slug' => 'size:5'
];
}
4 changes: 4 additions & 0 deletions app/views/editor.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
<div id="linenumbers"></div>
<div id="content"><pre><code></code></pre></div>
<textarea spellcheck="false" autocomplete="off" autofocus="true" id="editor" name="code">{{ $paste->code or '' }}</textarea>
<input type="hidden" name="parent_slug" id="parent_slug" value="{{ $paste->slug or '' }}">
<div id="caret"></div>
<menu id="mainmenu">
<div id="linepadder"></div>
@if(isset($paste->ip) && strcmp($paste->ip, Request::getClientIp()) == 0)
<button id="views">views {{ $paste->views }}</button>
<button id="delete">delete</button>
@endif
@if(isset($paste->parent_slug) && !empty($paste->parent_slug))
<a href="{{ url($paste->parent_slug) }}"><button id="parent">parent</button></a>
@endif
<button id="save">save</button>
<a href="{{ url('terms') }}"><button id="terms">terms</button></a>
<a href="{{ url('about') }}"><button id="about">about</button></a>
Expand Down
11 changes: 5 additions & 6 deletions app/views/layouts/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<title>killr.io</title>

<link href="{{ asset('css/hybrid.css') }}" rel="stylesheet">
<link href="{{ asset('css/perfect-scrollbar.min.css') }}" rel="stylesheet">
<link href="{{ asset('css/template.css') }}" rel="stylesheet">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
Expand All @@ -25,10 +24,10 @@
<body>
@yield('content')

<script src="{{ asset('/js/jquery.min.js') }}"></script>
<script src="{{ asset('/js/jquery.caret-1.5.2.js') }}"></script>
<script src="{{ asset('/js/highlight.pack.js') }}"></script>
<script src="{{ asset('/js/perfect-scrollbar.min.js') }}"></script>
<script src="{{ asset('/js/interaction.js') }}"></script>
<script src="{{ asset('js/jquery.min.js') }}"></script>
<script src="{{ asset('js/jquery.caret-1.5.2.js') }}"></script>
<script src="{{ asset('js/highlight.pack.js') }}"></script>
<script src="{{ asset('js/textarea-caret-position.js') }}"></script>
<script src="{{ asset('js/interaction.js') }}"></script>
</body>
</html>
41 changes: 13 additions & 28 deletions public/js/interaction.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
var getCaretCoordinates = require('textarea-caret-position');

$(document).ready(function() {
hljs.initHighlightingOnLoad();
var cols_per_line = [];

//update caret
document.querySelector('#editor').addEventListener('input', function() { update_caret(this); });
document.querySelector('#editor').addEventListener('propertychange', function() { update_caret(this); });
document.querySelector('#editor').addEventListener('click', function() { update_caret(this); });

//catch tabs
$("body").on('keydown', '#editor', function(e) {
var keyCode = e.keyCode || e.which;
Expand All @@ -11,13 +18,6 @@ $(document).ready(function() {
}
});

$("#editor").on('keydown', function() {
update_caret();
})
.on('click', function() {
update_caret();
});

$("#editor").bind('input propertychange', function() {
var decoded = $("#editor").val();

Expand All @@ -35,12 +35,10 @@ $(document).ready(function() {
cols_per_line.push(t.length);
return '<tr><td>'+(i+1)+'</td></tr>';
}).join('')+'</table>');

update_caret();
}).trigger('propertychange');

$("#save").click(function() {
$.post('/', {code: $('#editor').val()}, function(result) {
$.post('/', {code: $('#editor').val(), parent_slug: $("#parent_slug").val()}, function(result) {
if(result.success) {
$("#success-modal").html('<a href="/' + result.slug + '">killr.io/' + result.slug + '</a>');
$("#overlay").show();
Expand All @@ -60,27 +58,14 @@ $(document).ready(function() {
});
});

function update_caret()
function update_caret(el)
{
var caret_row = 0;
var caret_col = 0;
var caret_tmp = $('#editor').caret();

for(var i=0; i<cols_per_line.length; ++i) {
if(cols_per_line[i] < caret_tmp) {
caret_tmp -= cols_per_line[i] + 1;
++caret_row;
} else break;
}
caret_col = caret_tmp;

var ln_offset = $("#linenumbers tr:eq(" + (caret_row) + ")").offset();
var coordinates = getCaretCoordinates(el, el.selectionEnd);
var content_offset = $("#content").offset();

$("#caret").css({
left: (14) + content_offset.left + 8 + (caret_col * 8) + "px",
top: (ln_offset.top - 2) + "px"
left: content_offset.left + coordinates.left,
top: content_offset.top + coordinates.top
});

}
});
Loading

0 comments on commit b21e362

Please sign in to comment.