0

我已将 Joomla 1.5 网站迁移到 Joomla 2.5。

Joomla 1.5 网站使用 Mootools 1.11。
Joomla 2.5 网站使用 Mootools 1.4.5。
该网站包含一个名为 annuary 的特定功能。

年鉴需要一些基于 Mootools 1.11 的 JavaScript 文件。
我需要将这些文件中的一些说明改编为 Mootools 1.4.5。
这些 JavaScript 文件之一是 Autocompleter.js。
这是 Autocompleter.js 的摘录:

var Autocompleter = {};

Autocompleter.Base = new Class({

    ...

    initialize: function(el, options) {

        this.setOptions(options);
        this.element = $(el);
        this.build();
        this.observer = new Observer(this.element, this.prefetch.bind(this), $merge({
        delay: 400
        }, this.options.observerOptions));
        this.value = this.observer.value;
        this.queryValue = null;
    },

    ...

});

Autocompleter.Base.implement(new Events);

Autocompleter.Base.implement(new Options);

Autocompleter.Local = Autocompleter.Base.extend({

    ...

    initialize: function(el, tokens, options) {

        this.parent(el, options);
        this.tokens = tokens;
        if (this.options.filterTokens) this.filterTokens = this.options.filterTokens.bind(this);
    },

    ...

});

我注意到以下与 annuary 相关的 JavaScript 指令不再按预期工作:

new Autocompleter.Local(idChamp, tabValues, {

    'delay': 100,
    'injectChoice': function(choice) {
        var el = new Element('li')
        .setHTML(this.markQueryValue(choice[0]))
        .adopt(new Element('span', {'class': 'example-info'}).setHTML(this.markQueryValue(choice[1])));
        el.inputValue = choice[0];
        this.addChoiceEvents(el).injectInside(this.choices);
    }
});

执行 Autocompleter.Base 的初始化函数。
但是 Autocompleter.Local 的初始化函数不是。
有人可以解释一下为什么吗?
我确信问题是由使用 Mootools 1.4.5 引起的。

4

1 回答 1

1

这让我回...

在 1.2.5 中,Class 进行了相当大的改进。你现在不是做原型然后调用实现/扩展,而是将这些作为修改器来做

Autocompleter.Base = new Class({

    Implements: [Options, Events],

    initialize: function(el, options) {

        this.setOptions(options);
        this.element = $(el);
        this.build();
        this.observer = new Observer(this.element, this.prefetch.bind(this), $merge({
        delay: 400
        }, this.options.observerOptions));
        this.value = this.observer.value;
        this.queryValue = null;
    },

    ...

});

Autocompleter.Local = new Class({
    Extends: Autocompleter.Base
});

您应该阅读一些关于从 1.11 迁移到 1.2.5 的指南/教程。并且 1.2.5 实际上现在不是一个好的版本,它已有 2.5 年的历史,并且由于https://bugzilla.mozilla.org/show_bug.cgi?id=789036目前在 FireFox 18 中被破坏

see some tutorial on writing classes now like http://fragged.org/tutorial-write-a-small-content-slider-class-in-mootools-and-extend-it_1321.html etc

于 2013-01-16T15:46:45.107 回答