| 1 |
(function( $ ) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
/** |
| 5 |
* Render image numbers in CPT |
| 6 |
* |
| 7 |
* since updated for 0.8.5 |
| 8 |
* |
| 9 |
* |
| 10 |
* |
| 11 |
* |
| 12 |
*/ |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
//console.log('Scrollsequence admin.js initialized'); |
| 17 |
|
| 18 |
|
| 19 |
function renderImageNumbersCarbon() { |
| 20 |
var ssqCmb = { |
| 21 |
pageList:document.getElementsByClassName("cf-media-gallery__inner"), |
| 22 |
imageLists:[], |
| 23 |
} |
| 24 |
|
| 25 |
// Remove any pre-existing image seq number class |
| 26 |
jQuery("p").remove(".imageSeqNumber"); |
| 27 |
|
| 28 |
// AK ROADM Define Notices and Remove any pre-existing |
| 29 |
var notice_toomanyimg = document.getElementById("scrollsequence_notice_toomanyimg"); |
| 30 |
if (notice_toomanyimg) { |
| 31 |
notice_toomanyimg.style.display = "none"; |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
var notice_toomanypages = document.getElementById("scrollsequence_notice_toomanypages"); |
| 36 |
if (notice_toomanypages){ |
| 37 |
notice_toomanypages.style.display = "none"; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
if(ssqCmb.pageList.length >2){ // AKROADM FREE |
| 42 |
notice_toomanypages.style.display = "block"; |
| 43 |
console.log('more than two pages!!!'); |
| 44 |
} |
| 45 |
|
| 46 |
//console.log('ahoj tady je PRO ak:',ssqCmb); |
| 47 |
for (var i=0; i< ssqCmb.pageList.length; i++){ |
| 48 |
//console.log('1 - page:',i,'has number of images:',ssqCmb.pageList[i].getElementsByClassName("cmb2-media-item").length); |
| 49 |
ssqCmb.imageLists[i]=ssqCmb.pageList[i].getElementsByClassName("cf-media-gallery__item-inner") |
| 50 |
//console.log(ssqCmb.imageLists[i]); |
| 51 |
|
| 52 |
for (var j=0; j< ssqCmb.imageLists[i].length; j++){ |
| 53 |
|
| 54 |
var cislo = document.createElement("p"); // Create a <p> element |
| 55 |
cislo.classList.add("imageSeqNumber"); |
| 56 |
cislo.id="imageSeqId"+[i]+'_'+[j]; |
| 57 |
|
| 58 |
|
| 59 |
if (j < 100){ // AK ROADM |
| 60 |
cislo.innerHTML = j; |
| 61 |
ssqCmb.imageLists[i][j].appendChild(cislo); |
| 62 |
//console.log('page:',i,'image:',j,'image element OK :',ssqCmb.imageLists[i][j]); |
| 63 |
} |
| 64 |
else{ |
| 65 |
cislo.innerHTML = 'X'; |
| 66 |
ssqCmb.imageLists[i][j].appendChild(cislo); |
| 67 |
//console.log('page:',i,'image:',j,'image element NOK:',ssqCmb.imageLists[i][j]); |
| 68 |
notice_toomanyimg.style.display = "block"; |
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
} // END for loop j |
| 73 |
} // END for loop i |
| 74 |
|
| 75 |
//console.log(ssqCmb); |
| 76 |
} // END function |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
// Render Image every "second" |
| 82 |
window.setInterval(function(){ |
| 83 |
/// call your function here |
| 84 |
renderImageNumbersCarbon() |
| 85 |
renderButtonsCarbonNew() |
| 86 |
|
| 87 |
}, 1000); |
| 88 |
renderImageNumbersCarbon() // run immediately |
| 89 |
|
| 90 |
|
| 91 |
/** |
| 92 |
* NEW VERSION OF BUTTONS THAT ALLOW BULK ACTIONS |
| 93 |
* https://www.javascripttutorial.net/javascript-dom/javascript-select-box/ |
| 94 |
* Since 1.0.079 |
| 95 |
* |
| 96 |
*/ |
| 97 |
// Helper functions |
| 98 |
function insertAfterButton(referenceNode, newNode) { |
| 99 |
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); |
| 100 |
} |
| 101 |
|
| 102 |
function reverseChildren(parent) { |
| 103 |
for (var i = 1; i < parent.childNodes.length; i++){ |
| 104 |
parent.insertBefore(parent.childNodes[i], parent.firstChild); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
function renderButtonsCarbonNew(){ // TRANSLATION IS MISSING FOR STRINGS BELOW |
| 110 |
let selectAttsButtonCarbon = document.getElementsByClassName('button cf-media-gallery__browse'); |
| 111 |
if (selectAttsButtonCarbon.length > 0) { |
| 112 |
//console.log('OH YES! OH YES! OH YES! "SELECT ATTACHMENT" BUTTON EXISTS') |
| 113 |
for (let i = 0; i < selectAttsButtonCarbon.length; i++) { // loop through scenes |
| 114 |
let bulkSelectorElement = document.createElement("select"); |
| 115 |
bulkSelectorElement.innerHTML = |
| 116 |
//"<select id='select+"+i+"'>"+ |
| 117 |
"<option > - Bulk Actions - </option>"+ |
| 118 |
"<option value='sortby-name'>Sort By Name</option>"+ |
| 119 |
"<option value='sortby-date'>Sort By Date</option>"+ |
| 120 |
"<option value='sortby-reverse'>Reverse Current Order</option>"+ |
| 121 |
"<option value='delete-all'>Delete All</option>"; |
| 122 |
//"</select>"; |
| 123 |
bulkSelectorElement.id="ssqSortBy"+i; |
| 124 |
bulkSelectorElement.style.marginLeft="10px" |
| 125 |
bulkSelectorElement.dataset.cislo=i; |
| 126 |
|
| 127 |
bulkSelectorElement.onchange = (event) => { |
| 128 |
event.preventDefault(); |
| 129 |
let confirmAction |
| 130 |
switch(bulkSelectorElement.value) { |
| 131 |
case 'sortby-name': //console.log('selection changed to sortby-name') |
| 132 |
confirmAction = confirm('Are you sure you want to sort images by name?'); |
| 133 |
if (confirmAction) { // console.log('Confirmation - CONFIRMED:', event.target.dataset.cislo) |
| 134 |
bulkActionsSortbyName(event.target.dataset.cislo) |
| 135 |
} |
| 136 |
break; |
| 137 |
case 'sortby-date': //console.log('selection changed to sortby-date') |
| 138 |
confirmAction = confirm('Are you sure you want to sort images by date?'); |
| 139 |
if (confirmAction) { // console.log('Confirmation - CONFIRMED:', event.target.dataset.cislo) |
| 140 |
bulkActionsSortbyDate(event.target.dataset.cislo) |
| 141 |
} |
| 142 |
break; |
| 143 |
case 'sortby-reverse': //console.log('selection changed to sortby-reverse') |
| 144 |
confirmAction = confirm('Are you sure you want to reverse images order?'); |
| 145 |
if (confirmAction) { // console.log('Confirmation - CONFIRMED:', event.target.dataset.cislo) |
| 146 |
bulkActionsSortReverse(event.target.dataset.cislo) |
| 147 |
} |
| 148 |
break; |
| 149 |
case 'delete-all': // console.log('selection changed to delete-all') |
| 150 |
confirmAction = confirm('Are you sure you want to remove all images from scene?'); |
| 151 |
if (confirmAction) { // console.log('Confirmation - CONFIRMED:', event.target.dataset.cislo) |
| 152 |
bulkActionsDeleteAll(event.target.dataset.cislo) |
| 153 |
} |
| 154 |
break; |
| 155 |
default: //console.log('selection changed to default value (bulk actions)') |
| 156 |
|
| 157 |
} |
| 158 |
}; |
| 159 |
|
| 160 |
// Check if element exists, if not create, if yes do nothing |
| 161 |
let prevEl=document.getElementById("ssqSortBy"+i) |
| 162 |
if (!prevEl){ |
| 163 |
insertAfterButton(selectAttsButtonCarbon[i], bulkSelectorElement); |
| 164 |
} else { |
| 165 |
//console.log('do nothing, selector already exists') |
| 166 |
} |
| 167 |
|
| 168 |
} // loop through scenesend |
| 169 |
} else { |
| 170 |
//console.log('OH NO "SELECT ATTACHMENT" BUTTON IS UNAVAILABE') |
| 171 |
|
| 172 |
} |
| 173 |
} |
| 174 |
// BULK ACTION FUNCTIONS |
| 175 |
function bulkActionsSortbyName(sceneNumber){ |
| 176 |
let UlAytems=document.getElementsByClassName('cf-media-gallery__list ui-sortable').item(sceneNumber) |
| 177 |
let listAytems= UlAytems.getElementsByTagName("LI"); |
| 178 |
//console.log('listAytems:', listAytems); |
| 179 |
|
| 180 |
jQuery(listAytems).sort(sort_li) // sort elements |
| 181 |
.appendTo(document.getElementsByClassName('cf-media-gallery__list ui-sortable').item(sceneNumber)); // append again to the list |
| 182 |
// sort function callback |
| 183 |
function sort_li(a, b){ |
| 184 |
//console.log('a:',a,a.children[0].children[1].innerHTML.toLowerCase(),'b',b,b.children[0].children[1].innerHTML.toLowerCase()); |
| 185 |
return (b.children[0].children[1].innerHTML.toLowerCase()) < (a.children[0].children[1].innerHTML.toLowerCase()) ? 1 : -1; |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
function bulkActionsSortbyDate(sceneNumber){ |
| 190 |
let UlAytems=document.getElementsByClassName('cf-media-gallery__list ui-sortable').item(sceneNumber) |
| 191 |
let listAytems= UlAytems.getElementsByTagName("LI"); |
| 192 |
//console.log('listAytems:', listAytems); |
| 193 |
|
| 194 |
jQuery(listAytems).sort(sort_li) // sort elements |
| 195 |
.appendTo(document.getElementsByClassName('cf-media-gallery__list ui-sortable').item(sceneNumber)); // append again to the list |
| 196 |
// sort function callback |
| 197 |
function sort_li(a, b){ |
| 198 |
//console.log('a:',a,a.children[1].value.toLowerCase(),'b',b,b.children[1].value.toLowerCase()); |
| 199 |
return (b.children[1].value.toLowerCase()) < (a.children[1].value.toLowerCase()) ? 1 : -1; |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
function bulkActionsSortReverse(sceneNumber){ |
| 204 |
//console.log('S O R T - R E V E R S E on Scene ',sceneNumber) |
| 205 |
reverseChildren(document.getElementsByClassName('cf-media-gallery__list ui-sortable').item(sceneNumber)) |
| 206 |
} |
| 207 |
function bulkActionsDeleteAll(sceneNumber){ |
| 208 |
console.log('D E L E T E - A L L - on Scene ',sceneNumber) |
| 209 |
var imageUlforIthPage2 = document.getElementsByClassName('cf-media-gallery__list ui-sortable').item(sceneNumber).innerHTML = ''; // since 1.4.5 |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
})( jQuery ); |
| 219 |
|