Вход

Просмотр полной версии : Подписи картинок в Lytebox


SnikerS
09.08.2011, 12:02
Здравствуйте.

На стр. плагин u24 lytebox выводит серию фоток и подписи к ним:
LyteBox.prototype.updateDetails = function() {
var object = this.doc.getElementById('lbCaption');
var sTitle = (this.isSlideshow ? this.slideArray[this.activeSlide][1] : (this.isLyteframe ? this.frameArray[this.activeFrame][1] : this.imageArray[this.activeImage][1]));
object.style.display = '';
object.innerHTML = (sTitle == null ? '' : sTitle);
this.updateNav();
this.doc.getElementById('lbDetailsContainer').styl e.display = '';
object = this.doc.getElementById('lbNumberDisplay');
//Вот тут
if (this.isSlideshow && this.slideArray.length > 1) {
object.style.display = '';
object.innerHTML = "<b>" + document.title.slice(20, 56) + ":</b> изображение " + eval(this.activeSlide + 1) + " из " + this.slideArray.length;
this.doc.getElementById('lbNavDisplay').style.disp lay = (this.navType == 2 && this.showNavigation ? '' : 'none');
//И ещё раз тут
} else if (this.imageArray.length > 1 && !this.isLyteframe) {
object.style.display = '';
object.innerHTML = "<b>" + document.title.slice(20, 56) + ":</b> изображение " + eval(this.activeSlide + 1) + " из " + this.imageArray.length;
this.doc.getElementById('lbNavDisplay').style.disp lay = (this.navType == 2 ? '' : 'none');
} else if (this.frameArray.length > 1 && this.isLyteframe) {
object.style.display = '';
object.innerHTML = "Page " + eval(this.activeFrame + 1) + " of " + this.frameArray.length;
this.doc.getElementById('lbNavDisplay').style.disp lay = '';
} else {
this.doc.getElementById('lbNavDisplay').style.disp lay = 'none';
}
this.appear('lbDetailsContainer', (this.doAnimations ? 0 : 100));
};
Сейчас берётся document.title и обрезается для вставки назв. модели. Но на стр. есть h1.title с тем же названием. Подскажите как сделать обращение к h1?

melky
09.08.2011, 12:10
var h1 = document.querySelector("h1.title");


или


var a = document.getElementsByTagName("h1"), b = a.length, h1;
while(b--) if( ~a[b].className.indexOf("title") ){ h1 = a[b]; break;}

h1// OHO

SnikerS
09.08.2011, 12:35
вместо текста выводит [object HTMLHeadingElement] (и 1 и 2 прим.)

devote
09.08.2011, 12:47
лучше юзать второй пример, первый не всеми браузерами поддерживается.

alert( h1.className );
alert( h1.innerHTML );

SnikerS
09.08.2011, 13:01
Ну я сделал так:
LyteBox.prototype.updateDetails = function() {
var object = this.doc.getElementById('lbCaption');
var sTitle = (this.isSlideshow ? this.slideArray[this.activeSlide][1] : (this.isLyteframe ? this.frameArray[this.activeFrame][1] : this.imageArray[this.activeImage][1]));
object.style.display = '';
object.innerHTML = (sTitle == null ? '' : sTitle);
this.updateNav();
this.doc.getElementById('lbDetailsContainer').styl e.display = '';
object = this.doc.getElementById('lbNumberDisplay');
if (this.isSlideshow && this.slideArray.length > 1) {
object.style.display = '';
//Вставил
var a = document.getElementsByTagName("h1"), b = a.length, h1;
while(b--) if( ~a[b].className.indexOf("pos-title") ){ h1 = a[b]; break;}
object.innerHTML = "<b>" + h1 + ":</b> изображение " + eval(this.activeSlide + 1) + " из " + this.slideArray.length;
this.doc.getElementById('lbNavDisplay').style.disp lay = (this.navType == 2 && this.showNavigation ? '' : 'none');
} else if (this.imageArray.length > 1 && !this.isLyteframe) {
object.style.display = '';
//И тут
var a = document.getElementsByTagName("h1"), b = a.length, h1;
while(b--) if( ~a[b].className.indexOf("pos-title") ){ h1 = a[b]; break;}
object.innerHTML = "<b>" + h1 + ":</b> изображение " + eval(this.activeSlide + 1) + " из " + this.imageArray.length;
this.doc.getElementById('lbNavDisplay').style.disp lay = (this.navType == 2 ? '' : 'none');
} else if (this.frameArray.length > 1 && this.isLyteframe) {
object.style.display = '';
object.innerHTML = "Page " + eval(this.activeFrame + 1) + " of " + this.frameArray.length;
this.doc.getElementById('lbNavDisplay').style.disp lay = '';
} else {
this.doc.getElementById('lbNavDisplay').style.disp lay = 'none';
}
this.appear('lbDetailsContainer', (this.doAnimations ? 0 : 100));
};
И всё равно получаю: [object HTMLHeadingElement]: изображение 2 из 7
:cray:

devote
09.08.2011, 13:06
LyteBox.prototype.updateDetails = function() {
var object = this.doc.getElementById('lbCaption');
var sTitle = (this.isSlideshow ? this.slideArray[this.activeSlide][1] : (this.isLyteframe ? this.frameArray[this.activeFrame][1] : this.imageArray[this.activeImage][1]));
object.style.display = '';
object.innerHTML = (sTitle == null ? '' : sTitle);
this.updateNav();
this.doc.getElementById('lbDetailsContainer').styl e.display = '';
object = this.doc.getElementById('lbNumberDisplay');
if (this.isSlideshow && this.slideArray.length > 1) {
object.style.display = '';
//Вставил
var a = document.getElementsByTagName("h1"), b = a.length, h1;
while(b--) if( ~a[b].className.indexOf("pos-title") ){ h1 = a[b]; break;}
object.innerHTML = "<b>" + h1.innerHTML + ":</b> изображение " + eval(this.activeSlide + 1) + " из " + this.slideArray.length;
this.doc.getElementById('lbNavDisplay').style.disp lay = (this.navType == 2 && this.showNavigation ? '' : 'none');
} else if (this.imageArray.length > 1 && !this.isLyteframe) {
object.style.display = '';
//И тут
var a = document.getElementsByTagName("h1"), b = a.length, h1;
while(b--) if( ~a[b].className.indexOf("pos-title") ){ h1 = a[b]; break;}
object.innerHTML = "<b>" + h1.innerHTML + ":</b> изображение " + eval(this.activeSlide + 1) + " из " + this.imageArray.length;
this.doc.getElementById('lbNavDisplay').style.disp lay = (this.navType == 2 ? '' : 'none');
} else if (this.frameArray.length > 1 && this.isLyteframe) {
object.style.display = '';
object.innerHTML = "Page " + eval(this.activeFrame + 1) + " of " + this.frameArray.length;
this.doc.getElementById('lbNavDisplay').style.disp lay = '';
} else {
this.doc.getElementById('lbNavDisplay').style.disp lay = 'none';
}
this.appear('lbDetailsContainer', (this.doAnimations ? 0 : 100));
};

SnikerS
09.08.2011, 13:15
Вот же h1.innerHTML! Спасибо большое, помогло.