src/cm/media/js/client/c_layout.js
author Simon Descarpentries <sid@sopinspace.com>
Mon, 21 Oct 2013 16:37:07 +0200
changeset 553 bf26fb47a14c
parent 532 0bad3613f59d
child 562 92e8e5aaacde
permissions -rw-r--r--
To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout. So the automated scrolling operations in c_sync.js must be adjustable to the right part to scroll. Also, if a comment have to be shown outside of the current viewport, we scroll the correct part to that viewport and then set the comment top Y offset to juste what it needs to avoid the "Add comment" button after scrolling operation. If not in Safari mobile, we add an offset here to avoid comment to display under the "Add comment" button.

// globals used: gConf, gPrefs

Layout = function() {
}

Layout.prototype = {
  init : function () {
  },
  
  isInFrame : function () {
    return (!CY.Lang.isUndefined(parent) && parent.location != location && CY.Lang.isFunction(parent.f_getFrameFilterData)); ;
  },
  
  isInComentSite : function () {
    var ret = false;
    try { 
      if (!CY.Lang.isUndefined(sv_site_url) && !CY.Lang.isUndefined(parent) && !CY.Lang.isUndefined(parent.parent)) {
        var parentParentLocation = new String(parent.parent.location) ;
        // TODO warn server
        //CY.log(parentParentLocation) ;
        ret = (parentParentLocation.indexOf(sv_site_url) == 0);
      }
    }
    catch (e) {
      ret=false;
      //CY.log("error thrown while trying to access parent.parent.location") ;
    }
    //CY.log("inComentSite returned : " + ret) ;
    return ret ;
  },
  
  sliderValToPx : function (val) {
    var winWidth = CY.DOM.winWidth() ;
    if (this.isInFrame()) 
       winWidth = parent.$(parent).width() ;    
    var theta = val / 100 ;
    theta = Math.min(theta, gConf['sliderFixedMin']) ;
    theta = Math.max(theta, gConf['sliderFixedMax']) ;
    var colWidth = theta * winWidth ;
    return Math.floor(colWidth) ;
  },

  getTopICommentsWidth : function() {
    return this.getTopICommentsWidthFromWidth(this.sliderValToPx(gPrefs.get('layout','comments_col_width'))) ;
  },
  
  getTopICommentsWidthFromWidth : function(val) {
    var ret = val - ( 2 * gConf['iCommentThreadPadding']) ; // PhA said : a threaded discussion with a depth of 2 still shoudn't hide the text 20100317
    return ret - 7;
  },
  
  setLeftColumnWidth : function (colWidth) {
    CY.get('#contentcolumn').setStyle('marginLeft', colWidth + 'px');
    CY.get('#leftcolumn').setStyle('width', colWidth + 'px');
  },
  parentInterfaceUnfreeze : function() {
    if (this.isInFrame())
      parent.f_interfaceUnfreeze() ;
  }
  
}