installed plugin AudioIgniter version 1.7.3

This commit is contained in:
2022-04-17 00:39:10 +00:00
committed by Gitium
parent dbc3ae04ae
commit 55ea6cf8dd
56 changed files with 13860 additions and 0 deletions

View File

@ -0,0 +1,106 @@
//
// Mixins
//
@mixin clearfix() {
&::after {
content: "";
display: table;
clear: both;
}
}
@keyframes ai-spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
@mixin spinner($color: #fff, $opacity: .35, $size: 40px) {
border: 6px solid rgba($color, $opacity);
border-top-color: rgba($color, $opacity*2.5);
border-radius: 100%;
height: $size;
width: $size;
animation: ai-spin .8s infinite linear;
}
@mixin btn-reset {
display: inline-block;
font-weight: normal;
margin: 0;
padding: 0;
line-height: normal;
border: 0;
appearance: none;
text-align: center;
box-shadow: none;
vertical-align: middle;
cursor: pointer;
white-space: nowrap;
user-select: none;
border-radius: 0;
min-width: 0;
max-width: 100%;
min-height: 0;
width: auto;
height: auto;
background-image: none;
background-color: transparent;
&::before,
&::after {
display: none;
}
}
@keyframes backgroundPosition {
0% {
background-position: -140px 0
}
100% {
background-position: 140px 0
}
}
@mixin animatedBackground($width: 140px, $height: 8px, $top: 0, $left: 0) {
content: '';
width: $width;
height: $height;
background: linear-gradient(to right, $control-color 8%, lighten($control-color, 6%) 18%, $control-color 33%);
background-size: 500px;
position: absolute;
top: $top;
left: $left;
opacity: 1;
animation-duration: 1s;
animation-fill-mode: forwards;
animation-iteration-count: infinite;
animation-name: backgroundPosition;
animation-timing-function: linear;
}
@mixin sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
@mixin dashicon($icon) {
content: $icon;
display: inline-block;
font: 400 20px/1 dashicons;
speak: none;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-decoration: none !important;
}

View File

