コード例 #1
0
function enqueueOnepagerAdminAssets()
{
    $asset = onepager()->asset();
    if (function_exists('wp_enqueue_media')) {
        wp_enqueue_media();
        js_wp_editor();
    }
    $asset->style('tx-bootstrap', asset('assets/css/bootstrap.css'));
    $asset->style('tx-animatecss', asset('assets/css/animate.css'));
    $asset->style('tx-fontawesome', asset('assets/css/font-awesome.css'));
    $asset->style('tx-colorpicker', asset("assets/css/bootstrap-colorpicker.css"));
    $asset->style('lithium-ui', asset('assets/css/lithium-builder.css'));
    $asset->script('tx-bootstrap', asset('assets/js/bootstrap.js'), ['jquery']);
    $asset->script('tx-bootstrap-select', asset('assets/js/bootstrap-select.js'), ['jquery']);
    $asset->script('tx-iconselector', asset('assets/js/icon-selector-bootstrap.js'), ['jquery']);
    $asset->script('tx-colorpicker', asset('assets/js/bootstrap-colorpicker.js'), ['jquery']);
    $asset->script('tx-toastr', asset('assets/js/toastr.js'), ['jquery']);
    $asset->script('admin-bundle', asset('assets/optionspanel.bundle.js'), ['jquery']);
    $asset->enqueue();
}
コード例 #2
0
/**
 * Modules Reorder and Tabs functionality
 */
