# insert-php/2.3.10/admin/assets/js/tinymce4.4.js

Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts, version 2.3.10. 71 lines.

- Page: https://pluginprobe.com/plugins/insert-php/2.3.10/code/admin/assets/js/tinymce4.4.js
- Raw: https://pluginprobe.com/plugins/insert-php/2.3.10/raw/admin/assets/js/tinymce4.4.js
- Modified: 2021-02-15T09:44:04+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/insert-php/2.3.10/code/admin/assets/js/tinymce4.4.js#L10-L20`.

```javascript
(function($) {
	$(document).on('tinymce-editor-setup', function(event, editor) {

		if( void 0 === wbcr_inp_shortcode_snippets ) {
			console.log('Unknown error.');
			return;
		}

		if( $.isEmptyObject(wbcr_inp_shortcode_snippets) ) {
			return;
		}

		editor.settings.toolbar1 += ',wbcr_insert_php_button';

		var menu = [];

		$.each(wbcr_inp_shortcode_snippets, function(index, item) {
			menu.push({
				text: item.title,
				value: item.id,
				onclick: function() {
					var content = "";
					var snippet_type = item.type;
					var snippet_name = item.name;
					var selected_content = editor.selection.getContent();

					for( var tag in item ) {
						if( !item.hasOwnProperty(tag) ) {
							continue;
						}

						if( 'type' === tag ) {
							snippet_type = item[tag];
						} else if( 'name' === tag ) {
							snippet_name = item[tag];
						} else if( tag.indexOf('snippet_tags') === -1 ) {
							if( !('' !== selected_content && 'content' === tag) ) {
								content += ' ' + tag + '="' + item[tag] + '"';
							}
						}
					}

					if( '' === snippet_name || undefined === snippet_name ) {
						if( 'universal' === snippet_type ) {
							snippet_name = "wbcr_snippet";
						} else {
							snippet_name = "wbcr_" + snippet_type + "_snippet";
						}
					}

					if( '' === selected_content ) {
						editor.selection.setContent('[' + snippet_name + content + ']');
					} else {
						editor.selection.setContent(
							'[' + snippet_name + content + ']' +
							selected_content +
							'[/' + snippet_name + ']');
					}
				}
			});
		});

		editor.addButton('wbcr_insert_php_button', {
			title: wbcr_inp_tinymce_snippets_button_title,
			type: 'menubutton',
			icon: 'icon wbcr-inp-shortcode-icon',
			menu: menu
		});

	});
})(jQuery);
```
