הרשם שאלות ותשובות רשימת חברים לוח שנה הודעות מהיום

חזור   הוסטס - פורום אחסון האתרים הגדול בישראל > עיצוב גראפי, תכנות על כל שפותיו וקידום ושיווק אתרים > פורום תיכנות

   
|!|

השב
 
כלים לאשכול תצורת הצגה
ישן 24-05-07, 17:10   # 1
tnadav
חבר בקהילה
 
מיני פרופיל
תאריך הצטרפות: Oct 2006
הודעות: 216

tnadav לא מחובר  

[JS] בעיה עם this בתוך מחלקה

וואי.. הרבה זמן לא הייתי פה.. בכל מקרה יש לי בעיה עם מחלקה שאני עושה.. הנה המחלקה המלאה:
קוד:
var i = 0;
var floatWindow = function(weight, height, windowTitle)
{
    //reset all values
    i++;
    this.weight       =  weight;
    this.height       =  height;
    this.windowId     = "window_"+i;
    this.windowTopId  = "window_top_"+i;
    this.windowTitle  =  windowTitle;
    this.startClient  =  new Array();
    //Making a design of window
    var windowContent = "<div class='window_top' id='"+this.windowTopId+"'>"+windowTitle;
        //coming soon...
            //<img src='images/top_left.gif' align='left'>
            //<img src='images/top_center.gif' class='topCenterImage'>
            //<<div class='top_buttons'>
                //<img class='minimizeButton' src='images/minimize.gif'>
                //<img class='closeButton' src='images/close.gif'>
        
                //<img src='images/top_right.gif'>
            //</div>
        windowContent += "</div>";
        windowContent += "<div class='windowMiddle'>";
            windowContent += "<div class='windowContent'>";
                //Starting window content...
                windowContent += "Testing..Testing..123";
                //End of window content...
            windowContent += "</div>";
        windowContent += "</div>";
        windowContent += "<div class='window_bottom'>";
            //<img class="resizeImage" src="images/bottom_right.gif">
        windowContent += "</div>";
    //Creating the element...
    var window        = document.createElement("div");
    window.id         = this.windowId;
    window.className  = 'window';
    window.innerHTML  = windowContent;
    document.body.appendChild(window);
    this.windowObj    = document.getElementById(this.windowId);
    this.windowTopObj = document.getElementById(this.windowTopId);
    //end of creating element...
    //other functions...
    function findX()
      {
        obj = this.windowObj;
        var curleft = 0;
        if(obj.offsetParent)
            while(1) 
            {
                  curleft += obj.offsetLeft;
                      if(!obj.offsetParent)
                        break;
                  obj = obj.offsetParent;
            }
        else if(obj.x)
            curleft += obj.x;
        
        return curleft;
    }    
    function findY()
      {
        obj = this.windowObj;
        var curtop = 0;
        if(obj.offsetParent)
            while(1)
            {
                  curtop += obj.offsetTop;
                  if(!obj.offsetParent)
                    break;
                  obj = obj.offsetParent;
            }
        else if(obj.y)
            curtop += obj.y;
        return curtop;
      }
    function updatePos(e)
    {
        if(document.all)
            e = event;
        //-------------------------
        this.windowObj.style.left  = this.startClient[x] + e.clientX - this.findX  + 'px';
        this.windowObj.style.top   = this.startClient[y] + e.clientY - this.findY  + 'px';
    }
    function stopMove()
    {
        this.onmousemove  = null;
        this.onmouseup    = null;
    }
    function initMove(e)
    {
        if(document.all)
            e = event;
            
        this.startClient['x']          = e.clientX;
        this.startClient['y']          = e.clientY;
        this.windowTopObj.onmousemove  = function () {this.updatePos()};
        this.windowTopObj.onmouseup    = this.stopMove;
    }
    // Making evant
    this.windowTopObj.onmousedown = function () {this.initMove()};
}  
הבעיה היא בשורה
קוד:
 this.windowTopObj.onmousedown = function () {this.initMove()};  
בשורה הזאת, אני רוצה ש- this יהיה מיוחס למחלקה, אבל במקרה הזה, this מיוחס ל-
קוד:
this.windowTopObj
שלו, מן הסתם, אין פונקצית initMove.. מה אפשר לעשות במקום ש- this יהיה מיוחס למחלקה?
__________________
"אני לא מעצב גרפי... אני לא פלאשר תותח... בטח שלא מנכ"ל של חברת בניית אתרים, כעיקרון אסור לי להיות מועסק.. אבל אני... מתכנת ב-PHP , וגם, לא ממש מציעה.." (יצא לי מוזר משהו...חח)
  Reply With Quote
ישן 25-05-07, 15:40   # 2
tnadav
חבר בקהילה
 
מיני פרופיל
תאריך הצטרפות: Oct 2006
הודעות: 216

tnadav לא מחובר  

פתרתי את הבעיה בדרך קצת מגעילה..
PHP קוד:
obj this;
this.windowTopObj.onmousedown      = function () {obj.initMove()}; 
יש הצאות לפיתרון יותר טוב או אלגנטי?
בכל מקרה עכשיו יש לי עוד בעיה שאותה אני יפתח באשכול נפרד
__________________
"אני לא מעצב גרפי... אני לא פלאשר תותח... בטח שלא מנכ"ל של חברת בניית אתרים, כעיקרון אסור לי להיות מועסק.. אבל אני... מתכנת ב-PHP , וגם, לא ממש מציעה.." (יצא לי מוזר משהו...חח)
  Reply With Quote
השב

חברים פעילים הצופים באשכול זה: 1 (0 חברים ו- 1 אורחים)
 


חוקי פירסום
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is מופעל
סמיילים הם מופעל
[IMG] קוד מופעל
קוד HTML מכובה

קפיצה לפורום


כל הזמנים הם GMT +2. הזמן כעת הוא 22:19.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