Commit 441de0a5 by tady

js format

use strict;
parent d41c6b0d
...@@ -20,84 +20,72 @@ ...@@ -20,84 +20,72 @@
// Automaticaly change textarea height. // Automaticaly change textarea height.
$(document).ready(function(){ $(function(){
'use strict';
$('textarea.autosize').autosize(); $('textarea.autosize').autosize();
});
// Preview post. // Preview post.
$(document).ready(function(){
var load_preview = function(){ var load_preview = function(){
var text = $('#post_body').val(); var text = $('#post_body').val();
var csrfToken = $('meta[name="csrf-token"]').attr('content'); var csrfToken = $("meta[name='csrf-token']").attr('content');
$.post('/posts/preview.api', { $.post('/posts/preview.api', {
"text": text, 'text': text,
"authenticity_token": csrfToken 'authenticity_token': csrfToken
}) })
.done(function(data){ .done(function(data){
$('#post_preview').html(data); $('#post_preview').html(data);
}) });
}; };
$('#post_body').on('keyup mouseup', load_preview); $('#post_body').on('keyup mouseup', load_preview);
load_preview(); load_preview();
});
// post list // post list
$(document).ready(function(){
$('.post-list').on('click', function(e){ $('.post-list').on('click', function(e){
e.preventDefault(); e.preventDefault();
$this = $(this); var $this = $(this);
$this.siblings().removeClass('active'); $this.siblings().removeClass('active');
$this.addClass('active'); $this.addClass('active');
var id = $this.data('postId'); var id = $this.data('postId');
$.get('/posts/show_fragment', { $.get('/posts/show_fragment', {
"id": id, 'id': id,
}) })
.done(function(data){ .done(function(data){
$('#list_post').html(data); $('#list_post').html(data);
}) });
}) });
});
// search form // search form
$(document).ready(function(){ $('#app-search-form input').on('focus', function(){
$('#app-search-form input').on('focus', function(e){
$(this).parents('#app-search-form').animate({width: '600px'}); $(this).parents('#app-search-form').animate({width: '600px'});
}).on('blur', function(e){ }).on('blur', function(){
$(this).parents('#app-search-form').animate({width: '200px'}); $(this).parents('#app-search-form').animate({width: '200px'});
}) });
});
// disable tab key // disable tab key
$(document).ready(function(){
$('.disable-tab').on('keydown', function(e) { $('.disable-tab').on('keydown', function(e) {
var keyCode = e.keyCode || e.which; var keyCode = e.keyCode || e.which;
if (keyCode == 9) { if (keyCode === 9) {
e.preventDefault(); e.preventDefault();
var start = $(this).get(0).selectionStart; var start = $(this).get(0).selectionStart;
var end = $(this).get(0).selectionEnd; var end = $(this).get(0).selectionEnd;
// set textarea value to: text before caret + tab + text after caret // set textarea value to: text before caret + tab + text after caret
$(this).val($(this).val().substring(0, start) $(this).val($(this).val().substring(0, start) +
+ "\t" '\t' +
+ $(this).val().substring(end)); $(this).val().substring(end));
// put caret at right position again // put caret at right position again
$(this).get(0).selectionStart = $(this).get(0).selectionStart =
$(this).get(0).selectionEnd = start + 1; $(this).get(0).selectionEnd = start + 1;
} }
}); });
});
// new post tags
// new post tags $('#post_tags').select2();
$(document).ready(function(){
$("#post_tags").select2();
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment