Функция JS прерывается - предок имеет значение nullJavascript

Форум по Javascript
Ответить
Anonymous
 Функция JS прерывается - предок имеет значение null

Сообщение Anonymous »

Пытаюсь устранить неполадки, почему эта функция не работает, но мой JS очень и очень заржавел. Он предназначен для сворачивания/развертывания разделов на странице и работает при раскрытии, но затем перестает работать при повторном нажатии и должен свернуть этот раздел.
[img]https:// i.sstatic.net/gsAKe9Iz.png[/img]

Вот вызывающая функция (скриншот):
Изображение

Вот вызывающая функция (полный код):

Код: Выделить всё

NS.run_expansion = function(categorynode) {
var categorychildren = categorynode.one(SELECTORS.CONTENTNODE),
self = this,
ancestor = categorynode.ancestor(SELECTORS.COURSECATEGORYTREE);

// Add our animation to the categorychildren.
this.add_animation(categorychildren);

// If we already have the class, remove it before showing otherwise we perform the
// animation whilst the node is hidden.
if (categorynode.hasClass(CSS.SECTIONCOLLAPSED)) {
// To avoid a jump effect, we need to set the height of the children to 0 here before removing the SECTIONCOLLAPSED class.
categorychildren.setStyle('height', '0');
categorynode.removeClass(CSS.SECTIONCOLLAPSED);
categorynode.setAttribute('aria-expanded', 'true');
categorychildren.fx.set('reverse', false);
} else {
categorychildren.fx.set('reverse', true);
categorychildren.fx.once('end', function(e, categorynode) {
categorynode.addClass(CSS.SECTIONCOLLAPSED);
categorynode.setAttribute('aria-expanded', 'false');
}, this, categorynode);
}

categorychildren.fx.once('end', function(e, categorychildren) {
// Remove the styles that the animation has set.
categorychildren.setStyles({
height: '',
opacity: ''
});

// To avoid memory gobbling, remove the animation. It will be added back if called again.
this.destroy();
self.update_collapsible_actions(ancestor);
}, categorychildren.fx, categorychildren);

// Now that everything has been set up, run the animation.
categorychildren.fx.run();
};
И тут происходит сбой (скриншот):
[img]https://i.sstatic. net/0bJyirYC.png[/img]

Неверная функция (полный код):

Код: Выделить всё

NS.update_collapsible_actions = function(ancestor) {
var foundmaximisedchildren = false,
// Grab the anchor for the collapseexpand all link.
**togglelink = ancestor.one(SELECTORS.COLLAPSEEXPAND);**

if (!togglelink) {
// We should always have a togglelink but ensure.
return;
}

// Search for any visibly expanded children.
ancestor.all(SELECTORS.CATEGORYWITHMAXIMISEDLOADEDCHILDREN).each(function(n) {
// If we can find any collapsed ancestors, skip.
if (n.ancestor(SELECTORS.CATEGORYWITHCOLLAPSEDLOADEDCHILDREN)) {
return false;
}
foundmaximisedchildren = true;
return true;
});

if (foundmaximisedchildren) {
// At least one maximised child found. Show the collapseall.
togglelink.setHTML(M.util.get_string('collapseall', 'moodle'))
.addClass(CSS.COLLAPSEALL)
.removeClass(CSS.DISABLED);
} else {
// No maximised children found but there are collapsed children. Show the expandall.
togglelink.setHTML(M.util.get_string('expandall', 'moodle'))
.removeClass(CSS.COLLAPSEALL)
.removeClass(CSS.DISABLED);
}
};
Я погуглил это и немного поигрался с кодом, но ничего не добился. Как я уже сказал, мой JS очень заржавел, так что будьте добры :)

Подробнее здесь: https://stackoverflow.com/questions/793 ... or-is-null
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»