Linggo, Marso 13, 2011

And the ball rolls on (Edit content view - Finish!)

Weew, after 8.5 hours, by the grace and mercy of Our Lord, the Edit content view function is finished. Got delayed on one variable passing and the way <img> doesn't center automatically like <div> background-image (which I presumed both acted the same way. *shame on me.) which lead me to backtrack and check the code and variable, sure enough it was passing right, so had to read up on <img>. The thing was it seems <img> can be a real pain to center automatically, had to re-write a whole function and re-think the algorithm on some steps. Any who take a gander on the result below.


The image on the top is the same image at the center of the gallery, it auto resizes and center when clicked.


added  an additional 61 lines of codes to project and here they are.

function editContent(itemIndex){
   var iIndex = itemIndex;
   var currentPageIndex = checkWhichButtonOn("");
   var imgPath = searchArray[currentPageIndex][itemIndex][1];
   var editImgBox = new Image();
   editImgBox.src = imgPath;
   if (editImgBox.complete) {
    var imgOrientation = checkImgOrientation(editImgBox);
    var imgNewDimension = imgScaler(imgOrientation, editImgBox.height, editImgBox.width);
    var editImgBoxConfiguration = new Array(4);
    editImgBoxConfiguration = configureEditImgBox(imgNewDimension,imgOrientation);
    displayEditBox(editImgBoxConfiguration[0], editImgBoxConfiguration[1], editImgBoxConfiguration[2], editImgBoxConfiguration[3], editImgBox.src);
   }
   else{
    editContentTimer = setTimeout("editContent(\'"+iIndex+"\')",1200);
    imgBoxPathTransferTimer = true;
   }
  }
  
  function imgScaler(imgOrientation, imgHeight, imgWidth){
   if (imgBoxPathTransferTimer) {
    setTimeout(editContentTimer);
   }
   
   if (imgOrientation == "orientationPortrait"){
    var computeScaledDimension = Math.ceil((192*imgHeight)/imgWidth);
   }
   
   if (imgOrientation == "orientationLandscape"){
    var computeScaledDimension = Math.ceil((192*imgWidth)/imgHeight);
   } 
   
   return computeScaledDimension;          
  }
  
  function configureEditImgBox(imgNewDimension,imgOrientation){
   var editImgBoxConfiguration = new Array(4);
   
   if (imgOrientation=="orientationPortrait"){
    var imgWidth = "192";
    var imgHeight = imgNewDimension;
    var imgLeft = 0;
    var imgTop = -1*((imgHeight/2)-96);
    
   }else{
    var imgWidth = imgNewDimension;
    var imgHeight = "192";
    var imgLeft = -1*((imgWidth/2)-96);
    var imgTop = 0;
   }
   editImgBoxConfiguration = [imgWidth,imgHeight,imgLeft,imgTop]
   return editImgBoxConfiguration;
  }
  
  function displayEditBox(imgWidth,imgHeight,imgLeft,imgTop,src){
   var editImgBox = document.getElementById('imgBox');
   editImgBox.style.width = imgWidth+"px";
   editImgBox.style.height = imgHeight+"px";
   editImgBox.style.left = imgLeft+"px";
   editImgBox.style.top = imgTop+"px";
   editImgBox.src = src;
  }


Ill be doing the pure edit-area functions, 1st would be the information display function and then the content-edit functions.

Walang komento:

Mag-post ng isang Komento