-4

私はしばらくこれで遊んでいます。

私はあなたが言うようにJavaScriptのウィザードではありません笑...

とにかく、正しく動作しながらコードを準拠させようとしています。

私はそれを準拠させることができますが、スクリプトは機能しなくなります。

とにかく、ここにコードスニペットがあります:

(function() {

    'use strict';

    tinymce.create('tinymce.plugins.Shortcodes', {

        init : function(ed, url) {
        },
        createControl : function(n, cm) {

            if(n=='Shortcodes'){
                var msb = cm.createListBox('Shortcodes', {
                     title : 'Shortcodes',
                     onselect : function(p) {

                        if(p == 'Accordions'){

                            content =  "[accordion_wrap]<br>[accordions title=\"Title Goes Here\"]This is where some content goes...[/accordions]<br>[accordions title=\"Title Goes Here\"]This is where some content goes...[/accordions]<br>[accordions title=\"Title Goes Here\"]This is where some content goes...[/accordions]<br>[/accordion_wrap]";

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Accordions With Icons'){

                            content =  "[accordion_wrap]<br>[accordions accordionicon=\"icon-globe\" title=\"Title Goes Here\"]This is where some content goes...[/accordions]<br>[accordions accordionicon=\"icon-globe\" title=\"Title Goes Here\"]This is where some content goes...[/accordions]<br>[accordions accordionicon=\"icon-globe\" title=\"Title Goes Here\"]This is where some content goes...[/accordions]<br>[/accordion_wrap]";

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Toggles'){

                            content = "[toggle_wrap]<br>[toggles title=\"Title Goes Here\"]This is where some content goes...[/toggles]<br>[toggles title=\"Title Goes Here\"]This is where some content goes...[/toggles]<br>[toggles title=\"Title Goes Here\"]This is where some content goes...[/toggles]<br>[/toggle_wrap]";

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Tabs'){

                            content =  "[tab_wrap]<br>[tab title=\"Title Goes Here\"]This is where some content goes...[/tab]<br>[tab title=\"Title Goes Here\"]This is where some content goes...[/tab]<br>[tab title=\"Title Goes Here\"]This is where some content goes...[/tab]<br>[/tab_wrap]";

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Tabs With Icons'){

                            content =  "[tab_wrap]<br>[tab icon=\"icon-globe\" title=\"Title Goes Here\"]This is where some content goes...[/tab]<br>[tab icon=\"icon-globe\" title=\"Title Goes Here\"]This is where some content goes...[/tab]<br>[tab icon=\"icon-globe\" title=\"Title Goes Here\"]This is where some content goes...[/tab]<br>[/tab_wrap]";

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Latest Portfolio Items'){

                            var portfoliohowmany = prompt("How many?", 4);

                            content =  '[latest_portfolio howmany="'+portfoliohowmany+'"]';

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Testimonial Slider'){

                            content =  "[testimonial_wrap]<br>[testimonial name=\"Testimonial Name Here\" company=\"Testimonial Company Name\" testimonial=\"Testimonial goes here\"]Image Goes Here...[/testimonial]<br>[testimonial name=\"Testimonial Name Here\" company=\"Testimonial Company Name\" testimonial=\"Testimonial goes here\"]Image Goes Here...[/testimonial]<br>[testimonial name=\"Testimonial Name Here\" company=\"Testimonial Company Name\" testimonial=\"Testimonial goes here\"]Image Goes Here...[/testimonial]<br>[/testimonial_wrap]";

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Pricing Tables Wrapper'){

                            selected = tinyMCE.activeEditor.selection.getContent();

                            if( selected ){

                            content =  '[pricingtable_wrap]'+selected+'[/pricingtable_wrap]';

                            }else{

                            content =  '[pricingtable_wrap][/pricingtable_wrap]';

                            }

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Pricing Tables'){

                            var sellingcolumns = prompt("How Many Columns (Choices are: 3 or 4)", 3);
                            var sellingtitle = prompt("Package", "");
                            var sellingprice = prompt("Price", "$29");
                            var sellingunderprice = prompt("Pre Month/Per Year", "Per Month");
                            var sellingbuttonname = prompt("Buttons Name", "More Info");
                            var sellingbuttonurl = prompt("Buttons Url", "#");
                            var sellingbuttoncolor = prompt("Button Colour... (Your Choices are: green, blue, lightblue, orange, red, black)", "green");
                            var sellingfeatured = prompt("Make This Featured (Type yes to make it featured)", "no");

                            selected = tinyMCE.activeEditor.selection.getContent();

                            if( selected ){
                                //If text is selected when button is clicked
                                //Wrap shortcode around it.
                                content =  '[pricing_table columns="'+sellingcolumns+'" title="'+sellingtitle+'" price="'+sellingprice+'" underprice="'+sellingunderprice+'" buttonname="'+sellingbuttonname+'" buttonurl="'+sellingbuttonurl+'" buttoncolor="'+sellingbuttoncolor+'" featured="'+sellingfeatured+'"]'+selected+'[/pricing_table]';
                            }else{
                                content =  '[pricing_table columns="'+sellingcolumns+'" title="'+sellingtitle+'" price="'+sellingprice+'" underprice="'+sellingunderprice+'" buttonname="'+sellingbuttonname+'" buttonurl="'+sellingbuttonurl+'" buttoncolor="'+sellingbuttoncolor+'" featured="'+sellingfeatured+'"][/pricing_table]';
                            }

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Team Member'){

                            var teamhowmany = prompt("How Many In A Row: (Choices: 3,4)", 3);
                            var teamname = prompt("Team Members Name", "");
                            var teamposition = prompt("Team Members Company Position (Example: Web Developer)", "");
                            var teamcontent = prompt("Very Small Paragraph About Team Member", "");
                            var teamtwitter = prompt("Twitter Url (Including http://) ... Leave blank to not show", "");
                            var teamdribbble = prompt("Dribbble Url (Including http://) ... Leave blank to not show", "");
                            var teamfacebook = prompt("Facebook Url (Including http://) ... Leave blank to not show", "");
                            var teamlinkedin = prompt("Linked In Url (Including http://) ... Leave blank to not show", "");
                            var teamgoogle = prompt("Google Plus Url (Including http://) ... Leave blank to not show", "");
                            var teaminstagram = prompt("Instagram Url (Including http://) ... Leave blank to not show", "");
                            var teamwindows = prompt("Windows Url (Including http://) ... Leave blank to not show", "");

                            selected = tinyMCE.activeEditor.selection.getContent();

                            if( selected ){

                            content =  '[teammember howmany="'+teamhowmany+'" name="'+teamname+'" position="'+teamposition+'" smallcontent="'+teamcontent+'" twitter="'+teamtwitter+'" dribbble="'+teamdribbble+'" facebook="'+teamfacebook+'" linkedin="'+teamlinkedin+'" google="'+teamgoogle+'" instagram="'+teaminstagram+'" windows="'+teamwindows+'"]'+selected+'[/teammember]';

                            } else {

                            content =  '[teammember howmany="'+teamhowmany+'" name="'+teamname+'" position="'+teamposition+'" smallcontent="'+teamcontent+'" twitter="'+teamtwitter+'" dribbble="'+teamdribbble+'" facebook="'+teamfacebook+'" linkedin="'+teamlinkedin+'" google="'+teamgoogle+'" instagram="'+teaminstagram+'" windows="'+teamwindows+'"][/teammember]';

                            }

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Clients Show'){

                            selected = tinyMCE.activeEditor.selection.getContent();

                            if( selected ){
                                //If text is selected when button is clicked
                                //Wrap shortcode around it.
                                content =  '[clients]'+selected+'[/clients]';

                            } else {

                                content =  '[clients][/clients]';

                            }

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Intro Boxes'){

                            var introboxeshowmany = prompt("How Many In A Row (Choices are: 3 or 4)", 4);
                            var introboxescolor = prompt("Box Colour (Choices are: inverse, blue, red, orane, yellow)... Inverse means sites colours!", "");
                            var introboxesicon = prompt("Icon Code, Please see Font Awesome Website For Each And Every Code", "");
                            var introboxestitle = prompt("Title", "");
                            var introboxescontent = prompt("Small Content", "");

                            selected = tinyMCE.activeEditor.selection.getContent();

                            if( selected ){
                                //If text is selected when button is clicked
                                //Wrap shortcode around it.
                                content =  '[intro_icons howmany="'+introboxeshowmany+'" color="'+introboxescolor+'" icon="'+introboxesicon+'" title="'+introboxestitle+'" content="'+introboxescontent+'"]';
                            }else{
                                content =  '[intro_icons howmany="'+introboxeshowmany+'" color="'+introboxescolor+'" icon="'+introboxesicon+'" title="'+introboxestitle+'" content="'+introboxescontent+'"]';
                            }

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Progessive Bars'){

                            var progressivename = prompt("Name Of Bar", "");
                            var progressivepercentage = prompt("Percentage)", 100);
                            var progressivecolor = prompt("Bar Colour (Choices are: inverse, blue, green, orange, red)... Inverse is sites colours!", "green");
                            var progressivestriped = prompt("Stiped Effect (Choices: yes, no)", "no");
                            var progressiveactive = prompt("Moving Stripes (Choices: yes, no)... If you want moving stipes, the striped effect needs a yes!", "no");

                            content =  '[progress_bar name="'+progressivename+'" percentage="'+progressivepercentage+'" color="'+progressivecolor+'" striped="'+progressivestriped+'" active="'+progressiveactive+'"]';

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Slider'){

                            content =  "[slider_wrap]<br>[slide]Image Goes Here...[/slide]<br>[slide]Image Goes Here...[/slide]<br>[slide]Image Goes Here...[/slide]<br>[/slider_wrap]";

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Featured Link'){

                            var featuredclass = prompt("Do you want to add another css class?", "");
                            var featuredbuttonurl = prompt("Button Url", "#");
                            var featuredbuttonname = prompt("Button Name", "Buy Now");
                            var featuredbackgroundcolor = prompt("Background Colour (Choices are: white, grey, light grey, dark grey, very dark grey, blue, theme color)", "blue");
                            var featuredcontent = prompt("Content", "");
                            var featuredbuttoncolor = prompt("Button Colour (Choices are: grey, blue, lightblue, green, orange, red, black)", "");

                            content =  '[featuredlink backgroundcolor='+featuredbackgroundcolor+' class="'+featuredclass+'" buttonurl="'+featuredbuttonurl+'" buttonname="'+featuredbuttonname+'" content="'+featuredcontent+'" buttoncolor="'+featuredbuttoncolor+'"]';

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Buttons'){

                            var buttonlinkurl = prompt("Button Url", "#");
                            var buttoncolor = prompt("Button Colour (Choices are: grey, blue, aqua, green, orange, red, black)... Inverse means sites colours!", "");
                            var buttonsize = prompt("Button Size (Choices are: mini, small, normal, large)", "");

                            selected = tinyMCE.activeEditor.selection.getContent();

                            if( selected ){
                                //If text is selected when button is clicked
                                //Wrap shortcode around it.
                                content =  '[button linkurl="'+buttonlinkurl+'" color="'+buttoncolor+'" size="'+buttonsize+'"]'+selected+'[/button]';
                            }else{
                                content =  '[button linkurl="'+buttonlinkurl+'" color="'+buttoncolor+'" size="'+buttonsize+'"][/button]';
                            }

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Icons'){

                            var iconicon = prompt("Icon Code, Please see Font Awesome Website For Each And Every Code", "");
                            var iconsize = prompt("Icon Size (Choices are: small, normal, large, supersize)", "normal");
                            var iconposition = prompt("Icon Position (Choices: left, right)", "left");

                            content =  '[icon icon="'+iconicon+'" size="'+iconsize+'" position="'+iconposition+'"]';

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Tool Tips'){

                            var tooltipposition = prompt("Position (Choices are: top, bottom, left, right)", "right");
                            var tooltiplink = prompt("Tool tip link url", "#");
                            var tooltiptooltip = prompt("Tooltip Content", "");

                            selected = tinyMCE.activeEditor.selection.getContent();

                            if( selected ){
                                //If text is selected when button is clicked
                                //Wrap shortcode around it.
                                content =  '[tooltip position="'+tooltipposition+'" link="'+tooltiplink+'" tooltip="'+tooltiptooltip+'"]'+selected+'[/tooltip]';
                            }else{
                                content =  '[tooltip position="'+tooltipposition+'" link="'+tooltiplink+'" tooltip="'+tooltiptooltip+'"][/tooltip]';
                            }

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Alerts'){

                            var alerttype = prompt("Type (Choices are: alert-success, alert-yellow, alert-info, alert-danger, alert-warning)", "");

                            selected = tinyMCE.activeEditor.selection.getContent();

                            if( selected ){
                                //If text is selected when button is clicked
                                //Wrap shortcode around it.
                                content =  '[alert type="'+alerttype+'"]'+selected+'[/alert]';
                            }else{
                                content =  '[alert type="'+alerttype+'"][/alert]';
                            }

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Labels'){

                            var labeltype = prompt("Type (Choices are: grey, green, orange, red, blue, black)", "");

                            selected = tinyMCE.activeEditor.selection.getContent();

                            if( selected ){
                                //If text is selected when button is clicked
                                //Wrap shortcode around it.
                                content =  '[label type="'+labeltype+'"]'+selected+'[/label]';
                            }else{
                                content =  '[label type="'+labeltype+'"][/label]';
                            }

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Badges'){

                            var badgetype = prompt("Type (Choices are: grey, green, orange, red, blue, black)", "");

                            selected = tinyMCE.activeEditor.selection.getContent();

                            if( selected ){
                                //If text is selected when button is clicked
                                //Wrap shortcode around it.
                                content =  '[badge type="'+badgetype+'"]'+selected+'[/badge]';
                            }else{
                                content =  '[badge type="'+badgetype+'"][/badge]';
                            }

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Text Highlight'){

                            var heightlightcolor = prompt("Text Colour (Please use the hex colour charts!)", "#ffffff");
                            var heightlightbgcolor = prompt("Background Colour (Please use the hex colour charts!)", "#4aaaa5");

                            selected = tinyMCE.activeEditor.selection.getContent();

                            if( selected ){
                                //If text is selected when button is clicked
                                //Wrap shortcode around it.
                                content =  '[highlight color="'+heightlightcolor+'" bgcolor="'+heightlightbgcolor+'"]'+selected+'[/highlight]';
                            }else{
                                content =  '[highlight color="'+heightlightcolor+'" bgcolor="'+heightlightbgcolor+'"][/highlight]';
                            }

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Small Text'){

                            selected = tinyMCE.activeEditor.selection.getContent();

                            if( selected ){
                                //If text is selected when button is clicked
                                //Wrap shortcode around it.
                                content =  '[small]'+selected+'[/small]';
                            }else{
                                content =  '[small][/small]';
                            }

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Code Tags'){

                            selected = tinyMCE.activeEditor.selection.getContent();

                            if( selected ){
                                //If text is selected when button is clicked
                                //Wrap shortcode around it.
                                content =  '[code]'+selected+'[/code]';
                            }else{
                                content =  '[code][/code]';
                            }

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Pre Tags'){

                            selected = tinyMCE.activeEditor.selection.getContent();

                            if( selected ){
                                //If text is selected when button is clicked
                                //Wrap shortcode around it.
                                content =  '[pre]'+selected+'[/pre]';
                            }else{
                                content =  '[pre][/pre]';
                            }

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'HR Tag'){

                            content =  '[hr]';

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                        if(p == 'Clear Fix'){

                            content =  '[clear]';

                            tinymce.execCommand('mceInsertContent', false, content);

                        } // end of shortcode

                     }
                });


                // Add some menu items
                var my_shortcodes = ['Accordions','Accordions With Icons','Toggles','Tabs','Tabs With Icons','Latest Portfolio Items','Testimonial Slider','Pricing Tables Wrapper','Pricing Tables','Team Member','Clients Show','Intro Boxes','Progessive Bars','Slider','Featured Link','Buttons','Icons','Tool Tips','Alerts','Labels','Badges','Text Highlight','Small Text','Code Tags','Pre Tags','HR Tag','Clear Fix'];

                for(var i in my_shortcodes){
                    msb.add(my_shortcodes[i],my_shortcodes[i]);
                }

                return msb;
            }
            return null;
        }


    });
    tinymce.PluginManager.add('Shortcodes', tinymce.plugins.Shortcodes);
})();

最大の問題は == が === であるように見えますが、これを行うと機能しなくなります。

もう1つの大きな問題は、コンテンツが定義されていないということですが、varをその前に置くと、コンテンツがすでに定義されていると表示されるため、勝てません笑。

ifステートメントを考慮しているとは思いません。

もう1つはスペーシングです。これはまったくばかげていると思います。読みやすいので、このようにコーディングします。スペーシングはコードに影響しないと常に言われていました。

とにかく、どんな助けも素晴らしいでしょう

ありがとう

4

2 に答える 2

1

onselectを使用した方法は次のとおりswitch-caseです。

onselect: function (p) {
    switch (p) {
    case 'Accordions':
        content = "[accordion_wrap]<br>[accordions title=\"Title Goes Here\"]This is where some content goes...[/accordions]<br>[accordions title=\"Title Goes Here\"]This is where some content goes...[/accordions]<br>[accordions title=\"Title Goes Here\"]This is where some content goes...[/accordions]<br>[/accordion_wrap]";
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Accordions With Icons':
        content = "[accordion_wrap]<br>[accordions accordionicon=\"icon-globe\" title=\"Title Goes Here\"]This is where some content goes...[/accordions]<br>[accordions accordionicon=\"icon-globe\" title=\"Title Goes Here\"]This is where some content goes...[/accordions]<br>[accordions accordionicon=\"icon-globe\" title=\"Title Goes Here\"]This is where some content goes...[/accordions]<br>[/accordion_wrap]";
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Toggles':
        content = "[toggle_wrap]<br>[toggles title=\"Title Goes Here\"]This is where some content goes...[/toggles]<br>[toggles title=\"Title Goes Here\"]This is where some content goes...[/toggles]<br>[toggles title=\"Title Goes Here\"]This is where some content goes...[/toggles]<br>[/toggle_wrap]";
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Tabs':
        content = "[tab_wrap]<br>[tab title=\"Title Goes Here\"]This is where some content goes...[/tab]<br>[tab title=\"Title Goes Here\"]This is where some content goes...[/tab]<br>[tab title=\"Title Goes Here\"]This is where some content goes...[/tab]<br>[/tab_wrap]";
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Tabs With Icons':
        content = "[tab_wrap]<br>[tab icon=\"icon-globe\" title=\"Title Goes Here\"]This is where some content goes...[/tab]<br>[tab icon=\"icon-globe\" title=\"Title Goes Here\"]This is where some content goes...[/tab]<br>[tab icon=\"icon-globe\" title=\"Title Goes Here\"]This is where some content goes...[/tab]<br>[/tab_wrap]";
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Latest Portfolio Items':
        var portfoliohowmany = prompt("How many?", 4);
        content = '[latest_portfolio howmany="' + portfoliohowmany + '"]';
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Testimonial Slider':
        content = "[testimonial_wrap]<br>[testimonial name=\"Testimonial Name Here\" company=\"Testimonial Company Name\" testimonial=\"Testimonial goes here\"]Image Goes Here...[/testimonial]<br>[testimonial name=\"Testimonial Name Here\" company=\"Testimonial Company Name\" testimonial=\"Testimonial goes here\"]Image Goes Here...[/testimonial]<br>[testimonial name=\"Testimonial Name Here\" company=\"Testimonial Company Name\" testimonial=\"Testimonial goes here\"]Image Goes Here...[/testimonial]<br>[/testimonial_wrap]";
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Pricing Tables Wrapper':
        selected = tinyMCE.activeEditor.selection.getContent();
        if (selected) {
            content = '[pricingtable_wrap]' + selected + '[/pricingtable_wrap]';
        } else {
            content = '[pricingtable_wrap][/pricingtable_wrap]';
        }
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Pricing Tables':
        var sellingcolumns = prompt("How Many Columns (Choices are: 3 or 4)", 3);
        var sellingtitle = prompt("Package", "");
        var sellingprice = prompt("Price", "$29");
        var sellingunderprice = prompt("Pre Month/Per Year", "Per Month");
        var sellingbuttonname = prompt("Buttons Name", "More Info");
        var sellingbuttonurl = prompt("Buttons Url", "#");
        var sellingbuttoncolor = prompt("Button Colour... (Your Choices are: green, blue, lightblue, orange, red, black)", "green");
        var sellingfeatured = prompt("Make This Featured (Type yes to make it featured)", "no");
        selected = tinyMCE.activeEditor.selection.getContent();
        if (selected) {
            //If text is selected when button is clicked
            //Wrap shortcode around it.
            content = '[pricing_table columns="' + sellingcolumns + '" title="' + sellingtitle + '" price="' + sellingprice + '" underprice="' + sellingunderprice + '" buttonname="' + sellingbuttonname + '" buttonurl="' + sellingbuttonurl + '" buttoncolor="' + sellingbuttoncolor + '" featured="' + sellingfeatured + '"]' + selected + '[/pricing_table]';
        } else {
            content = '[pricing_table columns="' + sellingcolumns + '" title="' + sellingtitle + '" price="' + sellingprice + '" underprice="' + sellingunderprice + '" buttonname="' + sellingbuttonname + '" buttonurl="' + sellingbuttonurl + '" buttoncolor="' + sellingbuttoncolor + '" featured="' + sellingfeatured + '"][/pricing_table]';
        }
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Team Member':
        var teamhowmany = prompt("How Many In A Row: (Choices: 3,4)", 3);
        var teamname = prompt("Team Members Name", "");
        var teamposition = prompt("Team Members Company Position (Example: Web Developer)", "");
        var teamcontent = prompt("Very Small Paragraph About Team Member", "");
        var teamtwitter = prompt("Twitter Url (Including http://) ... Leave blank to not show", "");
        var teamdribbble = prompt("Dribbble Url (Including http://) ... Leave blank to not show", "");
        var teamfacebook = prompt("Facebook Url (Including http://) ... Leave blank to not show", "");
        var teamlinkedin = prompt("Linked In Url (Including http://) ... Leave blank to not show", "");
        var teamgoogle = prompt("Google Plus Url (Including http://) ... Leave blank to not show", "");
        var teaminstagram = prompt("Instagram Url (Including http://) ... Leave blank to not show", "");
        var teamwindows = prompt("Windows Url (Including http://) ... Leave blank to not show", "");
        selected = tinyMCE.activeEditor.selection.getContent();
        if (selected) {
            content = '[teammember howmany="' + teamhowmany + '" name="' + teamname + '" position="' + teamposition + '" smallcontent="' + teamcontent + '" twitter="' + teamtwitter + '" dribbble="' + teamdribbble + '" facebook="' + teamfacebook + '" linkedin="' + teamlinkedin + '" google="' + teamgoogle + '" instagram="' + teaminstagram + '" windows="' + teamwindows + '"]' + selected + '[/teammember]';
        } else {
            content = '[teammember howmany="' + teamhowmany + '" name="' + teamname + '" position="' + teamposition + '" smallcontent="' + teamcontent + '" twitter="' + teamtwitter + '" dribbble="' + teamdribbble + '" facebook="' + teamfacebook + '" linkedin="' + teamlinkedin + '" google="' + teamgoogle + '" instagram="' + teaminstagram + '" windows="' + teamwindows + '"][/teammember]';
        }
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Clients Show':
        selected = tinyMCE.activeEditor.selection.getContent();
        if (selected) {
            //If text is selected when button is clicked
            //Wrap shortcode around it.
            content = '[clients]' + selected + '[/clients]';
        } else {
            content = '[clients][/clients]';
        }
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Intro Boxes':
        var introboxeshowmany = prompt("How Many In A Row (Choices are: 3 or 4)", 4);
        var introboxescolor = prompt("Box Colour (Choices are: inverse, blue, red, orane, yellow)... Inverse means sites colours!", "");
        var introboxesicon = prompt("Icon Code, Please see Font Awesome Website For Each And Every Code", "");
        var introboxestitle = prompt("Title", "");
        var introboxescontent = prompt("Small Content", "");
        selected = tinyMCE.activeEditor.selection.getContent();
        if (selected) {
            //If text is selected when button is clicked
            //Wrap shortcode around it.
            content = '[intro_icons howmany="' + introboxeshowmany + '" color="' + introboxescolor + '" icon="' + introboxesicon + '" title="' + introboxestitle + '" content="' + introboxescontent + '"]';
        } else {
            content = '[intro_icons howmany="' + introboxeshowmany + '" color="' + introboxescolor + '" icon="' + introboxesicon + '" title="' + introboxestitle + '" content="' + introboxescontent + '"]';
        }
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Progessive Bars':
        var progressivename = prompt("Name Of Bar", "");
        var progressivepercentage = prompt("Percentage)", 100);
        var progressivecolor = prompt("Bar Colour (Choices are: inverse, blue, green, orange, red)... Inverse is sites colours!", "green");
        var progressivestriped = prompt("Stiped Effect (Choices: yes, no)", "no");
        var progressiveactive = prompt("Moving Stripes (Choices: yes, no)... If you want moving stipes, the striped effect needs a yes!", "no");
        content = '[progress_bar name="' + progressivename + '" percentage="' + progressivepercentage + '" color="' + progressivecolor + '" striped="' + progressivestriped + '" active="' + progressiveactive + '"]';
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Slider':
        content = "[slider_wrap]<br>[slide]Image Goes Here...[/slide]<br>[slide]Image Goes Here...[/slide]<br>[slide]Image Goes Here...[/slide]<br>[/slider_wrap]";
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Featured Link':
        var featuredclass = prompt("Do you want to add another css class?", "");
        var featuredbuttonurl = prompt("Button Url", "#");
        var featuredbuttonname = prompt("Button Name", "Buy Now");
        var featuredbackgroundcolor = prompt("Background Colour (Choices are: white, grey, light grey, dark grey, very dark grey, blue, theme color)", "blue");
        var featuredcontent = prompt("Content", "");
        var featuredbuttoncolor = prompt("Button Colour (Choices are: grey, blue, lightblue, green, orange, red, black)", "");
        content = '[featuredlink backgroundcolor=' + featuredbackgroundcolor + ' class="' + featuredclass + '" buttonurl="' + featuredbuttonurl + '" buttonname="' + featuredbuttonname + '" content="' + featuredcontent + '" buttoncolor="' + featuredbuttoncolor + '"]';
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Buttons':
        var buttonlinkurl = prompt("Button Url", "#");
        var buttoncolor = prompt("Button Colour (Choices are: grey, blue, aqua, green, orange, red, black)... Inverse means sites colours!", "");
        var buttonsize = prompt("Button Size (Choices are: mini, small, normal, large)", "");
        selected = tinyMCE.activeEditor.selection.getContent();
        if (selected) {
            //If text is selected when button is clicked
            //Wrap shortcode around it.
            content = '[button linkurl="' + buttonlinkurl + '" color="' + buttoncolor + '" size="' + buttonsize + '"]' + selected + '[/button]';
        } else {
            content = '[button linkurl="' + buttonlinkurl + '" color="' + buttoncolor + '" size="' + buttonsize + '"][/button]';
        }
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Icons':
        var iconicon = prompt("Icon Code, Please see Font Awesome Website For Each And Every Code", "");
        var iconsize = prompt("Icon Size (Choices are: small, normal, large, supersize)", "normal");
        var iconposition = prompt("Icon Position (Choices: left, right)", "left");
        content = '[icon icon="' + iconicon + '" size="' + iconsize + '" position="' + iconposition + '"]';
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Tool Tips':
        var tooltipposition = prompt("Position (Choices are: top, bottom, left, right)", "right");
        var tooltiplink = prompt("Tool tip link url", "#");
        var tooltiptooltip = prompt("Tooltip Content", "");
        selected = tinyMCE.activeEditor.selection.getContent();
        if (selected) {
            //If text is selected when button is clicked
            //Wrap shortcode around it.
            content = '[tooltip position="' + tooltipposition + '" link="' + tooltiplink + '" tooltip="' + tooltiptooltip + '"]' + selected + '[/tooltip]';
        } else {
            content = '[tooltip position="' + tooltipposition + '" link="' + tooltiplink + '" tooltip="' + tooltiptooltip + '"][/tooltip]';
        }
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Alerts':
        var alerttype = prompt("Type (Choices are: alert-success, alert-yellow, alert-info, alert-danger, alert-warning)", "");
        selected = tinyMCE.activeEditor.selection.getContent();
        if (selected) {
            //If text is selected when button is clicked
            //Wrap shortcode around it.
            content = '[alert type="' + alerttype + '"]' + selected + '[/alert]';
        } else {
            content = '[alert type="' + alerttype + '"][/alert]';
        }
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Labels':
        var labeltype = prompt("Type (Choices are: grey, green, orange, red, blue, black)", "");
        selected = tinyMCE.activeEditor.selection.getContent();
        if (selected) {
            //If text is selected when button is clicked
            //Wrap shortcode around it.
            content = '[label type="' + labeltype + '"]' + selected + '[/label]';
        } else {
            content = '[label type="' + labeltype + '"][/label]';
        }
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Badges':
        var badgetype = prompt("Type (Choices are: grey, green, orange, red, blue, black)", "");
        selected = tinyMCE.activeEditor.selection.getContent();
        if (selected) {
            //If text is selected when button is clicked
            //Wrap shortcode around it.
            content = '[badge type="' + badgetype + '"]' + selected + '[/badge]';
        } else {
            content = '[badge type="' + badgetype + '"][/badge]';
        }
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Text Highlight':
        var heightlightcolor = prompt("Text Colour (Please use the hex colour charts!)", "#ffffff");
        var heightlightbgcolor = prompt("Background Colour (Please use the hex colour charts!)", "#4aaaa5");
        selected = tinyMCE.activeEditor.selection.getContent();
        if (selected) {
            //If text is selected when button is clicked
            //Wrap shortcode around it.
            content = '[highlight color="' + heightlightcolor + '" bgcolor="' + heightlightbgcolor + '"]' + selected + '[/highlight]';
        } else {
            content = '[highlight color="' + heightlightcolor + '" bgcolor="' + heightlightbgcolor + '"][/highlight]';
        }
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Small Text':
        selected = tinyMCE.activeEditor.selection.getContent();
        if (selected) {
            //If text is selected when button is clicked
            //Wrap shortcode around it.
            content = '[small]' + selected + '[/small]';
        } else {
            content = '[small][/small]';
        }
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Code Tags':
        selected = tinyMCE.activeEditor.selection.getContent();
        if (selected) {
            //If text is selected when button is clicked
            //Wrap shortcode around it.
            content = '[code]' + selected + '[/code]';
        } else {
            content = '[code][/code]';
        }
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Pre Tags':
        selected = tinyMCE.activeEditor.selection.getContent();
        if (selected) {
            //If text is selected when button is clicked
            //Wrap shortcode around it.
            content = '[pre]' + selected + '[/pre]';
        } else {
            content = '[pre][/pre]';
        }
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'HR Tag':
        content = '[hr]';
        tinymce.execCommand('mceInsertContent', false, content);
        break;

    case 'Clear Fix':
        content = '[clear]';
        tinymce.execCommand('mceInsertContent', false, content);
        break;
    }
}

また、不要な空行をすべて取り除きました。いくつかの構文エラーが含まれている可能性がありますが、これらは自分で修正できると確信しています。

==基本的には if ステートメントと同じですが、変数名や===演算子を毎回見る必要はありません。

于 2013-08-06T08:47:42.820 に答える
1

開始するには:

今後の参考のために、質問の仕方に関する Stack Overflow のガイドラインに従ってください。私たち (コミュニティ) が立ち往生している、または人々を困難にしたいからではなく、それが私たちがあなたを助けるのに役立つからです. 私たちにたくさんのコードを投げつけてから、基本的に「これを修正してください!」と言います。医者のオフィスに足を踏み入れて「私を元気にしてください!」という言葉に似ています。

詳細がなければ、私たちはあなたを助けることはできません。あなたの問題を説明する際に、より具体的であるほど良いでしょう.

そうは言っても、私の頭の中では、JavaScript を学んでいるだけの人には明らかではないため、対処したい 1 つの特定の根本的な問題に焦点を合わせようとしました。

最大の問題は == が === であるように見えますが、これを行うと機能しなくなります。

私は創造的な自由を取り、それを次のように翻訳しました:

'===' に変更すると、等価チェックが失敗するのはなぜですか?

JavaScript では、等価性/同一性を判断するための 2 つの異なる比較演算子があります。

それらは恒等演算子です。

===

および等値演算子:

==

彼らは非常に異なった振る舞いをします。等値演算子は型強制を行うため、興味深く望ましくない動作を引き起こす可能性がありますが、恒等演算子はオペランドが前提条件として同じ型である必要があります。これがよく発生する場所の 1 つは、文字列と文字列オブジェクトの場合です。

異なるバックグラウンドを持っている、またはプログラミングに慣れていない場合、次のように考えるかもしれません。

var a = "foo";
var b = new String("foo");

同じことをします。いいえ。Javascript ではありません。aはタイプstringbあり、タイプobjectです。なぜこれが重要なのですか?次の例を検討してください。

a == "foo"  // 1. evaluates to true
a === "foo" // 2. evaluates to true because `a` and "foo" are both of the same type "string"
b == "foo" //  2. evaluates to true because b is coerced from type Object to type String and its value is then compared to "foo" 
b === "foo"// 3. evaluates to false because b is type Object and "foo" is type String

つまり、Javascript で平等を判断することと同一性を判断することは、2 つのまったく異なるものであるということです。ただし、一般的には===、等価性と同一性の両方をチェックするために使用することに固執する必要があります。これにより、コードの信頼性と予測可能性が向上し、一般的には良い考えです。==を使用して何かを true にしたいが、 を使用して falseにしたい場合はほとんどありません===。特にあなたがちょうど学んでいるとき。

私は のバックグラウンドがないので、パラメーターがtinymce何を持っているのか、またはそれ以外のことはわかりませんが、暗闇の中での 1 つの刺し傷は、実際には であるため、等値演算子 を使用して比較すると、強制され、次のように評価されます。 true に変更すると、もちろん失敗します。あなたへの私の最初の提案は、すべての等値演算子を恒等演算子に変更し、実際にそうである場合、の値を返す を呼び出してみることです。したがって、次のようなものです。typepnpString Object==========.valueOf()pStringString Object

if(p.valueOf() === 'Accordions'){

    content =  "[accordion_wrap]<br>[accordions title=\"Title Goes Here\"]This is where some content goes...[/accordions]<br>[accordions title=\"Title Goes Here\"]This is where some content goes...[/accordions]<br>[accordions title=\"Title Goes Here\"]This is where some content goes...[/accordions]<br>[/accordion_wrap]";

    tinymce.execCommand('mceInsertContent', false, content);

 } // end of shortcode

==しかし、 vs .についてさらに自分自身を教育する必要があります===

これについては、SO に関する多くの質問が寄せられています。また、インターウェブ上には、私がこれまで以上に詳細に説明している多くのリソースがあります。そのため、いくつかをここにリストします。

JavaScript の比較で使用する等号演算子 (== vs ===) は重要ですか?

比較演算子 - JavaScript | MDN

等値演算子 (JavaScript: The Definitive Guide, 4th Edition)

さて、この件に関して私があなたのために持っているのはそれだけです。お役に立てば幸いです。ここに書いたことに関して質問がある場合は、お気軽にコメントしてください。必ず返信いたします。

ハッピーコーディング!

于 2013-08-06T08:53:12.973 に答える