Передать ссылку на объект а не объект возникновения события
Доброго времени суток,
Подскажите пожалуйста, суть того, что хочу получить: есть объект (пример ниже) по достижению финального состояния идет замена кнопок на кнопку цепляется событие (метод: replaceButtons), а при нажатии на кнопку я хочу изменить свойства самого объекта, а не кнопки (метод resetAll), но на событие онклик this это кнопка а хочется чтобы это был объект с его последним состоянием. Как передать в метод ссылку на объект? Зараннее благодарен за советы. з.ы. это все еще очень очень сырое, та и опыта у меня совсем не много в js так что прошу ногами сильно не пинать, но за любую критику буду благодарен. var BLZ = BLZ||{}; BLZ.progressBar = { startPoint: -400, currentPos: -400, endPoint: 0, currentStage: 0, finalStageAchieved: false,//think about this flag. possibility send from php or count on user side isInnerProgressible: false, innerStateProgress: 0, animateDelay: 500, init: function (elem, stages) { var w = document.getElementById('progressPopBlock'); w.style.visibility = 'visible'; this.movDiv = document.getElementById(elem); this.movDiv.style.left = this.startPoint + 'px'; this.stages = stages; this.progressPerStage = Math.abs(this.startPoint) / this.stages; }, progress: function (achRes) { var achievedStage = achRes; if (achievedStage === 'addStage') {//test case alert(this.currentStage); //alert(this.stages); if (this.currentStage === this.stages) { this.finalStageAchieved = true;//emulate final stage achievement } achievedStage = this.currentStage + 1; } if (this.finalStageAchieved === true) { this.replaceButtons(); } if (achievedStage - this.currentStage > 0) { this.stageProgress = true; this.currentStage = achievedStage; this.isInnerProgressible = false; this.startPoint = this.currentPos; this.currentPos = this.currentPos + this.progressPerStage; } if(this.isInnerProgressible === true && this.stageProgress === false) { this.innerStateProgress = 'something'; } if (this.stageProgress === true && this.finalStageAchieved !== true) { this.stageProgress = false; this.drawProgress(this.startPoint, this.currentPos); } }, calculateInnerProgressParams: function() { }, drawProgress: function(start, finish) { var _startPoint, _endPoint, _movEl; _startPoint = start; _endPoint = finish; _movEl = document.getElementById('movingElem'); setTimeout(function() { _startPoint = _startPoint + 2; _movEl.style.left = _startPoint + 'px'; if (_startPoint < _endPoint) { setTimeout(arguments.callee, 50); } }, 0); }, replaceButtons: function() { var _e, _fc, _nFr, _btn, _spanElem; _e = document.getElementById('pBut'); _fc = _e.firstChild; while(_fc) { _e.removeChild(_fc); _fc = _e.firstChild; } _nFr = document.createDocumentFragment(); _btn = document.createElement('input') _btn.setAttribute('class', 'submit'); _btn.setAttribute('type', 'button'); _btn.setAttribute('value', 'OK'); _btn.onclick = this.resetAll; _spanElem = document.createElement('span'); _spanElem.setAttribute('class', 'button okey'); _spanElem.appendChild(_btn); _nFr.appendChild(_spanElem); _e.appendChild(_nFr); }, resetAll: function() { this.startPoint = -400; this.currentPos = -400; this.endPoint = 0; this.currentStage = 0; this.finalStageAchieved = false; document.getElementById('movingElem').style.left = this.startPoint + 'px'; document.getElementById('progressPopBlock').style.visibility = 'hidden'; } }; |
Часовой пояс GMT +3, время: 16:47. |