Initial Commit

This commit is contained in:
Rumperuu 2018-03-21 18:19:20 +00:00
parent 4c352bf02e
commit 1ab6e5f0b0
1085 changed files with 195258 additions and 0 deletions

View file

@ -0,0 +1,155 @@
/**
* JS for handling the Site Logo Customizer control.
*/
(function( wp, $ ){
// nice shortcut
var api = wp.customize;
/**
* The Customizer looks for wp.customizer.controlConstructor[type] functions
* where type == the type member of a WP_Customize_Control
*/
api.controlConstructor.site_logo = api.Control.extend({
/**
* This method is called when the control is ready to run.
* Do all of your setup and event binding here.
*/
ready: function() {
// this.container is a jQuery object of your container
// grab the bits of data from the title for specifying this control
var data = this.container.find( '.customize-control-title' ).data();
// Use specific l10n data for this control where available
this.l10n = data.l10n;
// Grab mime type
this.mime = data.mime;
// Set up image container and button elements. Cache for re-use.
this.$imgContainer = $( '#customize-control-site_logo .current' );
this.$btnContainer = $( '#customize-control-site_logo .actions' );
this.$img = $( '<img class="site-logo-thumbnail" />' ).prependTo( this.$imgContainer );
this.$placeholder = $( '<span>' + this.l10n.placeholder + '</span>' ).prependTo( this.$imgContainer );
this.$btnAdd = $( '<button type="button" class="button new">' + this.l10n.upload + '</button>' ).prependTo( this.$btnContainer );
this.$btnChange = $( '<button type="button" class="button change">' + this.l10n.change + '</button>' ).prependTo( this.$btnContainer );
this.$btnRemove = $( '<button type="button" class="button remove">' + this.l10n.remove + '</button>' ).prependTo( this.$btnContainer );
// handy shortcut so we don't have to us _.bind every time we add a callback
_.bindAll( this, 'removeImg', 'upload', 'render', 'pick' );
this.$btnAdd.on( 'click', this.upload );
this.$btnChange.on( 'click', this.upload );
this.$btnRemove.on( 'click', this.removeImg );
// Call render method whenever setting is changed.
this.setting.bind( 'change', this.render );
// Do initial rendering.
this.render();
},
/**
* Remember that _.bind was used to maintain `this` as the control
* object rather than the usual jQuery way of binding to the DOM element.
*/
upload: function( event ) {
event.preventDefault();
if ( ! this.frame ) {
this.initFrame();
}
this.frame.open();
},
/**
* Set the media frame so that it can be reused and accessed when needed.
*/
initFrame: function() {
this.frame = wp.media({
// The title of the media modal
title: this.l10n.choose,
// restrict to specified mime type
library: {
type: this.mime
},
// Customize the submit button.
button: {
// Set the text of the button.
text: this.l10n.set
},
// Just one, thanks.
multiple: false
});
// When an image is selected, run a callback.
this.frame.on( 'select', this.pick );
},
/**
* Fired when an image is selected in the media modal. Gets the selected
* image information, and sets it within the control.
*/
pick: function() {
// get the attachment from the modal frame
var attachment = this.frame.state().get( 'selection' ).single();
if ( 'image' === attachment.get( 'type' ) ) {
// set the setting - the callback will take care of rendering
this.setting( this.reduceMembers( attachment.toJSON() ) );
}
},
/**
* Reduces the attachment object to just the few desired members.
* @param {object} attachment An attachment object provided by the
* medial modal.
* @return {object} A reduced media object.
*/
reduceMembers: function( attachment ) {
var desired = [
'id',
'sizes',
'url'
],
output = {};
$.each( desired, function( i, key ){
output[key] = attachment[key];
});
return output;
},
/**
* Called on init and whenever a setting is changed. Shows the thumbnail
* when there is one or the upload button when there isn't.
*/
render: function() {
var value = this.setting();
if ( value && value.url ) {
this.$placeholder.hide();
if ( ! value.sizes || ! value.sizes.medium ) {
this.$img.attr( 'src', value.url );
} else {
this.$img.attr( 'src', value.sizes.medium.url );
}
this.$img.show();
this.$btnRemove.show();
this.$btnChange.show();
this.$btnAdd.hide();
} else {
this.$img.hide();
this.$placeholder.show();
this.$btnRemove.hide();
this.$btnChange.hide();
this.$btnAdd.show();
}
},
/**
* Called when the "Remove Image" link is clicked. Sets thes setting back
* to its default state.
* @param {object} event jQuery Event object from click event
*/
removeImg: function( event ) {
event.preventDefault();
this.setting( {
url: '',
id: 0
} );
}
});
})( this.wp, jQuery );

View file

