我已经玩了一段时间了。
我不是一个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);
})();
最大的问题看起来像==应该是===但是当我这样做时,他们就会停止工作。
另一个大问题是内容没有定义,但是当我把var放在它之前,它然后说明内容已经定义,所以不能赢得大声笑。
我不认为它会考虑if语句。
另一个是间距,我发现这完全是愚蠢的,我这样编码因为它很容易让我阅读,我总是被告知间距不会影响代码。
无论如何,任何帮助都会很棒
由于
答案 0 :(得分:1)
以下是使用onselect
的<{1}}方法:
switch-case
我也摆脱了所有那些不必要的空行。它可能包含一些语法错误,但我相信你可以自己修复它们。
这不应该破坏您的代码,它基本上与您的if语句相同,但不需要每次都看到变量名称和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;
}
}
或==
运算符。
答案 1 :(得分:1)
开始:
为了将来参考,请务必遵循question asking上的Stack Overflow指南。不是因为我们(社区)被困,或者想让人们变得困难,而是因为它帮助我们帮助你。向我们扔了一堆代码然后基本上说“修复这个!”就像走进医生办公室说“让我整个人!”
如果没有详细信息,我们就无法帮助您,在描述您的问题时,您可以更加具体。
话虽如此,在我的脑海中,我试图削减责任并专注于我要解决的一个具体的潜在问题,因为对于刚学习javascript的人来说,这并不明显:
最大的问题看起来像==应该是===但是当我这样做时,他们就会停止工作。
我采取了一些创造性的自由并将其转化为:
当我将其更改为“===”时,为什么我的平等检查失败?
在javascript中,有两个不同的比较运算符用于确定相等/身份。
他们是身份运营商:
===
和等号运算符:
==
他们表现得非常不同。等于运算符确实输入强制,这可能导致有趣的,非期望的行为,而身份运算符要求操作数与先决条件具有相同的类型。这可能发生很多的地方是字符串与字符串对象。
来自不同的背景,或者不熟悉编程,你可能会认为:
var a = "foo";
var b = new String("foo");
做同样的事情。不。不是在Javascript中。 a
的类型为string
,b
的类型为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中的平等和确定标识是两个完全不同的事情。但是,一般来说,你应该坚持使用===
来检查平等和安全性。身份。它使您的代码更可靠和可预测,通常只是一个好主意。如果您希望使用==
使某些内容成为现实,则使用===
时可能会出现错误。特别是当你刚刚学习的时候。
我没有tinymce
的背景,因此我不知道type
参数p
或n
或其他任何内容的p
,
但是在黑暗中进行的一次尝试就是String Object
实际上是==
所以当你使用等于运算符===
进行比较时,它会被强制并评估为true,当你将其更改为识别运算符==
,它当然失败了。我向您提出的第一个建议是将所有等号运算符===
更改为标识运算符.valueOf()
,并尝试在p
上调用String
,这将返回String 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
的值,如果确实如此。所以,像这样:
==
但你真的应该在===
与{{1}}进一步教育自己。
关于这一点有很多问题,有很多关于互联网的资源可以比我更好地详细解释这一点,所以我只想在这里列出一些:
Does it matter which equals operator (== vs ===) I use in JavaScript comparisons?
Comparison Operators - JavaScript | MDN
Equality Operators (JavaScript: The Definitive Guide, 4th Edition)
嗯,这就是我在这件事上所得到的一切。我希望它有所帮助。如果您对我在此处所写的内容有任何疑问,请随时发表评论&amp;我一定会回复你。
快乐编码!