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
* Notifications: show all/unread link
* Emojis popup selector
* bookmark on closed topic
Readme

View File

@ -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;
};

View File

@ -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 = '<a href="' + obj.url + '">' + obj.title + '</a>';
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( '<p>' + $txt + '</p>' );
$tab_notification_content.append( '<p>error</p>' );
})
.always( function() {

View File

@ -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() ) );

View File

@ -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 );

View File

@ -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 = $("<form/>", {
var $form = $("<form/>", {
'action': settings.target,
'method': "post"
});
}),
topic_id = $( "#id_move_comments_topic" ).val(),
$comment_id;
$input = $("<input/>", {
$("<input/>", {
'name': "csrfmiddlewaretoken",
'type': "hidden",
'value': settings.csrf_token
}).appendTo( $form );
// topic target
var topic_id = $( "#id_move_comments_topic" ).val();
$input = $("<input/>", {
$("<input/>", {
'name': "topic",
'type': "text",
'value': topic_id

View File

@ -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;
};

View File

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