function qi_modules_ui_setup_scripts()
{
    js_wp_editor();
    ?>
	<script type="text/javascript">

		// Add & build tabs menu
		jQuery('#mod-type-metabox').after('<ul class="qi-tabs-menu clear"><li class="module-style-link"><a href="#mod-metabox">Module Style</a></li></ul>');
		
		var moduleSelector = jQuery('#quadro_mod_type'),
			selType = moduleSelector.val();

		if ( selType != 'canvas' ) {
			
			var data = {
				action: 'quadro_ajax_mod_metabox',
				post_id: jQuery('#post_ID').val(),
				type: selType,
			};
			
			jQuery.post(ajaxurl, data, function(response) {
				if ( response != -1 ) {
					// Bring fields
					jQuery('#mod-container-metabox .inside').html(response);
			        // Call Scripts of Fields Function
					jQuery(this).callFieldsScripts();
				}
			});

			jQuery('.qi-tabs-menu').prepend('<li class="current module-options-link"><a href="#mod-container-metabox">Module Options</a></li>');
		
		}
		
		// Move WP editor after Module Type select
		jQuery('#mod-type-metabox').after( jQuery('#postdiv, #postdivrich') );
		
		// Create Tabs Container
		jQuery('.qi-tabs-menu').after('<div class="qi-tabs-container"></div>');
		
		// Add all relevant modules inside tabs container
		jQuery('.qi-tabs-container').append( jQuery('#mod-metabox') );
		// jQuery('.qi-tabs-container').append( jQuery('.postbox[id*=qi-type-metabox]') );
		jQuery('.qi-tabs-container').append( jQuery('#mod-container-metabox') );
		
		// Enable Tabs Functionality
		jQuery('.qi-tabs-menu').on( 'click', 'a', function(event) {
			event.preventDefault();
			jQuery(this).parent().addClass("current");
			jQuery(this).parent().siblings().removeClass("current");
			var tab = jQuery(this).attr("href");
			jQuery('.qi-tabs-container .postbox').not(tab).hide().addClass('tab-hidden');
			jQuery(tab).fadeIn().removeClass('tab-hidden');
		});

		moduleSelector.change(function(){
			var selType = moduleSelector.val();

			if ( selType != 'canvas' ) {
				
				var data = {
					action: 'quadro_ajax_mod_metabox',
					post_id: jQuery('#post_ID').val(),
					type: selType,
				};
				
				jQuery.post(ajaxurl, data, function(response) {
					if ( response != -1 ) {
						jQuery('#mod-container-metabox .inside').html(response);
						// Add link to tabs menu
						if ( !jQuery('.qi-tabs-menu li.module-options-link').length ) {
							jQuery('.qi-tabs-menu').prepend('<li class="module-options-link"><a href="#mod-container-metabox">Module Options</a></li>');
							// Keep Module Style as current if previously selected
							if ( !jQuery('.qi-tabs-menu li.module-style-link').hasClass('current') ) {
								jQuery('.qi-tabs-menu li.module-options-link').addClass('current');
							}			
						} 
						// Call Scripts of Fields Function
						jQuery(this).callFieldsScripts();
					}
				});
			
			} else {
				jQuery('#mod-container-metabox .inside').html('');
				jQuery('.qi-tabs-menu li.module-options-link').remove();
				jQuery('.qi-tabs-menu li.module-style-link').addClass('current');
			}
			
		});

		// Function to call scripts on newly loaded fields
		jQuery.fn.callFieldsScripts = function() {
			// Handles selection boxes appearing when chosing selection methods
			// First, hide the selectors by default and show already chosen selector
			var allSelectors = jQuery('.qcustom-selector, .qtax-selector, .qformat-selector').parents('tr');
			jQuery('select[id*=_method]').each(function(){
				jQuery(this).parents('tr').siblings('tr').find('.qcustom-selector, .qtax-selector, .qformat-selector').parents('tr').hide();
				jQuery(this).parents('tr').siblings('tr').find('.q' + jQuery(this).val() + '-selector').parents('tr').fadeIn();
			})

			// Enable Editor custom field
			// if ( jQuery('textarea.qi-editor').length ) jQuery('textarea.qi-editor').wp_editor();
			if ( jQuery('textarea.qi-editor').length ) {
				tinyMCE.init({
					selector: 'textarea.qi-editor',
					mode: 'specific_textareas',
					content_css: '<?php 
    echo includes_url();
    ?>
' + 'js/tinymce/skins/wordpress/wp-content.css',
					menubar : false,
					plugins: "textcolor",
					toolbar1: "styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | outdent indent | undo redo",
				});
			}
			
			// Enable Repeatable Editors
			tinyMCE.init({
				selector: 'textarea.repeatable-editor',
				mode: 'specific_textareas',
				content_css: '<?php 
    echo includes_url();
    ?>
' + 'js/tinymce/skins/wordpress/wp-content.css',
				menubar : false,
				plugins: "textcolor",
				toolbar1: "styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | undo redo",
			});


			jQuery('.custom_repeatable').sortable({
				opacity: 0.6,
				revert: true,
				cursor: 'move',
				handle: '.sort',
				start: function(event, ui) {
					sortablePrevChecked = ui.item.find('input:checked').val();
					// Disarm editors in this field before sorting
					if ( ui.item.find('.wp-editor-area').length ) tinyMCE.execCommand( 'mceRemoveEditor', false, ui.item.find('.wp-editor-area').attr('id') );
				},
				update: function(event, ui) {
					// Renumber Array indexes when re ordered
					jQuery(this).data().uiSortable.currentItem.parent().find('.fields-set').each(function(rowIndex){
						jQuery(this).find('input[name], textarea[name], select[name]').each(function(){
							var selectName;
							selectName = jQuery(this).attr('name');
							selectName = selectName.replace(/\[[0-9]+\]/g, '['+rowIndex+']');
							// Modify Names
							jQuery(this).attr('name',selectName);
							// Modify Editors' IDs too
							if ( jQuery(this).hasClass('wp-editor-area') ) jQuery(this).attr('id',selectName);
						});
					});
					ui.item.find(':radio[value='+sortablePrevChecked+']').prop("checked", true);
				},
				stop: function(e,ui) {},
			});

			// Enables Posts Sorting in Posts Select fields
			jQuery('.sel-posts-container').sortable({
				opacity: 0.6,
				revert: true,
				cursor: 'move',
				handle: '.li-mover',
				update: function (e, ui) {
					// Grabs current li's data IDs and puts them into the hidden field
					var $postsIds = '';
					jQuery(this).find('li').each(function(){
						$postsIds += jQuery(this).data('id') + ', ';
					});
					jQuery(this).next().val($postsIds);
				}
			});
			
		}
		
		/*
		 *	JavaScript Wordpress Editor
		 *	Author: 		Ante Primorac
		 *	Author URI: 	http://anteprimorac.from.hr
		 *	Version: 		1.1
		 *	License: (on PHP version of file)
		 */
		;(function(a,r){a.fn.wp_editor=function(c){a(this).is("textarea")||console.warn("Element must be a textarea");"undefined"!=typeof tinyMCEPreInit&&"undefined"!=typeof QTags&&"undefined"!=typeof adminscripts_localized||console.warn("js_wp_editor( $settings ); must be loaded");if(!a(this).is("textarea")||"undefined"==typeof tinyMCEPreInit||"undefined"==typeof QTags||"undefined"==typeof adminscripts_localized)return this;var e={mode:"html",mceInit:{theme:"modern",skin:"lightgray",language:"en",formats:{alignleft:[{selector:"p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li",styles:{textAlign:"left"},deep:!1,remove:"none"},{selector:"img,table,dl.wp-caption",classes:["alignleft"],deep:!1,remove:"none"}],aligncenter:[{selector:"p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li",styles:{textAlign:"center"},deep:!1,remove:"none"},{selector:"img,table,dl.wp-caption",classes:["aligncenter"],deep:!1,remove:"none"}],alignright:[{selector:"p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li",styles:{textAlign:"right"},deep:!1,remove:"none"},{selector:"img,table,dl.wp-caption",classes:["alignright"],deep:!1,remove:"none"}],strikethrough:{inline:"del",deep:!0,split:!0}},relative_urls:!1,remove_script_host:!1,convert_urls:!1,browser_spellcheck:!0,fix_list_elements:!0,entities:"38,amp,60,lt,62,gt",entity_encoding:"raw",keep_styles:!1,paste_webkit_styles:"font-weight font-style color",preview_styles:"font-family font-size font-weight font-style text-decoration text-transform",wpeditimage_disable_captions:!1,wpeditimage_html5_captions:!1,plugins:"charmap,hr,media,paste,tabfocus,textcolor,fullscreen,wordpress,wpeditimage,wpgallery,wplink,wpdialogs,wpview,image",content_css:"<?php 
    echo includes_url();
    ?>
css/dashicons.css?ver=3.9,<?php 
    echo includes_url();
    ?>
js/mediaelement/mediaelementplayer.min.css?ver=3.9,<?php 
    echo includes_url();
    ?>
js/mediaelement/wp-mediaelement.css?ver=3.9,<?php 
    echo includes_url();
    ?>
js/tinymce/skins/wordpress/wp-content.css?ver=3.9",selector:"#apid",resize:"vertical",menubar:!1,wpautop:!0,indent:!1,toolbar1:"bold,italic,strikethrough,bullist,numlist,blockquote,hr,alignleft,aligncenter,alignright,link,unlink,wp_more,spellchecker,fullscreen,wp_adv",toolbar2:"formatselect,underline,alignjustify,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help",toolbar3:"",toolbar4:"",tabfocus_elements:":prev,:next",body_class:"apid"}},n=RegExp("apid","g");tinyMCEPreInit.mceInit.apid&&(e.mceInit=tinyMCEPreInit.mceInit.apid);c=a.extend(!0,e,c);return this.each(function(){if(a(this).is("textarea")){var b=a(this).attr("id");a.each(c.mceInit,function(d,k){"string"==a.type(k)&&(c.mceInit[d]=k.replace(n,b))});c.mode="tmce"==c.mode?"tmce":"html";tinyMCEPreInit.mceInit[b]=c.mceInit;a(this).addClass("wp-editor-area").show();var d=this;a(this).closest(".wp-editor-wrap").length&&(d=a(this).closest(".wp-editor-wrap").parent(),a(this).closest(".wp-editor-wrap").before(a(this).clone()),a(this).closest(".wp-editor-wrap").remove(),d=d.find('textarea[id="'+b+'"]'));var f=a('<div id="wp-'+b+'-wrap" class="wp-core-ui wp-editor-wrap '+c.mode+'-active" />'),g=a('<div id="wp-'+b+'-editor-tools" class="wp-editor-tools hide-if-no-js" />'),h=a('<div class="wp-editor-tabs" />'),e=a('<a id="'+b+'-html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);">Text</a>'),p=a('<a id="'+b+'-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);">Visual</a>'),l=a('<div id="wp-'+b+'-media-buttons" class="wp-media-buttons" />'),q=a('<a href="#" id="insert-media-button" class="button insert-media add_media" data-editor="'+b+'" title="Add Media"><span class="wp-media-buttons-icon"></span> Add Media</a>'),m=a('<div id="wp-'+b+'-editor-container" class="wp-editor-container" />');q.appendTo(l);l.appendTo(g);e.appendTo(h);p.appendTo(h);h.appendTo(g);g.appendTo(f);m.appendTo(f);m.append(a(d).clone().addClass("wp-editor-area"));a(d).before('<link rel="stylesheet" id="editor-buttons-css" href="'+adminscripts_localized.includes_url+'css/editor.css" type="text/css" media="all">');a(d).before(f);a(d).remove();new QTags(b);QTags._buttonsInit();switchEditors.go(b,c.mode);a(f).on("click",".insert-media",function(b){var c=a(b.currentTarget),d=c.data("editor"),e={frame:"post",state:"insert",title:wp.media.view.l10n.addMedia,multiple:!0};b.preventDefault();c.blur();c.hasClass("gallery")&&(e.state="gallery",e.title=wp.media.view.l10n.createGalleryTitle);wp.media.editor.open(d,e)})}else console.warn("Element must be a textarea")})}})(jQuery,window);
	
	</script>
<?php 
}