MyBB Community Forums

Full Version: Bandcamp MyCode with single button for both tracks & albums
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I noticed that there were no Bandcamp MyCodes online, so here ya go. Hopefully it'll be useful to someone.

This works exactly like my SoundCloud MyCode; it will add a single MyCode button above the editor to embed either single tracks or full albums from Bandcamp.

First, you'll need to create the MyCodes:

Single Track

Title: Bandcamp Track

Short Description: Embed a single track from Bandcamp

Regular Expression:

\[bandcamp\](.*?)\[/bandcamp\]

Replacement:

<iframe width="400" height="100" style="position: relative; display: block; width: 400px; height: 100px;" src="http://bandcamp.com/EmbeddedPlayer/v=2/track=$1/size=venti/bgcol=ffffff/linkcol=4285BB/" allowtransparency="true" frameborder="0"></iframe>

Album

Title: Bandcamp Album

Short Description: Embed an album from Bandcamp

Regular Expression:

\[bcalbum\](.*?)\[/bcalbum\]

Replacement:

<iframe width="300" height="410" style="position: relative; display: block; width: 300px; height: 410px;" src="http://bandcamp.com/EmbeddedPlayer/v=2/album=$1/size=grande3/bgcol=ffffff/linkcol=4285BB/" allowtransparency="true" frameborder="0"></iframe>

--------

Next, upload this icon:

[Image: bandcamp.png]

... or your own 23 x 22px Bandcamp icon to jscripts/editor_themes/YOUR_EDITOR_THEME/images

Then add the following to editor.js:

				{type: 'button', name: 'bandcamp', insert: 'bandcamp', image: 'bandcamp.png', title: 'Bandcamp'}

			case "bandcamp":
				this.insertBandcamp();
				break;

	insertBandcamp: function()
	{
		type = prompt("Would you like to post a single track or a full album? Please choose either track or album.", "");
		type = type.replace(/^\s+/, '').replace(/\s+$/, '');
		type = type.toLowerCase();

		while(type != "" && type != null && type != "track" && type != "album")
		{
			type = prompt("Sorry, that wasn't a valid player type. Please try again. Valid choices are track or album.", "");
			type = type.replace(/^\s+/, '').replace(/\s+$/, '');
			type = type.toLowerCase();
		}

		if(type == "" || type == null)
		{
			return false;
		}
		
		if(type == "track")
		{
			id = prompt("Please enter the Bandcamp Track ID.\n\nYou can find this by clicking Share / Embed on a track page; select the Wordpress.com shortcode option, and copy only the ID number.", "Example: bandcamp track=*COPY THIS NUMBER*");
			id = id.replace(/^\s+/, '').replace(/\s+$/, '');

			if(id == "" || id == null || id == "Example: bandcamp track=*COPY THIS NUMBER*")
			{
				return false;
			} else {
				this.performInsert("[bandcamp]"+id+"[/bandcamp]", "", true);
			}

		} else {
			id = prompt("Please enter the Bandcamp Album ID.\n\nYou can find this by clicking Share / Embed on an album page; select the Wordpress.com shortcode option, and copy only the ID number.", "Example: bandcamp album=*COPY THIS NUMBER*");
			id = id.replace(/^\s+/, '').replace(/\s+$/, '');

			if(id == "" || id == null || id == "Example: bandcamp album=*COPY THIS NUMBER*")
			{
				return false;
			} else {
				this.performInsert("[bcalbum]"+id+"[/bcalbum]", "", true);
			}
		}
	},

Use this tutorial to work out where those bits of code go.

After these edits, users can click the Bandcamp icon, answer a prompt about which type of player they're embedding, and paste the ID taken from the WordPress.com shortcode section of the share dialog to post either version of the Bandcamp player.

Edit: Updated last editor.js edit to make "track or album" prompt case insensitive, avoid adding tags when user enters nothing but whitespace and avoid adding tags with "null" as value when user cancels prompt on iOS.
I can't get this to work in 1.8.4.
No surprise, but it doesn't work on 1.8.10 either. Has anyone got this working?
Hasn't worked since the 1.8 upgrade. Ditto for the playlist.