diff --git a/app/assets/javascripts/app/helpers/direction_detector.js b/app/assets/javascripts/app/helpers/direction_detector.js new file mode 100644 index 000000000..ee1495718 --- /dev/null +++ b/app/assets/javascripts/app/helpers/direction_detector.js @@ -0,0 +1,52 @@ +(function() { + app.helpers.txtDirection = { + setCssFor: function(str, on_element) { + if( this.isRTL(str) ) { + $(on_element).css('direction', 'rtl'); + } else { + $(on_element).css('direction', 'ltr'); + } + }, + + classFor: function(str) { + if( this.isRTL(str) ) return 'rtl'; + return 'ltr'; + }, + + isRTL: function(str) { + if(typeof str !== "string" || str.length < 1) { + return false; + } + + var charCode = str.charCodeAt(0); + if(charCode >= 1536 && charCode <= 1791) // Sarabic, Persian, ... + return true; + + else if(charCode >= 65136 && charCode <= 65279) // Arabic present 1 + return true; + + else if(charCode >= 64336 && charCode <= 65023) // Arabic present 2 + return true; + + else if(charCode>=1424 && charCode<=1535) // Hebrew + return true; + + else if(charCode>=64256 && charCode<=64335) // Hebrew present + return true; + + else if(charCode>=1792 && charCode<=1871) // Syriac + return true; + + else if(charCode>=1920 && charCode<=1983) // Thaana + return true; + + else if(charCode>=1984 && charCode<=2047) // NKo + return true; + + else if(charCode>=11568 && charCode<=11647) // Tifinagh + return true; + + return false; + } + }; +})(); diff --git a/app/assets/javascripts/app/helpers/handlebars-helpers.js b/app/assets/javascripts/app/helpers/handlebars-helpers.js index ebb1e132b..3affa6cdc 100644 --- a/app/assets/javascripts/app/helpers/handlebars-helpers.js +++ b/app/assets/javascripts/app/helpers/handlebars-helpers.js @@ -2,6 +2,10 @@ Handlebars.registerHelper('t', function(scope, values) { return Diaspora.I18n.t(scope, values.hash) }); +Handlebars.registerHelper('txtDirClass', function(str) { + return app.helpers.txtDirection.classFor(str); +}); + Handlebars.registerHelper('imageUrl', function(path){ return ImagePaths.get(path); }); @@ -72,3 +76,7 @@ Handlebars.registerHelper('personImage', function(person, size, imageClass) { Handlebars.registerHelper('localTime', function(timestamp) { return new Date(timestamp).toLocaleString(); }); + +Handlebars.registerHelper('fmtText', function(text) { + return new Handlebars.SafeString(app.helpers.textFormatter(text, null)); +}); diff --git a/app/assets/javascripts/app/helpers/text_formatter.js b/app/assets/javascripts/app/helpers/text_formatter.js index 9f27029c6..6e15e2ed3 100644 --- a/app/assets/javascripts/app/helpers/text_formatter.js +++ b/app/assets/javascripts/app/helpers/text_formatter.js @@ -7,7 +7,7 @@ $(function() { (function(){ //make it so I take text and mentions rather than the modelapp.helpers.textFormatter( var textFormatter = function textFormatter(text, model) { - var mentions = model.get("mentioned_people"); + var mentions = model ? model.get("mentioned_people") : []; return textFormatter.mentionify( textFormatter.hashtagify( diff --git a/app/assets/javascripts/app/pages/profile.js b/app/assets/javascripts/app/pages/profile.js index 8c622ddcf..65bb87eb0 100644 --- a/app/assets/javascripts/app/pages/profile.js +++ b/app/assets/javascripts/app/pages/profile.js @@ -6,7 +6,7 @@ app.pages.Profile = app.views.Base.extend({ }, subviews: { - '#profile .badge': 'sidebarView', + '#profile': 'sidebarView', '.profile_header': 'headerView' }, @@ -15,6 +15,10 @@ app.pages.Profile = app.views.Base.extend({ initialize: function(opts) { if( app.hasPreload('person') ) this.model = new app.models.Person(app.parsePreload('person')); + if( app.hasPreload('photos') ) + this.photos = app.parsePreload('photos'); // we don't interact with it, so no model + if( app.hasPreload('contacts') ) + this.contacts = app.parsePreload('contacts'); // we don't interact with it, so no model this.model.on('change', this.render, this); @@ -26,7 +30,11 @@ app.pages.Profile = app.views.Base.extend({ }, sidebarView: function() { - return new app.views.ProfileSidebar({model: this.model}); + return new app.views.ProfileSidebar({ + model: this.model, + photos: this.photos, + contacts: this.contacts + }); }, headerView: function() { diff --git a/app/assets/javascripts/app/views/profile_sidebar_view.js b/app/assets/javascripts/app/views/profile_sidebar_view.js index 9190bd544..f45f18f33 100644 --- a/app/assets/javascripts/app/views/profile_sidebar_view.js +++ b/app/assets/javascripts/app/views/profile_sidebar_view.js @@ -2,13 +2,23 @@ app.views.ProfileSidebar = app.views.Base.extend({ templateName: 'profile_sidebar', + initialize: function(opts) { + this.photos = _.has(opts, 'photos') ? opts.photos : null; + this.contacts = _.has(opts, 'contacts') ? opts.contacts : null; + }, + presenter: function() { return _.extend({}, this.defaultPresenter(), { do_profile_btns: this._shouldDoProfileBtns(), + do_profile_info: this._shouldDoProfileInfo(), + do_photos: this._shouldDoPhotos(), + do_contacts: this._shouldDoContacts(), is_sharing: this.model.isSharing(), is_receiving: this.model.isReceiving(), is_mutual: this.model.isMutual(), - is_not_blocked: !this.model.isBlocked() + is_not_blocked: !this.model.isBlocked(), + photos: this.photos, + contacts: this.contacts }); }, @@ -16,6 +26,18 @@ app.views.ProfileSidebar = app.views.Base.extend({ return (app.currentUser.authenticated() && !this.model.get('is_own_profile')); }, + _shouldDoProfileInfo: function() { + return (this.model.isSharing() || this.model.get('is_own_profile')); + }, + + _shouldDoPhotos: function() { + return (this.photos && this.photos.items.length > 0); + }, + + _shouldDoContacts: function() { + return (this.contacts && this.contacts.items.length > 0); + }, + postRenderTemplate: function() { // UGLY (re-)attach the facebox this.$('a[rel*=facebox]').facebox(); diff --git a/app/assets/javascripts/widgets/direction-detector.js b/app/assets/javascripts/widgets/direction-detector.js index 8c886e6f3..2db21a1f7 100644 --- a/app/assets/javascripts/widgets/direction-detector.js +++ b/app/assets/javascripts/widgets/direction-detector.js @@ -11,47 +11,13 @@ this.subscribe("widget/ready", function() { self.updateBinds(); - + self.globalSubscribe("stream/scrolled", function() { self.updateBinds(); }); }); - this.isRTL = function(str) { - if(typeof str !== "string" || str.length < 1) { - return false; - } - - var charCode = str.charCodeAt(0); - if(charCode >= 1536 && charCode <= 1791) // Sarabic, Persian, ... - return true; - - else if(charCode >= 65136 && charCode <= 65279) // Arabic present 1 - return true; - - else if(charCode >= 64336 && charCode <= 65023) // Arabic present 2 - return true; - - else if(charCode>=1424 && charCode<=1535) // Hebrew - return true; - - else if(charCode>=64256 && charCode<=64335) // Hebrew present - return true; - - else if(charCode>=1792 && charCode<=1871) // Syriac - return true; - - else if(charCode>=1920 && charCode<=1983) // Thaana - return true; - - else if(charCode>=1984 && charCode<=2047) // NKo - return true; - - else if(charCode>=11568 && charCode<=11647) // Tifinagh - return true; - - return false; - }; + this.isRTL = app.helpers.txtDirection; this.updateBinds = function() { $.each(self.binds, function(index, bind) { @@ -71,14 +37,9 @@ this.updateDirection = function() { var textArea = $(this), - cleaned = textArea.val().replace(self.cleaner, "").replace(/^[ ]+/, ""); + cleaned = textArea.val().replace(self.cleaner, "").replace(/^[ ]+/, ""); - if(self.isRTL(cleaned)) { - textArea.css("direction", "rtl"); - } - else { - textArea.css("direction", "ltr"); - } + app.helpers.txtDirection.setCssFor(cleaned, textArea); }; }; diff --git a/app/assets/templates/profile_sidebar_tpl.jst.hbs b/app/assets/templates/profile_sidebar_tpl.jst.hbs index 4d0bba7cc..e65cfd9ae 100644 --- a/app/assets/templates/profile_sidebar_tpl.jst.hbs +++ b/app/assets/templates/profile_sidebar_tpl.jst.hbs @@ -1,5 +1,5 @@ -