From 0d4b2568a401dcbd4d24600b4681bc2c3d912f10 Mon Sep 17 00:00:00 2001 From: nitely Date: Mon, 19 May 2014 21:48:50 -0300 Subject: [PATCH] js var declaration, the right way --- TODO | 1 - spirit/static/spirit/scripts/bookmark.js | 8 +++----- spirit/static/spirit/scripts/dropdown.js | 14 ++++++++------ spirit/static/spirit/scripts/editor.js | 13 +++++++------ spirit/static/spirit/scripts/like.js | 12 ++++++------ spirit/static/spirit/scripts/move_comments.js | 15 ++++++++------- spirit/static/spirit/scripts/storage.js | 8 ++++---- spirit/templates/spirit/_base.html | 6 ++---- 8 files changed, 38 insertions(+), 39 deletions(-) diff --git a/TODO b/TODO index 4dc0ae68..2a8292e5 100644 --- a/TODO +++ b/TODO @@ -34,7 +34,6 @@ Template * admin: add nav to detail templates * Notifications: show all/unread link * Emojis popup selector -* bookmark on closed topic Readme diff --git a/spirit/static/spirit/scripts/bookmark.js b/spirit/static/spirit/scripts/bookmark.js index a094ec29..9b9f665a 100644 --- a/spirit/static/spirit/scripts/bookmark.js +++ b/spirit/static/spirit/scripts/bookmark.js @@ -24,10 +24,8 @@ var settings = $.extend( { csrf_token: "csrf_token", target: "target url", - }, options ); - - - $this = this; + }, options ), + $this = $( this ); var post = function() { @@ -59,7 +57,7 @@ }, { offset: '100%', }); - return $this; + return this; }; diff --git a/spirit/static/spirit/scripts/dropdown.js b/spirit/static/spirit/scripts/dropdown.js index 6c6a6758..3fa3d244 100644 --- a/spirit/static/spirit/scripts/dropdown.js +++ b/spirit/static/spirit/scripts/dropdown.js @@ -22,7 +22,8 @@ requires: utils.js 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(); if ( tab.hasClass( "is-selected" ) ) @@ -49,19 +50,21 @@ requires: utils.js // on first click $( ".js-tab-notification" ).one("click", function( e ) { - $tab_notification = $( this ); - $tab_notification_content = $( $tab_notification.data( "related" ) ); + var $tab_notification = $( this ), + $tab_notification_content = $( $tab_notification.data( "related" ) ); $.getJSON( settings.notification_url ) .done( function( data, status, jqXHR ) { /* alert(jqXHR.responseText); */ + var $link, + $txt; if ( data.n.length > 0 ) { $.each( data.n, function( i, obj ) { $link = '' + obj.title + ''; - if ( obj.action == "Mention" ) + if ( obj.action === "Mention" ) { $txt = settings.mention_txt; } @@ -89,8 +92,7 @@ requires: utils.js }) .fail( function() { - $txt = 'error'; - $tab_notification_content.append( '

' + $txt + '

' ); + $tab_notification_content.append( '

error