@ -0,0 +1,155 @@
@charset "UTF-8";
@keyframes ai-spin { 0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); } }
@keyframes backgroundPosition { 0% { background-position: -140px 0; }
100% { background-position: 140px 0; } }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }
.ai-row { margin-left: -15px; margin-right: -15px; box-sizing: border-box; }
.ai-row::after { content: ""; display: table; clear: both; }
[class^="ai-col"] { float: left; padding-left: 15px; padding-right: 15px; width: 50%; box-sizing: border-box; }
.ai-btn { display: inline-block; font-weight: normal; margin: 0; line-height: normal; border: 0; box-shadow: none; text-align: center; vertical-align: middle; cursor: pointer; white-space: nowrap; user-select: none; border-radius: 2px; width: auto; height: auto; background-image: none; padding: 11px 20px 11px; font-size: 12px; text-transform: uppercase; background-color: #1c4866; color: #ffffff; text-decoration: none; }
.ai-btn:hover, .ai-btn:focus { color: #ffffff; background-color: #173a52; }
.ai-btn-green { background-color: #14b552; }
.ai-btn-green:hover, .ai-btn-green:focus { color: #ffffff; background-color: #119e48; }
.ai-brand-module { background-color: #1c4866; padding: 15px; color: #ffffff; font-size: 12px; }
.ai-brand-module p { font-size: 12px; }
.ai-brand-module a:not(.ai-btn) { color: #ffcc00; text-decoration: none; }
.ai-brand-module-actions { text-align: right; }
.ai-brand-module-actions p { margin: 0; }
.ai-header { margin: 12px 0 -12px; height: 40px; }
.ai-header-actions { text-align: right; }
.ai-logo { display: inline-block; position: relative; top: -2px; }
.ai-logo img { height: 44px; }
.ai-note { font-style: italic; }
.ai-list-inline { margin: 0; padding: 0; list-style: none; }
.ai-list-inline li { display: inline-block; margin: 0; }
.ai-footer-links a::after { content: "\007c"; color: #ffffff; opacity: .5; margin: 0 7px; }
.ai-footer-links li:last-child a::after { display: none; }
.ai-module { border: 1px solid #eeeeee; margin-top: 12px; padding: 15px; }
.ai-module::after { content: ""; display: table; clear: both; }
.ai-container { margin-top: 12px; }
.ai-field-controls-wrap { padding: 15px; border: 1px solid #eeeeee; }
.ai-field-controls-wrap::after { content: ""; display: table; clear: both; }
.ai-field-controls { float: left; }
.ai-field-controls .button { margin-right: 5px; }
.ai-field-controls-visibility { float: right; padding-top: 4px; }
.ai-field-controls-visibility a { text-decoration: none; }
.ai-fields-expand-all { margin-right: 8px; padding-right: 6px; border-right: 1px solid #f1f1f1; }
.ai-fields-container { padding: 15px; border-left: 1px solid #eeeeee; border-right: 1px solid #eeeeee; }
.ai-field-repeatable { margin-bottom: 15px; border: 1px solid #d7d7d7; box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.07); }
.ai-field-repeatable:last-child { margin-bottom: 0; }
.ai-field-repeatable:only-child .ai-remove-field { display: none; }
.ai-field-container { padding: 15px; background-color: #ffffff; }
.ai-field-container::after { content: ""; display: table; clear: both; }
.ai-field-head { padding: 8px 15px 5px; line-height: normal; background-color: #d7d7d7; background: linear-gradient(to bottom, #f1f1f1, #d7d7d7); border-bottom: 1px solid #cccccc; }
.ai-field-head::after { content: ""; display: table; clear: both; }
.ai-field-head .toggle-indicator { border-radius: 50%; }
.ai-fields-sortable .ai-field-head { cursor: move; }
.ai-field-sort-handle { position: relative; top: 1px; color: #0073aa; }
.ai-field-sort-handle .dashicons { font-size: 18px; }
.ai-field-title { font-weight: bold; font-size: 1.05em; margin-left: 8px; padding-top: 3px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; max-width: 80%; display: inline-block; }
.ai-field-toggle { float: right; }
.ai-field-cover { float: left; width: 100px; height: 100px; margin-right: 15px; background-color: #eeeeee; border: 1px solid #cccccc; }
.ai-field-split { float: left; width: calc(50% - 71px); margin-right: 15px; }
.ai-field-split:nth-child(2n + 1) { margin-right: 0; }
.ai-container .button .dashicons, .ai-module .button .dashicons { font-size: 1.2em; line-height: 1.7em; }
.ai-form-field-group { padding: 15px; border: 1px solid #f1f1f1; margin-bottom: 15px; }
.ai-form-field-group :last-child { margin-bottom: 0; }
.ai-form-field-group-title { margin-top: 0; }
.ai-form-field { margin-bottom: 15px; }
.ai-form-field label { display: inline-block; font-weight: bold; margin-bottom: 3px; }
.ai-form-field input[type="text"], .ai-form-field input[type="url"], .ai-form-field input[type="search"], .ai-form-field input[type="email"], .ai-form-field input[type="password"], .ai-form-field input[type="number"], .ai-form-field input[type="tel"], .ai-form-field input[type="date"], .ai-form-field textarea { width: 100%; }
.ai-form-field input[type="checkbox"], .ai-form-field input[type="radio"] { display: inline-block; position: relative; top: 1px; }
.ai-module-settings .ai-form-field input[type="text"], .ai-module-settings .ai-form-field input[type="url"], .ai-module-settings .ai-form-field input[type="search"], .ai-module-settings .ai-form-field input[type="email"], .ai-module-settings .ai-form-field input[type="password"], .ai-module-settings .ai-form-field input[type="number"], .ai-module-settings .ai-form-field input[type="tel"], .ai-module-settings .ai-form-field input[type="date"], .ai-module-settings .ai-form-field textarea, .ai-module-settings .ai-form-field select { width: 200px; max-width: 100%; display: block; }
.ai-form-field-addon { position: relative; }
.ai-form-field-addon input { padding-right: 80px; }
.ai-form-field-addon button { position: absolute; top: 0; right: -2px; }
.ai-field-help { margin: 5px 0 0; font-style: italic; color: #999; }
.ai-remove-field { float: right; }
.ai-field-upload-cover { display: block; position: relative; width: 100px; height: 100px; text-decoration: none; color: initial; overflow: hidden; }
.ai-field-upload-cover img { max-width: 100%; display: none; }
.ai-has-cover .ai-remove-cover { display: block; }
.ai-has-cover .ai-field-cover-placeholder { display: none; }
.ai-has-cover img { display: inline-block; }
.ai-field-cover-placeholder { text-align: center; font-style: normal; font-size: .9em; opacity: .8; padding-top: 28px; }
.ai-field-cover-placeholder::before { content: ""; display: inline-block; font: 400 20px/1 dashicons; speak: none; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-decoration: none !important; display: block; }
.ai-track-loading .ai-field-cover-placeholder::before { content: "\f463"; animation: rotation 1.2s infinite linear; }
.ai-remove-cover { color: #ffffff; background-color: #ff0000; width: 16px; height: 16px; font-size: 12px; cursor: pointer; position: absolute; top: 0; right: 0; opacity: .9; transition: opacity 0.18s ease-in; display: none; text-align: center; }
.ai-remove-cover:hover { opacity: 1; }
.ai-remove-cover .dashicons { font-size: 16px; width: 100%; height: 100%; }
.ai-remove-all-fields .dashicons, .ai-remove-field .dashicons { color: #ff0000; }
.ai-add-field-batch .dashicons, .ai-add-field .dashicons { color: #0073aa; }
.ai-info-box { background: #fffce6; color: #948832; font-size: 12px; border: solid 1px #eeeac9; padding: 15px; margin: 0 0 15px 0; }
.ai-player-type-message { display: none; }
.ai-drop-placeholder { background-color: #f1f1f1; border: 2px dashed #cccccc; opacity: 0.5; margin-bottom: 15px; }
.ai-collapsed .ai-field-container { display: none; }
.ai-collapsed .toggle-indicator::before { content: "\f140" !important; }
.ai-module-shortcode .code { display: block; width: 100%; margin-top: 3px; padding: 10px 10px 8px; font-weight: bold; background: #f1f1f1; }
.ai-sync-soundcloud.button { display: none; }
.ai-sync-soundcloud.button::before { content: "\f463"; color: #d54e21; display: inline-block; font: 400 19px/1 dashicons; speak: none; position: relative; left: -1px; top: 4px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; vertical-align: top; }
.ai-track-loading .ai-sync-soundcloud.button::before { animation: rotation 1.2s infinite linear; }
.ai-soundcloud-track .ai-sync-soundcloud { display: inline-block; }
.ai-soundcloud-track .ai-upload { display: none; }
@media (max-width: 1100px) { .ai-field-controls, .ai-field-controls-visibility { margin: 0; float: none; width: 100%; }
.ai-field-controls { margin-bottom: 5px; }
.ai-field-split { float: none; width: 100%; }
.ai-field-cover { margin-bottom: 15px; }
.ai-footer { text-align: center; }
.ai-footer .ai-brand-module-actions { text-align: center; margin-top: 10px; }
.ai-footer [class^="ai-col"] { width: 100%; } }
@media (max-width: 782px) { .ai-container .button .dashicons, .ai-module .button .dashicons { line-height: 1.2em; }
.ai-form-field-addon .button { top: 2px; } }
@media (max-width: 600px) { .ai-field-controls .button { width: 100%; }
.ai-header { text-align: center; }
.ai-header .ai-brand-module-actions { margin-top: 10px; }
.ai-header .ai-btn { display: block; }
.ai-header [class^="ai-col"] { width: 100%; } }

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,660 @@
@import 'mixins';
$brand-color: #1c4866 !default;
$brand-secondary-color: #ffcc00 !default;
$lighter-grey: #f1f1f1 !default;
$light-grey: #eeeeee !default;
$medium-grey: #d7d7d7 !default;
$dark-grey: #cccccc !default;
$white: #ffffff !default;
$blue: #0073aa !default;
$red: #ff0000 !default;
$green: #14b552 !default;
$info-box-bg-color: #fffce6 !default;
$info-box-border-color: #eeeac9 !default;
$info-box-text-color: #948832 !default;
$base-pad: 15px !default;
$transition-time: .18s !default;
$border-color: $lighter-grey !default;
.sr-only {
@include sr-only;
}
.ai-row {
@include clearfix;
margin-left: -15px;
margin-right: -15px;
box-sizing: border-box;
}
[class^="ai-col"] {
float: left;
padding-left: 15px;
padding-right: 15px;
width: 50%;
box-sizing: border-box;
}
.ai-btn {
display: inline-block;
font-weight: normal;
margin: 0;
line-height: normal;
border: 0;
box-shadow: none;
text-align: center;
vertical-align: middle;
cursor: pointer;
white-space: nowrap;
user-select: none;
border-radius: 2px;
width: auto;
height: auto;
background-image: none;
padding: 11px 20px 11px;
font-size: 12px;
text-transform: uppercase;
background-color: $brand-color;
color: $white;
text-decoration: none;
&:hover,
&:focus {
color: $white;
background-color: darken($brand-color, 5%);
}
}
.ai-btn-green {
background-color: $green;
&:hover,
&:focus {
color: $white;
background-color: darken($green, 5%);
}
}
//
// Brand Modules
//
.ai-brand-module {
background-color: $brand-color;
padding: $base-pad;
color: $white;
font-size: 12px;
p {
font-size: 12px;
}
a:not(.ai-btn) {
color: $brand-secondary-color;
text-decoration: none;
}
}
.ai-brand-module-actions {
text-align: right;
p {
margin: 0;
}
}
//
// Header
//
.ai-header {
margin: 12px 0 -12px;
height: 40px;
}
.ai-header-actions {
text-align: right;
}
.ai-logo {
display: inline-block;
position: relative;
top: -2px;
img {
height: 44px;
}
}
//
// Footer
//
.ai-note {
font-style: italic;
}
.ai-list-inline {
margin: 0;
padding: 0;
list-style: none;
li {
display: inline-block;
margin: 0;
}
}
.ai-footer-links {
a {
&::after {
content: "\007c";
color: $white;
opacity: .5;
margin: 0 7px;
}
}
li {
&:last-child {
a::after {
display: none;
}
}
}
}
//
// General
//
.ai-module {
@include clearfix;
border: 1px solid $light-grey;
margin-top: 12px;
padding: $base-pad;
}
.ai-container {
margin-top: 12px;
}
//
// Field Controls
//
.ai-field-controls-wrap {
@include clearfix;
padding: $base-pad;
border: 1px solid $light-grey;
}
.ai-field-controls {
float: left;
.button {
margin-right: 5px;
}
}
.ai-field-controls-visibility {
float: right;
padding-top: 4px;
}
.ai-field-controls-visibility {
a {
text-decoration: none;
}
}
.ai-fields-expand-all {
margin-right: 8px;
padding-right: 6px;
border-right: 1px solid $lighter-grey;
}
//
// Fields general structure
//
.ai-fields-container {
padding: $base-pad;
border-left: 1px solid $light-grey;
border-right: 1px solid $light-grey;
}
.ai-field-repeatable {
margin-bottom: $base-pad;
border: 1px solid $medium-grey;
box-shadow: 1px 1px 2px rgba(black, .07);
&:last-child {
margin-bottom: 0;
}
&:only-child {
.ai-remove-field {
display: none;
}
}
}
.ai-field-container {
@include clearfix;
padding: $base-pad;
background-color: $white;
}
.ai-field-head {
@include clearfix;
padding: 8px $base-pad 5px;
line-height: normal;
background-color: $medium-grey;
background: linear-gradient(to bottom, $lighter-grey, $medium-grey);
border-bottom: 1px solid $dark-grey;
.toggle-indicator {
border-radius: 50%;
}
.ai-fields-sortable & {
cursor: move;
}
}
.ai-field-sort-handle {
position: relative;
top: 1px;
color: $blue;
.dashicons {
font-size: 18px;
}
}
.ai-field-title {
font-weight: bold;
font-size: 1.05em;
margin-left: 8px;
padding-top: 3px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
max-width: 80%;
display: inline-block;
}
.ai-field-toggle {
float: right;
}
.ai-field-cover {
float: left;
width: 100px;
height: 100px;
margin-right: $base-pad;
background-color: $light-grey;
border: 1px solid $dark-grey;
}
.ai-field-split {
float: left;
width: calc(50% - 71px);
margin-right: $base-pad;
&:nth-child(2n + 1) {
margin-right: 0;
}
}
//
// Form elements
//
.ai-container,
.ai-module {
.button {
.dashicons {
font-size: 1.2em;
line-height: 1.7em;
}
}
}
.ai-form-field-group {
padding: $base-pad;
border: 1px solid $border-color;
margin-bottom: $base-pad;
:last-child {
margin-bottom: 0;
}
&-title {
margin-top: 0;
}
}
.ai-form-field {
margin-bottom: $base-pad;
label {
display: inline-block;
font-weight: bold;
margin-bottom: 3px;
}
input[type="text"],
input[type="url"],
input[type="search"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="date"],
textarea {
width: 100%;
}
input[type="checkbox"],
input[type="radio"] {
display: inline-block;
position: relative;
top: 1px;
}
}
.ai-module-settings {
.ai-form-field {
input[type="text"],
input[type="url"],
input[type="search"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="date"],
textarea,
select {
width: 200px;
max-width: 100%;
display: block;
}
}
}
.ai-form-field-addon {
position: relative;
input {
padding-right: 80px;
}
button {
position: absolute;
top: 0;
right: -2px;
}
}
.ai-field-help {
margin: 5px 0 0;
font-style: italic;
color: #999;
}
.ai-remove-field {
float: right;
}
.ai-field-upload-cover {
display: block;
position: relative;
width: 100px;
height: 100px;
text-decoration: none;
color: initial;
overflow: hidden;
img {
max-width: 100%;
display: none;
}
}
.ai-has-cover {
.ai-remove-cover {
display: block;
}
.ai-field-cover-placeholder {
display: none;
}
img {
display: inline-block;
}
}
.ai-field-cover-placeholder {
text-align: center;
font-style: normal;
font-size: .9em;
opacity: .8;
padding-top: 28px;
&::before {
@include dashicon($icon: "\f128");
display: block;
}
.ai-track-loading & {
&::before {
content: "\f463";
animation: rotation 1.2s infinite linear;
}
}
}
.ai-remove-cover {
color: $white;
background-color: $red;
width: 16px;
height: 16px;
font-size: 12px;
cursor: pointer;
position: absolute;
top: 0;
right: 0;
opacity: .9;
transition: opacity $transition-time ease-in;
display: none;
text-align: center;
&:hover {
opacity: 1;
}
.dashicons {
font-size: 16px;
width: 100%;
height: 100%;
}
}
.ai-remove-all-fields,
.ai-remove-field {
.dashicons {
color: $red;
}
}
.ai-add-field-batch,
.ai-add-field {
.dashicons {
color: $blue;
}
}
.ai-info-box {
background: $info-box-bg-color;
color: $info-box-text-color;
font-size: 12px;
border: solid 1px $info-box-border-color;
padding: 15px;
margin: 0 0 15px 0;
}
.ai-player-type-message {
display: none;
}
//
// Sortable specific
//
.ai-drop-placeholder {
background-color: $lighter-grey;
border: 2px dashed $dark-grey;
opacity: 0.5;
margin-bottom: $base-pad;
}
//
// Collapsible
//
.ai-collapsed {
.ai-field-container {
display: none;
}
.toggle-indicator {
&::before {
content: "\f140" !important;
}
}
}
//
// Shortcode field
//
.ai-module-shortcode {
.code {
display: block;
width: 100%;
margin-top: 3px;
padding: 10px 10px 8px;
font-weight: bold;
background: $lighter-grey;
}
}
//
// Soundcloud module
//
.ai-sync-soundcloud.button { // Overcoming specificity
display: none;
&::before {
content: "\f463";
color: #d54e21;
display: inline-block;
font: 400 19px/1 dashicons;
speak: none;
position: relative;
left: -1px;
top: 4px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
vertical-align: top;
}
.ai-track-loading & {
&::before {
animation: rotation 1.2s infinite linear;
}
}
}
.ai-soundcloud-track {
.ai-sync-soundcloud {
display: inline-block;
}
.ai-upload {
display: none;
}
}
//
// Media queries
//
@media (max-width: 1100px) {
.ai-field-controls,
.ai-field-controls-visibility {
margin: 0;
float: none;
width: 100%;
}
.ai-field-controls {
margin-bottom: 5px;
}
.ai-field-split {
float: none;
width: 100%;
}
.ai-field-cover {
margin-bottom: $base-pad;
}
.ai-footer {
text-align: center;
.ai-brand-module-actions {
text-align: center;
margin-top: 10px;
}
[class^="ai-col"] {
width: 100%;
}
}
}
@media (max-width: 782px) {
.ai-container,
.ai-module {
.button {
.dashicons {
line-height: 1.2em;
}
}
}
.ai-form-field-addon {
.button {
top: 2px;
}
}
}
@media (max-width: 600px) {
.ai-field-controls {
.button {
width: 100%;
}
}
.ai-header {
text-align: center;
.ai-brand-module-actions {
margin-top: 10px;
}
.ai-btn {
display: block;
}
[class^="ai-col"] {
width: 100%;
}
}
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -0,0 +1,529 @@
/* eslint-env browser, jquery */
/* eslint-disable prefer-arrow-callback, prefer-template, func-names, no-var, object-shorthand, no-alert */
/* global wp ai_scripts */
jQuery(function($) {
// Return early if ai_scripts are not available
if (!ai_scripts) {
// eslint-disable-line camelcase
return;
}
// eslint-disable-next-line vars-on-top
var AudioIgniter = (function() {
var el = {
$trackContainer: $(".ai-fields-container"),
trackFieldClassName: ".ai-field-repeatable",
$addTrackButtonTop: $(".ai-add-field-top"),
$addTrackButtonBottom: $(".ai-add-field-bottom"),
removeFieldButtonClassName: ".ai-remove-field",
$removeAllTracksButton: $(".ai-remove-all-fields"),
$batchUploadButton: $(".ai-add-field-batch"),
audioUploadButtonClassName: ".ai-upload",
coverUploadButtonClassName: ".ai-field-upload-cover",
coverRemoveClassName: ".ai-remove-cover",
fieldTitleClassName: ".ai-field-title",
trackTitleClassName: ".ai-track-title",
trackArtistClassName: ".ai-track-artist",
trackLyricsClassName: ".ai-track-lyrics",
trackUrlClassName: ".ai-track-url",
hasCoverClass: "ai-has-cover",
fieldHeadClassName: ".ai-field-head",
fieldCollapsedClass: "ai-collapsed",
$expandAllButton: $(".ai-fields-expand-all"),
$collapseAllButton: $(".ai-fields-collapse-all"),
$shortcodeInputField: $("#ai_shortcode"),
soundCloudTrackClass: "ai-soundcloud-track"
};
/**
* Generate a rfc4122 version 4 compliant UUID
* http://stackoverflow.com/a/2117523
*
* @returns {string} - UUID
*/
function uuid() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(
c
) {
var r = (Math.random() * 16) | 0;
var v = c === "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
/**
* Check if field is collapsed
*
* @param {Object} $field - jQuery object
* @returns {*|boolean}
*/
function isFieldCollapsed($field) {
return $field.hasClass(el.fieldCollapsedClass);
}
/**
* Collapse a field
*
* @param {Object} $field - jQuery object
*/
function collapseField($field) {
$field.addClass(el.fieldCollapsedClass);
}
/**
* Expand a field
*
* @param {Object} $field - jQuery object
*/
function expandField($field) {
$field.removeClass(el.fieldCollapsedClass);
}
/**
* Resets the cover image placeholder state
*
* @param {Object} $field - the remove button jQuery object
*/
function resetCoverImage($field) {
var $coverWrap = $field.find("." + el.hasCoverClass);
$coverWrap
.removeClass(el.hasCoverClass)
.find("img")
.attr("src", "")
.attr("alt", "");
$coverWrap
.parent()
.find("input")
.val("");
}
/**
* Resets a form field
* - Clears input values
* - Clears thumbnail
*
* @param {object} $field - the field's jQuery object
* @param {string} [hash] - UUID or random hash
*/
function resetField($field, hash) {
var fieldHash = $field.data("uid");
var newHash = hash || uuid();
$field.attr("data-uid", newHash);
$field
.find("input, textarea")
.not(":button")
.each(function() {
var $this = $(this);
$this.attr("id", $this.attr("id").replace(fieldHash, newHash));
$this.attr("name", $this.attr("name").replace(fieldHash, newHash));
$this.val("");
});
$field.find("label").each(function() {
var $this = $(this);
$this.attr("for", $this.attr("for").replace(fieldHash, newHash));
});
$field.find(el.fieldTitleClassName).text("");
$field.removeClass(el.soundCloudTrackClass);
expandField($field);
resetCoverImage($field);
}
/**
* Checks if a track field is clear of values
*
* @param {object} $field - Track field jQuery object
* @returns {boolean}
*/
function isTrackFieldEmpty($field) {
var isEmpty = true;
var $inputs = $field.find("input");
$inputs.each(function() {
if ($(this).val()) {
isEmpty = false;
}
});
return isEmpty;
}
/**
* Gets the first field from $trackContainer
* and appends it back after resetting it
*
* @param {string} [hash] - UUID or random hash
*
* return {Object} - jQuery object
*/
function getNewTrackField(hash) {
var newHash = hash || uuid();
var $clone = el.$trackContainer
.find(el.trackFieldClassName)
.first()
.clone()
.hide()
.fadeIn();
resetField($clone, newHash);
return $clone;
}
/**
* Removes an element (or many) from the DOM
* by fading it out first
*
* @param {Object} $el - jQuery object of the element(s) to be removed
* @param {Function} [callback] - Optional callback
*/
function removeElement($el, callback) {
$el.fadeOut("fast", function() {
$(this).remove();
if (callback && typeof callback === "function") {
callback();
}
});
}
/**
* Populates a track field
*
* @param {Object} $field - The field's jQuery object
* @param {Object} media - WP Media Manager media object
*/
function populateTrackField($field, media) {
var $urlInput = $field.find(el.trackUrlClassName);
var $titleInput = $field.find(el.trackTitleClassName);
var $artistInput = $field.find(el.trackArtistClassName);
var $fieldTitle = $field.find(el.fieldTitleClassName);
if (media.url) {
$urlInput.val(media.url);
}
if (media.title && $titleInput.val() === "") {
$titleInput.val(media.title);
$fieldTitle.text(media.title);
}
if (media.meta && media.meta.artist && $artistInput.val() === "") {
$artistInput.val(media.meta.artist);
}
}
/**
* Sets a cover image for the field
*
* @param $field - The field's jQuery object
* @param {Object} cover - Cover object
* @param {number} cover.id - Image ID
* @param {string} cover.url - Image URL
* @param {string} [cover.alt] - Image alt text
*/
function setTrackFieldCover($field, cover) {
var $coverField = $field.find(el.coverUploadButtonClassName);
if (!cover || !cover.url || !cover.id) {
return;
}
$coverField
.find("img")
.attr("src", cover.url)
.attr("alt", cover.alt || "");
$coverField
.addClass(el.hasCoverClass)
.siblings("input")
.val(cover.id);
}
/**
* Initializes the WordPress Media Manager
*
* @param {Object} opts - Options object
* @param {string} opts.handler - Handler identifier of the media frame,
* this allows multiple media manager frames with different functionalities
* @param {string} [opts.type] - Filter media manager by type (audio, image etc)
* @param {string} [opts.title=Select Media] - Title of the media manager frame
* @param {boolean} [opts.multiple=false] - Accept multiple selections
* @param {Function} [opts.onMediaSelect] - Do something after media selection
*/
function wpMediaInit(opts) {
if (!opts.handler) {
throw new Error("Missing `handler` option");
}
/* eslint-disable */
var multiple = opts.multiple || false;
var title = opts.title || "Select media";
var mediaManager = wp.media.frames[opts.handler];
/* eslint-enable */
if (mediaManager) {
mediaManager.open();
return;
}
mediaManager = wp.media({
title: title,
multiple: multiple,
library: {
type: opts.type
}
});
mediaManager.open();
mediaManager.on("select", function() {
var attachments;
var attachmentModels = mediaManager.state().get("selection");
if (multiple) {
attachments = attachmentModels.map(function(attachment) {
return attachment.toJSON();
});
} else {
attachments = attachmentModels.first().toJSON();
}
if (opts.onMediaSelect && typeof opts.onMediaSelect === "function") {
opts.onMediaSelect(attachments);
}
});
}
/**
* Collapsible bindings
*/
el.$trackContainer.on("click", el.fieldHeadClassName, function(e) {
var $this = $(this);
var $parentField = $this.parents(el.trackFieldClassName);
if (isFieldCollapsed($parentField)) {
expandField($parentField);
} else {
collapseField($parentField);
}
e.preventDefault();
});
el.$expandAllButton.on("click", function(e) {
expandField(el.$trackContainer.find(el.trackFieldClassName));
e.preventDefault();
});
el.$collapseAllButton.on("click", function(e) {
collapseField(el.$trackContainer.find(el.trackFieldClassName));
e.preventDefault();
});
/**
* Field control bindings
* (Add, remove buttons etc)
*/
/* Bind track title to title input value */
el.$trackContainer.on("keyup", el.trackTitleClassName, function() {
var $this = $(this);
var $fieldTitle = $this
.parents(el.trackFieldClassName)
.find(el.fieldTitleClassName);
$fieldTitle.text($this.val());
});
/* Add Track Top*/
el.$addTrackButtonTop.on("click", function() {
el.$trackContainer.prepend(getNewTrackField());
});
/* Add Track Bottom*/
el.$addTrackButtonBottom.on("click", function () {
el.$trackContainer.append(getNewTrackField());
});
/* Remove Track */
el.$trackContainer.on("click", el.removeFieldButtonClassName, function() {
var $this = $(this);
removeElement($this.parents(".ai-field-repeatable"));
});
/* Remove All Tracks */
el.$removeAllTracksButton.on("click", function() {
var $trackFields = el.$trackContainer.find(el.trackFieldClassName);
if (window.confirm(ai_scripts.messages.confirm_clear_tracks)) {
if ($trackFields.length > 1) {
removeElement($trackFields.slice(1));
resetField($trackFields);
} else {
resetField($trackFields);
}
}
});
/**
* Bind media uploaders
*/
/* Audio upload */
el.$trackContainer.on("click", el.audioUploadButtonClassName, function() {
var $this = $(this);
var $parentTrackField = $this.parents(el.trackFieldClassName);
wpMediaInit({
handler: "ai-audio",
title: ai_scripts.messages.media_title_upload,
type: "audio",
onMediaSelect: function(media) {
populateTrackField($parentTrackField, media);
}
});
});
/**
* Cover image upload
*
* Element `coverUploadButtonClassName` *must* have
* an `img` and `coverRemoveClassName` elements
* as children
*/
el.$trackContainer
.on("click", el.coverUploadButtonClassName, function(e) {
var $this = $(this);
wpMediaInit({
handler: "ai-cover",
title: ai_scripts.messages.media_title_upload_cover,
type: "image",
onMediaSelect: function(media) {
setTrackFieldCover($this.parents(el.trackFieldClassName), {
id: media.id,
url: media.sizes.thumbnail.url,
alt: media.alt
});
}
});
e.preventDefault();
})
/* Remove Image */
.on("click", el.coverRemoveClassName, function(e) {
var $this = $(this);
resetCoverImage($this.parents(el.trackFieldClassName));
e.stopPropagation();
e.preventDefault();
});
/**
* Hide / show options based on player type
*
* Different player types support different kind of options.
* E.g. "Simple Player" doesn't support tracklist height, etc.
*/
var $settingsWrap = $(".ai-module-settings");
var $typeSelect = $(".ai-form-select-player-type");
function getUnsupportedSettings($el) {
var settingsString = $el.data("no-support");
if (typeof settingsString !== "string") {
return [];
}
return settingsString
.replace(/\s/g, "") // remove all whitespace
.split(",")
.map(function(x) {
return "_audioigniter_" + x;
});
}
function filterUIBasedOnPlayerType($el) {
var type = $el.val();
// Reset styles
var $shortcodeMetaBox = $("#ai-meta-box-shortcode");
var $messageBox = $(".ai-player-type-message");
var info = $el.data("info");
$shortcodeMetaBox.show();
if (info) {
$messageBox.text(info).show();
} else {
$messageBox.text("").hide();
}
// Player specific controls
switch (type) {
case "global-footer":
$shortcodeMetaBox.hide();
break;
default:
return;
}
}
function filterSettings() {
var $formFields;
var $type = $typeSelect.find(":selected");
var unsupportedSettings = getUnsupportedSettings($type);
filterUIBasedOnPlayerType($type);
if (unsupportedSettings.length === 0) {
$formFields = $settingsWrap.find(".ai-form-field");
$formFields.show();
return;
}
$settingsWrap.find("input", "select", "textarea").each(function() {
var $this = $(this);
var $parent = $this.parents(".ai-form-field");
if (unsupportedSettings.indexOf($this.attr("name")) > -1) {
$parent.hide();
} else {
$parent.show();
}
});
}
filterSettings();
$typeSelect.on("change", filterSettings);
/**
* Shortcode select on click
*/
el.$shortcodeInputField.on("click", function() {
$(this).select();
});
/**
* Export public methods and variables
*/
return {
elements: el,
uuid: uuid,
collapseField: collapseField,
expandField: expandField,
isFieldCollapsed: isFieldCollapsed,
isTrackFieldEmpty: isTrackFieldEmpty,
resetField: resetField,
resetCoverImage: resetCoverImage,
getNewTrackField: getNewTrackField,
removeElement: removeElement,
populateTrackField: populateTrackField,
setTrackFieldCover: setTrackFieldCover,
wpMediaInit: wpMediaInit
};
})();
// Expose the AudioIgniter instance as a global
if (!window.AudioIgniter) {
window.AudioIgniter = AudioIgniter;
}
});