Permalink
Browse files

by default open external links in a new window (can be changed with a…

… new setting in local_settings)

Fix first part of ticket #23
  • Loading branch information...
1 parent 6365f08 commit 86bbe2451aca88eb67d92c075f4e0be3a8e40f36 @macadames macadames committed Aug 29, 2011
@@ -50,6 +50,8 @@
# Timeout for walls automatic reload in ms, 0 = no reload
WALLS_RELOAD_TIMEOUT = 120000
+# Open external links in a new window
+EXTERNAL_LINKS_NEW_WIN = True
# #
# Hosting settings #
# #
@@ -32,6 +32,7 @@ loadLastComment = function(comments_container, html) {
jq('form:first', comments_container).before(html);
window.setTimeout(function() {jq('.comment-description-field', comments_container).trigger('focusout')}, 3);
twistranet.showCommentsActions();
+ comments_container.initExternalLinks();
}
loadComments = function(ID, html) {
@@ -43,6 +44,7 @@ loadComments = function(ID, html) {
commentOnSubmit(comments_container);
commentOnFocus(comments_container);
jq('.comment-description-field', comments_container).focus();
+ comments_container.initExternalLinks();
}
commentOnFocus = function(comments_container) {
@@ -366,6 +366,7 @@ reloadWall = function() {
// for now we just remove all possibles messages (for deletion, etc ...)
// but we could want to add a new message here ?
jq("#tn-message").remove();
+ jq("#content").initExternalLinks();
});
},
error: function(jqXHR, textStatus, errorThrown) {
@@ -404,6 +405,7 @@ var twistranet = {
this.formInputsHints();
this.loadUploaders();
this.initWysiwygBrowser();
+ $('body').initExternalLinks();
},
setBrowserProperties : function(e) {
if (! this.browser_width){
@@ -447,6 +449,15 @@ var twistranet = {
block.remove();
}
});
+ },
+ initExternalLinks: function() {
+ if (external_links_new_win) {
+ jq("a[href^='http:']", this).each(function(){
+ if(jq(this).attr("href").search(location.host) == -1){
+ jq(this).attr("target", "_blank");
+ }
+ });
+ }
}
});
},
@@ -488,6 +499,7 @@ var twistranet = {
success: function(htmlcontent){
bottomBar.replaceWith(htmlcontent);
setFirstAndLast('#content', '.post');
+ jq("#content").initExternalLinks();
}
});
return false;
@@ -527,6 +539,7 @@ var twistranet = {
self.formInputsHints();
self.loadUploaders();
tnResourceWidget();
+ jq("#content").initExternalLinks();
});
}
});
@@ -8,6 +8,8 @@
from django.contrib import messages
from django.conf import settings
+DEFAULT_EXTERNAL_LINKS_NEW_WIN = True
+
def js_vars(request):
"""
return javascript dynamic stuff
@@ -19,11 +21,16 @@ def js_vars(request):
var home_url = '%(home_url)s';
var jq = jQuery;
var reloadtimeout=%(rtimeout)s;
+var external_links_new_win=%(external_links_new_win)s;
"""
-
+ if getattr(settings, 'EXTERNAL_LINKS_NEW_WIN', DEFAULT_EXTERNAL_LINKS_NEW_WIN):
+ external_links_new_win = 'true'
+ else:
+ external_links_new_win = 'false'
js_vars = dict(
home_url = reverse("twistranet_home"),
- rtimeout = getattr(settings, 'WALLS_RELOAD_TIMEOUT', 0)
+ rtimeout = getattr(settings, 'WALLS_RELOAD_TIMEOUT', 0),
+ external_links_new_win = external_links_new_win,
)
response = HttpResponse( src %js_vars,

0 comments on commit 86bbe24

Please sign in to comment.