' ); }) .always( function() { diff --git a/spirit/static/spirit/scripts/editor.js b/spirit/static/spirit/scripts/editor.js index eba59182..fd6645a0 100644 --- a/spirit/static/spirit/scripts/editor.js +++ b/spirit/static/spirit/scripts/editor.js @@ -14,14 +14,14 @@ }, options ); - $textarea = $( '.js-reply' ).find( 'textarea' ); + var $textarea = $( '.js-reply' ).find( 'textarea' ); var wrapSelection = function( pre_txt, post_txt, default_txt ) { - var pre_selection = $textarea.val().substring( 0, $textarea[0].selectionStart ); - var selection = $textarea.val().substring( $textarea[0].selectionStart, $textarea[0].selectionEnd ); - var post_selection = $textarea.val().substring( $textarea[0].selectionEnd ); + var pre_selection = $textarea.val().substring( 0, $textarea[0].selectionStart ), + selection = $textarea.val().substring( $textarea[0].selectionStart, $textarea[0].selectionEnd ), + post_selection = $textarea.val().substring( $textarea[0].selectionEnd ); if ( !selection ) { selection = default_txt; @@ -52,7 +52,7 @@ $( '.js-box-list' ).click(function() { - wrapSelection( "\n\n* ", "", settings.list_item_text ); + wrapSelection( "\n* ", "", settings.list_item_text ); return false; @@ -78,7 +78,8 @@ $( '.js-box-preview' ).click(function() { - $preview = $( '.js-box-preview-content' ); + var $preview = $( '.js-box-preview-content' ); + $textarea.toggle(); $preview.toggle(); $preview.html( marked( $textarea.val() ) ); diff --git a/spirit/static/spirit/scripts/like.js b/spirit/static/spirit/scripts/like.js index 5edcd65c..32d69ee1 100644 --- a/spirit/static/spirit/scripts/like.js +++ b/spirit/static/spirit/scripts/like.js @@ -15,16 +15,18 @@ requires: utils.js like_text: "like ({count})", remove_like_text: "remove like ({count})", }, options ); + + + var $likes = $( ".js-like" ); var post = function() { - $this = $( this ); + var $this = $( this ), + href = $this.attr( 'href' ); $this.off( "click", post ); - var href = $this.attr( 'href' ); - $.post( href, { 'csrfmiddlewaretoken': settings.csrf_token, }) .done(function( data ) { @@ -53,9 +55,7 @@ requires: utils.js }); } - - - $likes = $( ".js-like" ); + $likes.on( 'click', post ); diff --git a/spirit/static/spirit/scripts/move_comments.js b/spirit/static/spirit/scripts/move_comments.js index 1dd7eb40..a2fdb904 100644 --- a/spirit/static/spirit/scripts/move_comments.js +++ b/spirit/static/spirit/scripts/move_comments.js @@ -16,6 +16,8 @@ Move comments to other topic $( ".js-show-move-comments" ).on( 'click', function() { + var $li; + if ( $( ".move-comments" ).is( ":hidden" ) ) { $( ".move-comments" ).show(); @@ -37,21 +39,20 @@ Move comments to other topic $( ".js-move-comments" ).on( 'click', function() { // dynamic form - $form = $("
", { + var $form = $("", { 'action': settings.target, 'method': "post" - }); + }), + topic_id = $( "#id_move_comments_topic" ).val(), + $comment_id; - $input = $("", { + $("", { 'name': "csrfmiddlewaretoken", 'type': "hidden", 'value': settings.csrf_token }).appendTo( $form ); - // topic target - var topic_id = $( "#id_move_comments_topic" ).val(); - - $input = $("", { + $("", { 'name': "topic", 'type': "text", 'value': topic_id diff --git a/spirit/static/spirit/scripts/storage.js b/spirit/static/spirit/scripts/storage.js index 1496857f..d873cda2 100644 --- a/spirit/static/spirit/scripts/storage.js +++ b/spirit/static/spirit/scripts/storage.js @@ -2,11 +2,11 @@ $.fn.store = function( ls_key ) { - $this = this; - $form = $this.closest( "form" ); + var $this = $( this ), + $form = $this.closest( "form" ); if ( !localStorage ) { - return $this; + return this; } @@ -52,7 +52,7 @@ }); - return $this; + return this; }; diff --git a/spirit/templates/spirit/_base.html b/spirit/templates/spirit/_base.html index 51489bdd..28f6e5a5 100644 --- a/spirit/templates/spirit/_base.html +++ b/spirit/templates/spirit/_base.html @@ -16,10 +16,6 @@ - - - - {% if user.is_authenticated %} @@ -47,6 +43,8 @@ unread: "{% trans "unread" %}", } ); + $( "#id_comment" ).store( "comment" ); + });