-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Code from https://github.com/xwp/wp-customizer-blank-slate | ||
* | ||
* Learn more at: https://make.xwp.co/2016/09/11/resetting-the-customizer-to-a-blank-slate/ | ||
* Copyright (c) 2016 XWP (https://make.xwp.co/) | ||
*/ | ||
/* global wp, jQuery */ | ||
/* exported PluginCustomizer */ | ||
var WPMLang = (function (api, $) { | ||
'use strict'; | ||
|
||
var component = { | ||
data: { | ||
url: null | ||
} | ||
}; | ||
|
||
/** | ||
* Initialize functionality. | ||
* | ||
* @param {object} home Args. | ||
* @param {string} home.url Preview URL. | ||
* @returns {void} | ||
*/ | ||
component.init = function init(home) { | ||
_.extend(component.data, home); | ||
if (!home || !home.url) { | ||
throw new Error('Missing args'); | ||
} | ||
|
||
api.bind('ready', function () { | ||
api.previewer.previewUrl.set(home.url); | ||
}); | ||
}; | ||
return component; | ||
}(wp.customize, jQuery) ); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
( function( $ ) { | ||
"use strict"; | ||
|
||
$( function() { | ||
|
||
$('#wpm_installed_localizations').on('init_localizations', function(){ | ||
if ($(this).val()) { | ||
$('#delete_localization').prop('disabled', false); | ||
} else { | ||
$('#delete_localization').prop('disabled', true); | ||
} | ||
}); | ||
|
||
$('#delete_localization').click(function(){ | ||
|
||
if (confirm(wpm_additional_settings_params.confirm_question)) { | ||
|
||
var locale = $('#wpm_installed_localizations').val(); | ||
var button = $(this); | ||
|
||
var data = { | ||
action: 'wpm_delete_localization', | ||
locale: locale, | ||
security: wpm_additional_settings_params.delete_localization_nonce | ||
}; | ||
|
||
$.ajax({ | ||
url: wpm_additional_settings_params.ajax_url, | ||
type: 'post', | ||
data: data, | ||
dataType: 'json', | ||
beforeSend: function() { | ||
button.prop('disabled', true).after('<span class="spinner is-active"></span>'); | ||
}, | ||
success: function (json) { | ||
button.next().remove(); | ||
if (json.success) { | ||
button.after('<span class="success">' + json.data + '</span>'); | ||
$('#wpm_installed_localizations option[value="' + locale + '"]').remove(); | ||
} else { | ||
button.after('<span class="error">' + json.data + '</span>'); | ||
} | ||
}, | ||
complete: function() { | ||
$('#wpm_installed_localizations').trigger('init_localizations'); | ||
}, | ||
error: function (xhr, ajaxOptions, thrownError) { | ||
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
$('#qtx_import').click(function(){ | ||
var button = $(this); | ||
|
||
var data = { | ||
action: 'wpm_qtx_import', | ||
security: wpm_additional_settings_params.qtx_import_nonce | ||
}; | ||
|
||
$.ajax({ | ||
url: wpm_additional_settings_params.ajax_url, | ||
type: 'post', | ||
data: data, | ||
dataType: 'json', | ||
beforeSend: function() { | ||
button.prop('disabled', true).after('<span class="spinner is-active"></span>'); | ||
}, | ||
success: function (json) { | ||
button.next().remove(); | ||
button.after('<span class="success">' + json + '</span>'); | ||
}, | ||
error: function (xhr, ajaxOptions, thrownError) { | ||
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); | ||
} | ||
}); | ||
}); | ||
|
||
}); | ||
})( jQuery ); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(function ($) { | ||
"use strict"; | ||
|
||
$(function () { | ||
if ($('#wpm-language-switcher').length === 0) { | ||
var language_switcher = wp.template('wpm-ls-customizer'); | ||
$('#customize-header-actions').append(language_switcher); | ||
} | ||
}); | ||
})(jQuery, wp); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(function ($) { | ||
"use strict"; | ||
|
||
$(function () { | ||
if ($('#wpm-language-switcher').length === 0) { | ||
var language_switcher = wp.template('wpm-ls'); | ||
$('#wpbody-content > .wrap').prepend(language_switcher); | ||
} | ||
}); | ||
})(jQuery, wp); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
(function ($) { | ||
"use strict"; | ||
|
||
function formatState (item) { | ||
if (!item.id) { | ||
return item.text; | ||
} | ||
return $('<img src="' + $(item.element).data('flag') + '" /> ' + item.text + '</span>'); | ||
} | ||
|
||
$(function () { | ||
|
||
$(document).on('click', '.delete-language', function () { | ||
|
||
var button = $(this); | ||
|
||
if (confirm(wpm_languages_params.confirm_question)) { | ||
|
||
var data = { | ||
action: 'wpm_delete_lang', | ||
language: button.data('language'), | ||
security: wpm_languages_params.delete_lang_nonce | ||
}; | ||
|
||
$.ajax({ | ||
url: wpm_languages_params.ajax_url, | ||
type: 'post', | ||
data: data, | ||
complete: function () { | ||
button.parent().parents('.postbox').fadeOut('slow', function () { | ||
$(this).remove(); | ||
$('.language-order').each(function(i){ | ||
$(this).text(i+1); | ||
}); | ||
wpm_lang_count--; | ||
}); | ||
}, | ||
error: function (xhr, ajaxOptions, thrownError) { | ||
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
$("#wpm-languages").sortable({ | ||
update: function(){ | ||
$('.language-order').each(function(i){ | ||
$(this).text(i+1); | ||
}); | ||
} | ||
}); | ||
|
||
$('#add_lang').click(function () { | ||
var t_language = wp.template('wpm-add-lang'); | ||
var data = { | ||
count: wpm_lang_count | ||
}; | ||
$('#wpm-languages').append(t_language(data)); | ||
$(".wpm-flags").trigger('init_select2'); | ||
wpm_lang_count++; | ||
}); | ||
|
||
|
||
$(document).on('click', '.handlediv', function(){ | ||
$(this).parent().toggleClass('closed'); | ||
}); | ||
|
||
$(document).on('keypress, keyup', '.postbox input[name$="[name]"]', function(){ | ||
var text = $(this).val(); | ||
$(this).parents('.postbox').find('h2 .language-order+span').text(text); | ||
}); | ||
|
||
$(document).on('init_select2', '.wpm-flags', function(){ | ||
$(this).select2({ | ||
templateResult: formatState, | ||
templateSelection: formatState | ||
}); | ||
}); | ||
|
||
$(".wpm-flags").trigger('init_select2'); | ||
|
||
}); | ||
}(jQuery)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
( function( $ ) { | ||
"use strict"; | ||
|
||
$( function() { | ||
var changed = false; | ||
|
||
$( 'input, textarea, select, checkbox' ).change( function() { | ||
changed = true; | ||
}); | ||
|
||
$( '.wpm-nav-tab-wrapper a' ).click( function() { | ||
if ( changed ) { | ||
window.onbeforeunload = function() { | ||
return wpm_settings_params.nav_warning; | ||
}; | ||
} else { | ||
window.onbeforeunload = ''; | ||
} | ||
}); | ||
|
||
$( '.submit input' ).click( function() { | ||
window.onbeforeunload = ''; | ||
}); | ||
|
||
}); | ||
})( jQuery ); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
String.prototype.xsplit = function (_regEx) { | ||
// Most browsers can do this properly, so let them work, they'll do it faster | ||
if ('a~b'.split(/(~)/).length === 3) { | ||
return this.split(_regEx); | ||
} | ||
|
||
if (!_regEx.global) { | ||
_regEx = new RegExp(_regEx.source, 'g' + (_regEx.ignoreCase ? 'i' : '')); | ||
} | ||
|
||
// IE (and any other browser that can't capture the delimiter) | ||
// will, unfortunately, have to be slowed down | ||
var start = 0, arr = []; | ||
var result; | ||
while ((result = _regEx.exec(this)) !== null) { | ||
arr.push(this.slice(start, result.index)); | ||
if (result.length > 1) arr.push(result[1]); | ||
start = _regEx.lastIndex; | ||
} | ||
if (start < this.length) arr.push(this.slice(start)); | ||
if (start === this.length) arr.push(''); //delim at the end | ||
return arr; | ||
}; | ||
|
||
var wpm_translator = { | ||
|
||
string_to_ml_array: function (text) { | ||
|
||
if (Object.prototype.toString.call(text) !== '[object String]') { | ||
return text; | ||
} | ||
|
||
var split_regex = /(\[:[a-z-]+\]|\[:\])/gi; | ||
var blocks = text.xsplit(split_regex); | ||
|
||
if (typeof blocks !== 'object' || !Object.keys(blocks).length) | ||
return text; | ||
|
||
if (Object.keys(blocks).length === 1) { | ||
return blocks[0]; | ||
} | ||
|
||
var results = {}, | ||
languages = wpm_translator_params.languages; | ||
|
||
languages.forEach(function(item){ | ||
results[item] = ''; | ||
}); | ||
|
||
var lang = blocks.length === 1 ? wpm_translator_params.default_language : ''; | ||
|
||
blocks.forEach(function(block, index) { | ||
if (index % 2 === 1) { | ||
lang = block; | ||
} else if (!!results[lang]) { | ||
results[lang] += block.trim(); | ||
} | ||
}); | ||
|
||
return results; | ||
}, | ||
|
||
|
||
translate_string: function (string, language) { | ||
|
||
var strings = wpm_translator.string_to_ml_array(string); | ||
|
||
if (typeof strings !== 'object' || !Object.keys(strings).length) { | ||
return string; | ||
} | ||
|
||
var languages = wpm_translator_params.languages; | ||
|
||
if (language) { | ||
if (!!languages[language]) { | ||
return strings[language]; | ||
} | ||
|
||
return ''; | ||
} | ||
|
||
language = wpm_translator_params.language; | ||
|
||
if (!strings[language].length && wpm_translator_params.show_untranslated_strings === "yes") { | ||
return strings[wpm_translator_params.default_language]; | ||
} | ||
|
||
if (!!strings[language]) { | ||
return strings[language]; | ||
} | ||
|
||
return ''; | ||
} | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.