@ -0,0 +1 @@
(function(a,c){var b=a.customize;b.controlConstructor.site_logo=b.Control.extend({ready:function(){var d=this.container.find(".customize-control-title").data();this.l10n=d.l10n;this.mime=d.mime;this.$imgContainer=c("#customize-control-site_logo .current");this.$btnContainer=c("#customize-control-site_logo .actions");this.$img=c('<img class="site-logo-thumbnail" />').prependTo(this.$imgContainer);this.$placeholder=c("<span>"+this.l10n.placeholder+"</span>").prependTo(this.$imgContainer);this.$btnAdd=c('<button type="button" class="button new">'+this.l10n.upload+"</button>").prependTo(this.$btnContainer);this.$btnChange=c('<button type="button" class="button change">'+this.l10n.change+"</button>").prependTo(this.$btnContainer);this.$btnRemove=c('<button type="button" class="button remove">'+this.l10n.remove+"</button>").prependTo(this.$btnContainer);_.bindAll(this,"removeImg","upload","render","pick");this.$btnAdd.on("click",this.upload);this.$btnChange.on("click",this.upload);this.$btnRemove.on("click",this.removeImg);this.setting.bind("change",this.render);this.render()},upload:function(d){d.preventDefault();if(!this.frame){this.initFrame()}this.frame.open()},initFrame:function(){this.frame=a.media({title:this.l10n.choose,library:{type:this.mime},button:{text:this.l10n.set},multiple:false});this.frame.on("select",this.pick)},pick:function(){var d=this.frame.state().get("selection").first().toJSON();d=this.reduceMembers(d);this.setting(d)},reduceMembers:function(f){var e=["id","sizes","url"],d={};c.each(e,function(h,g){d[g]=f[g]});return d},render:function(){var d=this.setting();if(d&&d.url){this.$placeholder.hide();if(!d.sizes||!d.sizes.medium){this.$img.attr("src",d.url)}else{this.$img.attr("src",d.sizes.medium.url)}this.$img.show();this.$btnRemove.show();this.$btnChange.show();this.$btnAdd.hide()}else{this.$img.hide();this.$placeholder.show();this.$btnRemove.hide();this.$btnChange.hide();this.$btnAdd.show()}},removeImg:function(d){d.preventDefault();this.setting({url:"",id:0})}})})(this.wp,jQuery);

View file

@ -0,0 +1,24 @@
/* global site_logo_header_classes */
/**
* JS for handling the "Display Header Text" setting's realtime preview.
*/
(function($){
var api = wp.customize,
$classes = site_logo_header_classes;
api( 'site_logo_header_text', function( value ) {
value.bind( function( to ) {
if ( true === to ) {
$( $classes ).css({
'position': 'static',
'clip': 'auto'
});
} else {
$( $classes ).css({
'position': 'absolute',
'clip': 'rect(1px 1px 1px 1px)'
});
}
});
});
})(jQuery);

View file

@ -0,0 +1 @@
!function(t){var i=wp.customize,o=site_logo_header_classes;i("site_logo_header_text",function(i){i.bind(function(i){t(o).css(!0===i?{position:"static",clip:"auto"}:{position:"absolute",clip:"rect(1px 1px 1px 1px)"})})})}(jQuery);

View file

@ -0,0 +1,43 @@
/**
* JS for handling the Site Logo real-time display in the Customizer preview frame.
*/
(function($){
var api = wp.customize,
$body, $anchor, $logo, size;
function cacheSelectors() {
$body = $( 'body' );
$anchor = $( '.site-logo-link' );
$logo = $( '.site-logo' );
size = $logo.attr( 'data-size' );
}
api( 'site_logo', function( value ){
value.bind( function( newVal ){
// grab selectors the first time through
if ( ! $body ) {
cacheSelectors();
}
// Let's update our preview logo.
if ( newVal && newVal.url ) {
// If the source was smaller than the size required by the theme, give the biggest we've got.
if ( ! newVal.sizes[ size ] ) {
size = 'full';
}
$logo.attr({
height: newVal.sizes[ size ].height,
width: newVal.sizes[ size ].width,
src: newVal.sizes[ size ].url
});
$anchor.show();
$body.addClass( 'has-site-logo' );
} else {
$anchor.hide();
$body.removeClass( 'has-site-logo' );
}
});
});
})(jQuery);

View file

@ -0,0 +1 @@
(function(d){var e=wp.customize,c,f,g,a;e("site_logo",function(e){e.bind(function(b){c||(c=d("body"),f=d(".site-logo-link"),g=d(".site-logo"),a=g.attr("data-size"));b&&b.url?(b.sizes[a]||(a="full"),g.attr({height:b.sizes[a].height,width:b.sizes[a].width,src:b.sizes[a].url}),f.show(),c.addClass("has-site-logo")):(f.hide(),c.removeClass("has-site-logo"))})})})(jQuery);