js var declaration, the right way

This commit is contained in:
nitely 2014-05-19 21:48:50 -03:00
parent 34877186f7
commit 0d4b2568a4
8 changed files with 38 additions and 39 deletions

1
TODO
View File

@ -34,7 +34,6 @@ Template
* admin: add nav to detail templates * admin: add nav to detail templates
* Notifications: show all/unread link * Notifications: show all/unread link
* Emojis popup selector * Emojis popup selector
* bookmark on closed topic
Readme Readme

View File

@ -24,10 +24,8 @@
var settings = $.extend( { var settings = $.extend( {
csrf_token: "csrf_token", csrf_token: "csrf_token",
target: "target url", target: "target url",
}, options ); }, options ),
$this = $( this );
$this = this;
var post = function() { var post = function() {
@ -59,7 +57,7 @@
}, { offset: '100%', }); }, { offset: '100%', });
return $this; return this;
}; };

View File

@ -22,7 +22,8 @@ requires: utils.js
var switch_tab = function( tab ) { var switch_tab = function( tab ) {
$tabs_container = tab.closest( ".js-tabs-container" ); var $tabs_container = tab.closest( ".js-tabs-container" );
$tabs_container.find( ".js-tab-content" ).hide(); $tabs_container.find( ".js-tab-content" ).hide();
if ( tab.hasClass( "is-selected" ) ) if ( tab.hasClass( "is-selected" ) )
@ -49,19 +50,21 @@ requires: utils.js
// on first click // on first click
$( ".js-tab-notification" ).one("click", function( e ) { $( ".js-tab-notification" ).one("click", function( e ) {
$tab_notification = $( this ); var $tab_notification = $( this ),
$tab_notification_content = $( $tab_notification.data( "related" ) ); $tab_notification_content = $( $tab_notification.data( "related" ) );
$.getJSON( settings.notification_url ) $.getJSON( settings.notification_url )
.done( function( data, status, jqXHR ) { .done( function( data, status, jqXHR ) {
/* alert(jqXHR.responseText); */ /* alert(jqXHR.responseText); */
var $link,
$txt;
if ( data.n.length > 0 ) if ( data.n.length > 0 )
{ {
$.each( data.n, function( i, obj ) { $.each( data.n, function( i, obj ) {
$link = '<a href="' + obj.url + '">' + obj.title + '</a>'; $link = '<a href="' + obj.url + '">' + obj.title + '</a>';
if ( obj.action == "Mention" ) if ( obj.action === "Mention" )
{ {
$txt = settings.mention_txt; $txt = settings.mention_txt;
} }
@ -89,8 +92,7 @@ requires: utils.js
}) })
.fail( function() { .fail( function() {
$txt = 'error'; $tab_notification_content.append( '<p>error</p>' );
$tab_notification_content.append( '<p>' + $txt + '</p>' );
}) })
.always( function() { .always( function() {

View File

@ -14,14 +14,14 @@
}, options ); }, options );
$textarea = $( '.js-reply' ).find( 'textarea' ); var $textarea = $( '.js-reply' ).find( 'textarea' );
var wrapSelection = function( pre_txt, post_txt, default_txt ) { var wrapSelection = function( pre_txt, post_txt, default_txt ) {
var pre_selection = $textarea.val().substring( 0, $textarea[0].selectionStart ); var pre_selection = $textarea.val().substring( 0, $textarea[0].selectionStart ),
var selection = $textarea.val().substring( $textarea[0].selectionStart, $textarea[0].selectionEnd ); selection = $textarea.val().substring( $textarea[0].selectionStart, $textarea[0].selectionEnd ),
var post_selection = $textarea.val().substring( $textarea[0].selectionEnd ); post_selection = $textarea.val().substring( $textarea[0].selectionEnd );
if ( !selection ) { if ( !selection ) {
selection = default_txt; selection = default_txt;
@ -52,7 +52,7 @@
$( '.js-box-list' ).click(function() { $( '.js-box-list' ).click(function() {
wrapSelection( "\n\n* ", "", settings.list_item_text ); wrapSelection( "\n* ", "", settings.list_item_text );
return false; return false;
@ -78,7 +78,8 @@
$( '.js-box-preview' ).click(function() { $( '.js-box-preview' ).click(function() {
$preview = $( '.js-box-preview-content' ); var $preview = $( '.js-box-preview-content' );
$textarea.toggle(); $textarea.toggle();
$preview.toggle(); $preview.toggle();
$preview.html( marked( $textarea.val() ) ); $preview.html( marked( $textarea.val() ) );

View File

@ -15,16 +15,18 @@ requires: utils.js
like_text: "like ({count})", like_text: "like ({count})",
remove_like_text: "remove like ({count})", remove_like_text: "remove like ({count})",
}, options ); }, options );
var $likes = $( ".js-like" );
var post = function() { var post = function() {
$this = $( this ); var $this = $( this ),
href = $this.attr( 'href' );
$this.off( "click", post ); $this.off( "click", post );
var href = $this.attr( 'href' );
$.post( href, { 'csrfmiddlewaretoken': settings.csrf_token, }) $.post( href, { 'csrfmiddlewaretoken': settings.csrf_token, })
.done(function( data ) { .done(function( data ) {
@ -53,9 +55,7 @@ requires: utils.js
}); });
} }
$likes = $( ".js-like" );
$likes.on( 'click', post ); $likes.on( 'click', post );

View File

@ -16,6 +16,8 @@ Move comments to other topic
$( ".js-show-move-comments" ).on( 'click', function() { $( ".js-show-move-comments" ).on( 'click', function() {
var $li;
if ( $( ".move-comments" ).is( ":hidden" ) ) if ( $( ".move-comments" ).is( ":hidden" ) )
{ {
$( ".move-comments" ).show(); $( ".move-comments" ).show();
@ -37,21 +39,20 @@ Move comments to other topic
$( ".js-move-comments" ).on( 'click', function() { $( ".js-move-comments" ).on( 'click', function() {
// dynamic form // dynamic form
$form = $("<form/>", { var $form = $("<form/>", {
'action': settings.target, 'action': settings.target,
'method': "post" 'method': "post"
}); }),
topic_id = $( "#id_move_comments_topic" ).val(),
$comment_id;
$input = $("<input/>", { $("<input/>", {
'name': "csrfmiddlewaretoken", 'name': "csrfmiddlewaretoken",
'type': "hidden", 'type': "hidden",
'value': settings.csrf_token 'value': settings.csrf_token
}).appendTo( $form ); }).appendTo( $form );
// topic target $("<input/>", {
var topic_id = $( "#id_move_comments_topic" ).val();
$input = $("<input/>", {
'name': "topic", 'name': "topic",
'type': "text", 'type': "text",
'value': topic_id 'value': topic_id

View File

@ -2,11 +2,11 @@
$.fn.store = function( ls_key ) { $.fn.store = function( ls_key ) {
$this = this; var $this = $( this ),
$form = $this.closest( "form" ); $form = $this.closest( "form" );
if ( !localStorage ) { if ( !localStorage ) {
return $this; return this;
} }
@ -52,7 +52,7 @@
}); });
return $this; return this;
}; };

View File

@ -16,10 +16,6 @@
<script src="{{ STATIC_URL }}spirit/scripts/utils.js"></script> <script src="{{ STATIC_URL }}spirit/scripts/utils.js"></script>
<script src="{{ STATIC_URL }}spirit/scripts/dropdown.js"></script> <script src="{{ STATIC_URL }}spirit/scripts/dropdown.js"></script>
<script src="{{ STATIC_URL }}spirit/scripts/jquery.min.js"></script>
<script src="{{ STATIC_URL }}spirit/scripts/utils.js"></script>
<script src="{{ STATIC_URL }}spirit/scripts/dropdown.js"></script>
{% if user.is_authenticated %} {% if user.is_authenticated %}
<script src="{{ STATIC_URL }}spirit/scripts/marked/marked.min.js"></script> <script src="{{ STATIC_URL }}spirit/scripts/marked/marked.min.js"></script>
<script src="{{ STATIC_URL }}spirit/scripts/waypoints/waypoints.min.js"></script> <script src="{{ STATIC_URL }}spirit/scripts/waypoints/waypoints.min.js"></script>
@ -47,6 +43,8 @@
unread: "{% trans "unread" %}", unread: "{% trans "unread" %}",
} ); } );
$( "#id_comment" ).store( "comment" );
}); });
</script> </script>