0

cleditorを使用して、次のコードでカスタム ボタンを設定しようとしています。

(function($) {
    $.cleditor.buttons.link_species = {
        name: "link_species",
        image: "fish.gif",
        title: "Species Link",
        command: "inserthtml",
        popupName: "link_species",
        popupClass: "cleditorPrompt",
        popupContent: "Genus: <input type='text' size='15'> Species: <input type='text' size='15'><br />Remove italics? <input type='checkbox' value='remove'>&nbsp;<input type='button' value='Ok' />",
        buttonClick: link_speciesClick
    };

  // Handle the hello button click event
  function link_speciesClick(e, data) {
    // Wire up the submit button click event
    $(data.popup).children(":button")
      .unbind("click")
      .bind("click", function(e) {

        // Get the editor
        var editor = data.editor;

        var $text = $(data.popup).find(":text"),
          genus = $text[0].value,
          species = $text[1].value;

        var slug = genus + '-' + species;
        slug = htmlEntities(slug);

        var link = '/dev/species/' + slug + '/';
        var rel = link + '?preview=true';

        var display = firstUpper(genus) + ' ' + species;

        // Get the entered name
        var html = '<a href="' + link + '" rel="' + rel + '">' + display + '</a>';

        if ( !$(data.popup).find(":checkbox").is(':checked') ) {
            html = '<em>' + html + '</em>';
        }

        // Insert some html into the document
        editor.execCommand(data.command, html, null, data.button);

        // Hide the popup and set focus back to the editor
        editor.hidePopups();
        editor.focus();
      });
  }
})(jQuery);

これは WordPress の Web サイトで、ディレクトリ構造は次のようなものです。

/wp-content/plugins/sf-species-profile/cleditor

そこにはすべての cleditor ファイルconfig.jsがあり、このファイルは上記のコードが保存されている場所です。

images24*24fish.gifファイルを含むフォルダーもあります。

何らかの理由で、このコードを実行すると、次のエラーが発生します。

[firefox]
a is undefined
<<myurl>>/wp-content/plugins/sf-species-profiles/cleditor/jquery.cleditor.min.js?ver=3.3.1
Line 17

[chrome]
Uncaught TypeError: Cannot read property 'length' of undefined

「image」引数を image:"" に変更すると、「B」と同じ画像が表示されますが、プラグインはエラーなく動作します。

誰が何が間違っているのか考えていますか?

4

1 に答える 1

1

最小化されていないバージョンを使用すると、デバッグが容易になります。ここから入手できます:http://premiumsoftware.net/cleditor/zip

最小化されたコードの17行目で終わるコードに長さの呼び出しを含む2つの関数があります。色を処理する関数hex(s)の1つ。もう1つはimagePath関数です。

function imagesPath() {
  var cssFile = "jquery.cleditor.css",
  href = $("link[href$='" + cssFile +"']").attr("href");
  return href.substr(0, href.length - cssFile.length) + "images/";
}

レンダリングされたHTMLに「<linkrel="stylesheet" type = "text / css" href = "path / to / jquery.cleditor.css" /」のような行が含まれていない場合、使用しているタイプのエラーがスローされる可能性があります。 >"。(その場合、Hrefは未定義になります。)

ワードプレス統合の場合、ワードプレスプラグインバージョンのcleditorを使用するとセットアップが簡単になる場合があります。

于 2012-03-11T16:52:16.410 に答える