From 7086111ad4dd997e12a3220e1ee60c9b9bcf0bb8 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 7 Jan 2020 13:06:14 +0100 Subject: Added wordpress --- .../twentysixteen/js/color-scheme-control.js | 96 ++++++ .../themes/twentysixteen/js/customize-preview.js | 41 +++ .../themes/twentysixteen/js/functions.js | 213 ++++++++++++++ .../wp-content/themes/twentysixteen/js/html5.js | 326 +++++++++++++++++++++ .../twentysixteen/js/keyboard-image-navigation.js | 26 ++ .../themes/twentysixteen/js/skip-link-focus-fix.js | 36 +++ 6 files changed, 738 insertions(+) create mode 100644 srcs/wordpress/wp-content/themes/twentysixteen/js/color-scheme-control.js create mode 100644 srcs/wordpress/wp-content/themes/twentysixteen/js/customize-preview.js create mode 100644 srcs/wordpress/wp-content/themes/twentysixteen/js/functions.js create mode 100644 srcs/wordpress/wp-content/themes/twentysixteen/js/html5.js create mode 100644 srcs/wordpress/wp-content/themes/twentysixteen/js/keyboard-image-navigation.js create mode 100644 srcs/wordpress/wp-content/themes/twentysixteen/js/skip-link-focus-fix.js (limited to 'srcs/wordpress/wp-content/themes/twentysixteen/js') diff --git a/srcs/wordpress/wp-content/themes/twentysixteen/js/color-scheme-control.js b/srcs/wordpress/wp-content/themes/twentysixteen/js/color-scheme-control.js new file mode 100644 index 0000000..e65b5bd --- /dev/null +++ b/srcs/wordpress/wp-content/themes/twentysixteen/js/color-scheme-control.js @@ -0,0 +1,96 @@ +/* global colorScheme, Color */ +/** + * Add a listener to the Color Scheme control to update other color controls to new values/defaults. + * Also trigger an update of the Color Scheme CSS when a color is changed. + */ + +( function( api ) { + var cssTemplate = wp.template( 'twentysixteen-color-scheme' ), + colorSchemeKeys = [ + 'background_color', + 'page_background_color', + 'link_color', + 'main_text_color', + 'secondary_text_color' + ], + colorSettings = [ + 'background_color', + 'page_background_color', + 'link_color', + 'main_text_color', + 'secondary_text_color' + ]; + + api.controlConstructor.select = api.Control.extend( { + ready: function() { + if ( 'color_scheme' === this.id ) { + this.setting.bind( 'change', function( value ) { + var colors = colorScheme[value].colors; + + // Update Background Color. + var color = colors[0]; + api( 'background_color' ).set( color ); + api.control( 'background_color' ).container.find( '.color-picker-hex' ) + .data( 'data-default-color', color ) + .wpColorPicker( 'defaultColor', color ); + + // Update Page Background Color. + color = colors[1]; + api( 'page_background_color' ).set( color ); + api.control( 'page_background_color' ).container.find( '.color-picker-hex' ) + .data( 'data-default-color', color ) + .wpColorPicker( 'defaultColor', color ); + + // Update Link Color. + color = colors[2]; + api( 'link_color' ).set( color ); + api.control( 'link_color' ).container.find( '.color-picker-hex' ) + .data( 'data-default-color', color ) + .wpColorPicker( 'defaultColor', color ); + + // Update Main Text Color. + color = colors[3]; + api( 'main_text_color' ).set( color ); + api.control( 'main_text_color' ).container.find( '.color-picker-hex' ) + .data( 'data-default-color', color ) + .wpColorPicker( 'defaultColor', color ); + + // Update Secondary Text Color. + color = colors[4]; + api( 'secondary_text_color' ).set( color ); + api.control( 'secondary_text_color' ).container.find( '.color-picker-hex' ) + .data( 'data-default-color', color ) + .wpColorPicker( 'defaultColor', color ); + } ); + } + } + } ); + + // Generate the CSS for the current Color Scheme. + function updateCSS() { + var scheme = api( 'color_scheme' )(), + css, + colors = _.object( colorSchemeKeys, colorScheme[ scheme ].colors ); + + // Merge in color scheme overrides. + _.each( colorSettings, function( setting ) { + colors[ setting ] = api( setting )(); + } ); + + // Add additional color. + // jscs:disable + colors.border_color = Color( colors.main_text_color ).toCSS( 'rgba', 0.2 ); + // jscs:enable + + css = cssTemplate( colors ); + + api.previewer.send( 'update-color-scheme-css', css ); + } + + // Update the CSS whenever a color setting is changed. + _.each( colorSettings, function( setting ) { + api( setting, function( setting ) { + setting.bind( updateCSS ); + } ); + } ); +} )( wp.customize ); diff --git a/srcs/wordpress/wp-content/themes/twentysixteen/js/customize-preview.js b/srcs/wordpress/wp-content/themes/twentysixteen/js/customize-preview.js new file mode 100644 index 0000000..fc99333 --- /dev/null +++ b/srcs/wordpress/wp-content/themes/twentysixteen/js/customize-preview.js @@ -0,0 +1,41 @@ +/** + * Live-update changed settings in real time in the Customizer preview. + */ + +( function( $ ) { + var style = $( '#twentysixteen-color-scheme-css' ), + api = wp.customize; + + if ( ! style.length ) { + style = $( 'head' ).append( ''; + return parent.insertBefore(p.lastChild, parent.firstChild); + } + + /** + * Returns the value of `html5.elements` as an array. + * @private + * @returns {Array} An array of shived element node names. + */ + function getElements() { + var elements = html5.elements; + return typeof elements == 'string' ? elements.split(' ') : elements; + } + + /** + * Extends the built-in list of html5 elements + * @memberOf html5 + * @param {String|Array} newElements whitespace separated list or array of new element names to shiv + * @param {Document} ownerDocument The context document. + */ + function addElements(newElements, ownerDocument) { + var elements = html5.elements; + if(typeof elements != 'string'){ + elements = elements.join(' '); + } + if(typeof newElements != 'string'){ + newElements = newElements.join(' '); + } + html5.elements = elements +' '+ newElements; + shivDocument(ownerDocument); + } + + /** + * Returns the data associated to the given document + * @private + * @param {Document} ownerDocument The document. + * @returns {Object} An object of data. + */ + function getExpandoData(ownerDocument) { + var data = expandoData[ownerDocument[expando]]; + if (!data) { + data = {}; + expanID++; + ownerDocument[expando] = expanID; + expandoData[expanID] = data; + } + return data; + } + + /** + * returns a shived element for the given nodeName and document + * @memberOf html5 + * @param {String} nodeName name of the element + * @param {Document|DocumentFragment} ownerDocument The context document. + * @returns {Object} The shived element. + */ + function createElement(nodeName, ownerDocument, data){ + if (!ownerDocument) { + ownerDocument = document; + } + if(supportsUnknownElements){ + return ownerDocument.createElement(nodeName); + } + if (!data) { + data = getExpandoData(ownerDocument); + } + var node; + + if (data.cache[nodeName]) { + node = data.cache[nodeName].cloneNode(); + } else if (saveClones.test(nodeName)) { + node = (data.cache[nodeName] = data.createElem(nodeName)).cloneNode(); + } else { + node = data.createElem(nodeName); + } + + // Avoid adding some elements to fragments in IE < 9 because + // * Attributes like `name` or `type` cannot be set/changed once an element + // is inserted into a document/fragment + // * Link elements with `src` attributes that are inaccessible, as with + // a 403 response, will cause the tab/window to crash + // * Script elements appended to fragments will execute when their `src` + // or `text` property is set + return node.canHaveChildren && !reSkip.test(nodeName) && !node.tagUrn ? data.frag.appendChild(node) : node; + } + + /** + * returns a shived DocumentFragment for the given document + * @memberOf html5 + * @param {Document} ownerDocument The context document. + * @returns {Object} The shived DocumentFragment. + */ + function createDocumentFragment(ownerDocument, data){ + if (!ownerDocument) { + ownerDocument = document; + } + if(supportsUnknownElements){ + return ownerDocument.createDocumentFragment(); + } + data = data || getExpandoData(ownerDocument); + var clone = data.frag.cloneNode(), + i = 0, + elems = getElements(), + l = elems.length; + for(;i -1, + isOpera = navigator.userAgent.toLowerCase().indexOf( 'opera' ) > -1, + isIE = navigator.userAgent.toLowerCase().indexOf( 'msie' ) > -1; + + if ( ( isWebkit || isOpera || isIE ) && document.getElementById && window.addEventListener ) { + window.addEventListener( 'hashchange', function() { + var id = location.hash.substring( 1 ), + element; + + if ( ! ( /^[A-z0-9_-]+$/.test( id ) ) ) { + return; + } + + element = document.getElementById( id ); + + if ( element ) { + if ( ! ( /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) ) { + element.tabIndex = -1; + } + + element.focus(); + + // Repositions the window on jump-to-anchor to account for admin bar and border height. + window.scrollBy( 0, -53 ); + } + }, false ); + } +} )(); -- cgit