From 7ed9b8b84f3d850374b86100908fdb32721d7e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Deparis?= Date: Thu, 16 Oct 2014 10:47:08 +0200 Subject: [PATCH 1/4] First try around hashchange monitoring --- js/interface_common.js | 56 +++++++++++++++++++++++++++--------------- js/interface_home.js | 8 +++--- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/js/interface_common.js b/js/interface_common.js index ba93950..dd7e725 100644 --- a/js/interface_common.js +++ b/js/interface_common.js @@ -30,7 +30,7 @@ function openModal( modalClass ) //fecha o modal removendo o conteúdo por detach function closeModal($this) -{ +{ var $body = $( "body" ); var $modalWindows = $( "body" ).children( ".modal-blackout" ); @@ -103,7 +103,12 @@ function openProfileModal(e) var $this = $( this ); var username = $.MAL.urlToUser( $this.attr("href") ); - + openProfileModalWithUsername(username); +} + + +function openProfileModalWithUsername(username) +{ if(!username) { alert(polyglot.t("You don't have any profile because you are not logged in.")); @@ -118,14 +123,14 @@ function openProfileModal(e) //título do modal $( "."+profileModalClass + " h3" ).text( polyglot.t("users_profile", { username: username }) ); - + //hed//add dinamic follow button in profile modal window if(followingUsers.indexOf(username) != -1){ $('.profile-card button.followButton').first().removeClass('follow').addClass('profileUnfollow').text(polyglot.t('Unfollow')).on('click', function(){ unfollow(username); }); }; - + $(".tox-ctc").attr("title", polyglot.t("Copy to clipboard")); $(".bitmessage-ctc").attr("title", polyglot.t("Copy to clipboard")); } @@ -354,6 +359,17 @@ function openConversationModal(e) $( "." + conversationModalClass + " h3" ).text( polyglot.t('conversation_title', {'username': postLi.find('.post-data').attr('data-screen-name')}) ); } + +function watchHashChange(e){ + if(/user=(.+)/.test(window.location.hash)) + { + var username = location.hash.match(/user=(.+)/); + if(username[1] != undefined) + openProfileModalWithUsername(username[1]); + } +} + + // // Post actions, submit, count characters // -------------------------------------- @@ -366,7 +382,7 @@ var reTwistPopup = function( e ) alert(polyglot.t("You have to log in to retransmit messages.")); return; } - + var reTwistClass = "reTwist"; openModal( reTwistClass ); @@ -439,7 +455,7 @@ var postExpandFunction = function( e, postLi ) var $postsRelated = postLi.find(".related"); var openClass = "open"; - + if( !postLi.hasClass( openClass ) ) { originalPost.detach(); postLi.empty(); @@ -451,7 +467,7 @@ var postExpandFunction = function( e, postLi ) originalLi.append(originalPost); $postExpandedContent.slideDown( "fast" ); - + if ($.Options.getShowPreviewOpt() == 'enable'){ var previewContainer=$postExpandedContent.find(".preview-container")[0]; /* was the preview added before... */ @@ -683,7 +699,7 @@ function replyTextKeypress(e) { } }else if( !$.Options.keyEnterToSend() ){ if (e.keyCode === 13 && (e.metaKey || e.ctrlKey)) { - + $this.val($this.val().trim()); if( !tweetAction.hasClass("disabled") ) { tweetAction.click(); @@ -960,15 +976,15 @@ var unicodeConversionList = { function getRangesForUnicodeConversion(msg) { if(!msg) return; - + var tempMsg = msg; var results = []; var regexHttpStart = /http[s]?:\/\//; var regexHttpEnd = /[ \n\t]/; var start=0, end, position, rep = true; - + position = tempMsg.search(regexHttpStart); - + while(position!=-1) { end = start + position; @@ -979,7 +995,7 @@ function getRangesForUnicodeConversion(msg) rep = !rep; start = end; tempMsg = tempMsg.substring(position, tempMsg.length); - + if(rep == true) position = tempMsg.search(regexHttpStart); else @@ -988,15 +1004,15 @@ function getRangesForUnicodeConversion(msg) end = msg.length; if(end > start) results.push({start: start, end: end, replace: rep}); - - return results; + + return results; } function getUnicodeReplacement(msg, list, ranges, ta) { if(!msg || !list || !ranges) return; if(ranges.length===0) return ""; - + var position, substrings = []; for (var j=0; j 0) { var ub = ta.closest(".post-area-new").find(".undo-unicode"); @@ -1083,7 +1099,7 @@ function undoLastUnicode(e) { var uc = $ta.data("unicodeConversionStack").shift(); var pt = $ta.val(); - + // If the text was shifted, and character is no longer at the saved position, this function // searches for it to the right. If it is not there, it searches in the oposite direction. // if it's not there either, it means it was deleted, so it is skipped. @@ -1282,7 +1298,7 @@ function replaceDashboards() { } function initInterfaceCommon() { - $( "body" ).on( "click", function(event) { + $( "body" ).on( "click", function(event) { if($(event.target).hasClass('cancel')) closeModal($(this)); }); $(".cancel").on('click', function(event){ diff --git a/js/interface_home.js b/js/interface_home.js index 5c930d6..5c2a2cb 100644 --- a/js/interface_home.js +++ b/js/interface_home.js @@ -31,7 +31,7 @@ var InterfaceFunctions = function() requestTimelineUpdate("latest",postsPerRefresh,followingUsers,promotedPostsOnly);}); // modified the way promoted posts are shown - $( ".promoted-posts-only").click(function() { + $( ".promoted-posts-only").click(function() { promotedPostsOnly = !promotedPostsOnly; //active promoted posts tab $(this).children('.promoted-posts').addClass(promotedPostsOnly ? "active" : "disabled"); @@ -163,15 +163,15 @@ var InterfaceFunctions = function() var interfaceFunctions = new InterfaceFunctions; $( document ).ready( interfaceFunctions.init ); $( window ).resize(replaceDashboards); +window.addEventListener('hashchange', watchHashChange, false); //função no window que fixa o header das postagens function fixDiv() { var $cache = $('.postboard h2'); - if ($(window).scrollTop() > 26) - $cache.addClass( "fixed" ); + if ($(window).scrollTop() > 26) + $cache.addClass( "fixed" ); else $cache.removeClass( "fixed" ); } $(window).scroll(fixDiv); - From 0ea050571a06c42511f7c2eb5114d286d517bbbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Deparis?= Date: Thu, 16 Oct 2014 16:57:25 +0200 Subject: [PATCH 2/4] Generalize hash affectation --- js/interface_common.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/js/interface_common.js b/js/interface_common.js index dd7e725..5a5cfaf 100644 --- a/js/interface_common.js +++ b/js/interface_common.js @@ -133,6 +133,7 @@ function openProfileModalWithUsername(username) $(".tox-ctc").attr("title", polyglot.t("Copy to clipboard")); $(".bitmessage-ctc").attr("title", polyglot.t("Copy to clipboard")); + window.location.hash = '#profile?user=' + username; } function newHashtagModal(hashtag) { @@ -155,16 +156,7 @@ function openHashtagModal(e) var $this = $( this ); var hashtag = $this.text().substring(1).toLowerCase(); - - var hashtagModalClass = "hashtag-modal"; - openModal( hashtagModalClass ); - $( "."+hashtagModalClass ).attr("data-resource","hashtag"); - - var hashtagModalContent = newHashtagModal( hashtag ); - hashtagModalContent.appendTo("." +hashtagModalClass + " .modal-content"); - - //título do modal - $( "."+hashtagModalClass + " h3" ).text( "#" + hashtag ); + openHashtagModalFromSearch(hashtag); } function openHashtagModalFromSearch(hashtag) @@ -178,6 +170,7 @@ function openHashtagModalFromSearch(hashtag) //título do modal $( "."+hashtagModalClass + " h3" ).text( "#" + hashtag ); + window.location.hash = '#hashtag?hashtag=' + hashtag; } function updateHashtagModal(postboard,hashtag) { @@ -361,11 +354,16 @@ function openConversationModal(e) function watchHashChange(e){ - if(/user=(.+)/.test(window.location.hash)) + var hashdata = window.location.hash.match(/(hashtag|profile)\?(?:user|hashtag)=(.+)/); + + if (hashdata && hashdata[1] != undefined && hashdata[2] != undefined) { - var username = location.hash.match(/user=(.+)/); - if(username[1] != undefined) - openProfileModalWithUsername(username[1]); + if(hashdata[1] == 'profile') + { + openProfileModalWithUsername(hashdata[2]); + }else if (hashdata[2] == 'hashtag'){ + openHashtagModalFromSearch(username[2]); + } } } From 46fc58f69e16716649c84f3815aa3a61b3fa930f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Deparis?= Date: Fri, 17 Oct 2014 00:17:40 +0200 Subject: [PATCH 3/4] Fix hashtag watching bugs and add custom protocol handler support --- js/interface_common.js | 30 ++++++++++++++++++++++++------ js/interface_home.js | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/js/interface_common.js b/js/interface_common.js index 5a5cfaf..7ac983c 100644 --- a/js/interface_common.js +++ b/js/interface_common.js @@ -353,21 +353,39 @@ function openConversationModal(e) } -function watchHashChange(e){ - var hashdata = window.location.hash.match(/(hashtag|profile)\?(?:user|hashtag)=(.+)/); +function watchHashChange(e) +{ + var hashstring = window.location.hash + hashstring = decodeURIComponent(hashstring); + + var hashdata = hashstring.split(':'); + if (hashdata[0] != '#web+twister') { + hashdata = hashstring.match(/(hashtag|profile)\?(?:user|hashtag)=(.+)/); + } if (hashdata && hashdata[1] != undefined && hashdata[2] != undefined) { - if(hashdata[1] == 'profile') - { + if(hashdata[1] == 'profile') { openProfileModalWithUsername(hashdata[2]); - }else if (hashdata[2] == 'hashtag'){ - openHashtagModalFromSearch(username[2]); + }else if (hashdata[1] == 'hashtag') { + openHashtagModalFromSearch(hashdata[2]); } } } +function initHashWatching() +{ + // Register custom protocol handler + var local_twister_url = window.location.protocol + '//' + window.location.host + '/home.html#%s'; + window.navigator.registerProtocolHandler('web+twister', local_twister_url, 'Twister'); + + // Register hash spy and launch it once + window.addEventListener('hashchange', watchHashChange, false); + watchHashChange(null); +} + + // // Post actions, submit, count characters // -------------------------------------- diff --git a/js/interface_home.js b/js/interface_home.js index 5c2a2cb..4297f6e 100644 --- a/js/interface_home.js +++ b/js/interface_home.js @@ -52,6 +52,7 @@ var InterfaceFunctions = function() initInterfaceDirectMsg(); initUser(initHome); + initHashWatching(); }; function initHome(cbFunc, cbArg) { @@ -163,7 +164,6 @@ var InterfaceFunctions = function() var interfaceFunctions = new InterfaceFunctions; $( document ).ready( interfaceFunctions.init ); $( window ).resize(replaceDashboards); -window.addEventListener('hashchange', watchHashChange, false); //função no window que fixa o header das postagens function fixDiv() From 4efada7fd8eb7a2e46ee7ae2fc2547fe8f19cf33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Deparis?= Date: Tue, 21 Oct 2014 00:33:14 +0200 Subject: [PATCH 4/4] Fix error when browser doesn't know how to deal with window.navigator.registerProtocolHandler --- js/interface_common.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/interface_common.js b/js/interface_common.js index 7ac983c..8edbcba 100644 --- a/js/interface_common.js +++ b/js/interface_common.js @@ -377,8 +377,10 @@ function watchHashChange(e) function initHashWatching() { // Register custom protocol handler - var local_twister_url = window.location.protocol + '//' + window.location.host + '/home.html#%s'; - window.navigator.registerProtocolHandler('web+twister', local_twister_url, 'Twister'); + if (window.navigator && window.navigator.registerProtocolHandler){ + var local_twister_url = window.location.protocol + '//' + window.location.host + '/home.html#%s'; + window.navigator.registerProtocolHandler('web+twister', local_twister_url, 'Twister'); + } // Register hash spy and launch it once window.addEventListener('hashchange', watchHashChange, false);