1$(function () { 2 ////////////////////////////////////////////////// 3 // Bric Version 1.6.2 4 // 1.6.2 5 ////////////////////////////////////////////////// 6 7 ////////////////////////////////////////////////// 8 // template parameters 9 ////////////////////////////////////////////////// 10 var localhost_preview = '1'; 11 var baseURL = 'https://osxhackers.net/'; 12 var redirect_root = '0'; 13 var lightbox_captions = '1'; 14 var lightbox_color = 'rgba(0,0,0,0.8)'; 15 var language = 'en'; 16 var styles_img = ''; 17 var styles_p = 'fine-print-text,text-white,display-4,lead'; 18 19 ////////////////////////////////////////////////// 20 // constants and variables 21 ////////////////////////////////////////////////// 22 var base_path = ''; 23 var volt_php_file = 'includes/volt-core.php'; 24 var login = false; 25 var authorization_editor = false; 26 var csrfToken = ''; 27 var editor; 28 var storedImages = []; 29 var volt_content = 'volt-content-'; 30 var volt_blog_item = 'volt-blog-item-'; 31 var blankRegex = /\s+/g; 32 var charRegex = /[^a-z0-9_\-]+/g; 33 var emptyParagraphRegex = /<p>(|\s+)<\/p>/; 34 var sanitizeString = function (value) { 35 value = value.trim(); 36 value = value.toLowerCase(); 37 value = value.replace(blankRegex, '-'); 38 value = value.replace(charRegex, ''); 39 return value; 40 } 41 var blogActive = Boolean($('.volt-blog').length); 42 var blogModalActive = Boolean($('.volt-blog').length && $('.volt-blog-modal').length); 43 var blogModal; 44 if (blogModalActive) { 45 blogModal = new bootstrap.Modal($('.volt-blog-modal').parent().parent()[0], { 46 backdrop: 'static', 47 keyboard: false, 48 focus: false 49 }) 50 } 51 52 if (localhost_preview === '1' && 53 window.location.hostname === 'localhost' && 54 baseURL !== 'http://setTheBaseURLInProjectSettings.com/') { 55 localhost_preview = true; 56 base_path = baseURL + volt_php_file; 57 } else { 58 localhost_preview = false; 59 base_path = '/' + volt_php_file; 60 } 61 redirect_root = redirect_root === '1'; 62 lightbox_captions = lightbox_captions === '1'; 63 language = language.indexOf('%') === -1 ? language : 'en'; 64 styles_img = styles_img.indexOf('%') === -1 ? styles_img : ''; 65 styles_p = styles_p.indexOf('%') === -1 ? styles_p : ''; 66 67 $.ajaxSetup({ 68 cache: false 69 }); 70 71 ////////////////////////////////////////////////// 72 // check for login state 73 ////////////////////////////////////////////////// 74 $.ajax({ 75 url: base_path, 76 data: { 77 api: 'login' 78 }, 79 dataType: 'json', 80 beforeSend: function (request) { 81 // fetch csrf token 82 request.setRequestHeader("X-CSRF-Token", "fetch"); 83 } 84 }) 85 .done(function (response, status, xhr) { 86 if (response.login) { 87 login = true; 88 toggleLoginForm(false, true, false, response.username); 89 // TODO 90 if (response.editor) { 91 authorization_editor = true; 92 initializeEditor(); 93 initializeStoredImages(); 94 editor.init('.volt-content, .volt-blog-content', 'data-name'); 95 afterEditorInit(); 96 } 97 } else { 98 toggleLoginForm(true, false, false, response.username); 99 } 100 // store csrf token 101 csrfToken = xhr.getResponseHeader("X-CSRF-Token"); 102 loadContentJS(authorization_editor); 103 }) 104 .fail(function () { 105 // Blocs preview mode 106 toggleLoginForm(true, true, true, 'username'); 107 afterEditorInit(); 108 if (localhost_preview) { 109 loadContentJS(authorization_editor); 110 if (blogActive) { 111 loadBlogJS(); 112 } 113 } 114 }); 115 116 ////////////////////////////////////////////////// 117 // blog items 118 ////////////////////////////////////////////////// 119 if ($('.volt-blog-item-detail').length) { 120 // share icons 121 if ($('.volt-blog-item-share-detail').length && $('.volt-blog-share').length) { 122 var permalink = $('.volt-blog-item-detail').attr('data-item-permalink'); 123 var title = $('.volt-blog-item-detail').attr('data-item-title'); 124 html = $('.volt-blog-share').html().replace(/&/gi, '&').replace(/\$\{permalink\}/gi, permalink).replace(/\$\{title\}/gi, title); 125 $('.volt-blog-item-share-detail').html(html); 126 } 127 } 128
129 ////////////////////////////////////////////////// 130 // recent posts 131 ////////////////////////////////////////////////// 132 if ($('.volt-recent-posts').length) { 133 $.each($('.volt-recent-posts'), function(index, value){ 134 value = $(this); 135 var items = parseInt(value.attr('data-blog-items')); 136 var start = parseInt(value.attr('data-blog-start') - 1); 137 items = items + start; 138 var url = value.find('.volt-recent-posts-link').attr('href') + "?feed=rss"; 139 var query = value.attr('data-blog-query'); 140 if (query) { 141 url = url + "&" + query; 142 } 143 if (localhost_preview) { 144 url = baseURL + url.replace('.php', '/'); 145 } 146 var layout = value.attr('data-blog-layout'); 147 var css_wrapper = ''; 148 var css_item = ''; 149 switch (layout) { 150 case '1 Column': 151 break; 152 case 'Bootstrap 2 Columns': 153 css_wrapper = 'row'; 154 css_item = 'col-12 col-md-6'; 155 break; 156 case 'Bootstrap 3 Columns': 157 css_wrapper = 'row'; 158 css_item = 'col-12 col col-md-6 col-lg-4'; 159 break; 160 case 'Bootstrap 4 Columns': 161 css_wrapper = 'row'; 162 css_item = 'col-12 col-md-6 col-lg-4 col-xl-3'; 163 break; 164 default: 165 break; 166 } 167 var image = Boolean(parseInt(value.attr('data-blog-image'))); 168 var link = Boolean(parseInt(value.attr('data-blog-link'))); 169 var description = Boolean(parseInt(value.attr('data-blog-description'))); 170 $.ajax({ 171 url: url, 172 dataType: 'xml' 173 }) 174 .done(function (data) { 175 var html = [], 176 i = 0; 177 value.addClass(css_wrapper); 178 $(data).find("item").each(function () { 179 if (start <= i) { 180 var item = $(this); 181 html.push('<div class="volt-recent-posts-item-wrapper ' + css_item + '"><div class="volt-recent-posts-item">'); 182 if (image && item.find('content\\:encoded').length > 0) { 183 html.push('<div class="volt-recent-posts-item-header">'); 184 if (link) { 185 html.push('<a href="' + item.find('link').text() + '">' + item.find('content\\:encoded').text() + '</a>'); 186 } else { 187 item.find('content\\:encoded').text() 188 } 189 html.push('</div>'); 190 } 191 html.push('<h3 class="volt-recent-posts-item-title mt-2">'); 192 if (link) { 193 html.push('<a class="volt-recent-posts-item-title-link" href="' + item.find('link').text() + '">' + item.find('title').text() + '</a>'); 194 } else { 195 html.push(item.find('title').text()); 196 } 197 html.push('</h3>'); 198 if (description) { 199 html.push('<div class="volt-recent-posts-item-body"><p>' + item.find('description').text() + '</p></div>'); 200 } 201 html.push('</div></div>'); 202 } 203 i++; 204 if (i === items) { 205 return false; 206 } 207 }); 208 var blogPage = value.attr('data-blog-page') 209 $('[data-blog-page="' + blogPage + '"]').html(html.join('')); 210 }); 211 }); 212 } 213 214 ////////////////////////////////////////////////// 215 // functions
216 ////////////////////////////////////////////////// 217 var initializeStoredImages = function () { 218 storedImages = []; 219 $.ajax({ 220 url: base_path, 221 data: { 222 api: 'image' 223 } 224 }) 225 .done(function (response) { 226 if (response && response.image) { 227 $.each(response.image, function (index, val) { 228 if (val.url) { 229 storedImages.push(val.url); 230 } 231 }); 232 } 233 }); 234 } 235 236 var initializeJSforContent = function () { 237 var voltGallery = $('.volt-gallery'); 238 if (voltGallery.length) { 239 voltGallery.each(function (index, value) { 240 // add id to all galleries for later accesss 241 var id = 'volt-gallery-' + index; 242 $(this).attr('id', id); 243 // check if attribute data-gallery-layout is existing, if not, add default value flexbox 244 if (!$(this).attr('data-gallery-layout')) { 245 $(this).attr('data-gallery-layout', 'flexbox'); 246 } 247 // if carousel, add max-heigth none to images 248 // build html for carousel 249 if ($(this).attr('data-gallery-layout') == 'carousel') { 250 $(this).addClass('carousel'); 251 $(this).addClass('slide'); 252 $(this).attr('data-ride', 'carousel'); 253 $(this).attr('data-bs-ride', 'carousel'); 254 var captions = false; 255 if (this.dataset.galleryLightboxCaptions == 1) { 256 captions = true; 257 } 258 var html = '<ol class="carousel-indicators">'; 259 var images = $(this).find('img'); 260 $(images).each(function (index, value) { 261 if (index == 0) { 262 html = html + '<li data-target="#' + id + '" data-bs-target="#' + id + '" data-slide-to="' + index + '" data-bs-slide-to="' + index + '" class="active"></li>'; 263 } else { 264 html = html + '<li data-target="#' + id + '" data-bs-target="#' + id + '" data-slide-to="' + index + '" data-bs-slide-to="' + index + '" class=""></li>'; 265 } 266 }); 267 html = html + '</ol><div class="carousel-inner" role="listbox">'; 268 $(images).each(function (index, value) { 269 if (index == 0) { 270 html = html + '<div class="carousel-item active">'; 271 } else { 272 html = html + '<div class="carousel-item">'; 273 } 274 var img = $(this), 275 href = img.attr('src'), 276 caption = img.attr('alt'); 277 html = html + '<img class="d-inline-block w-100 img-fluid" alt="' + caption + '" src="' + href + '">'; 278 if (captions) { 279 html = html + '<div class="carousel-caption d-none d-md-block"><p>' + caption + '</p></div>' 280 } 281 html = html + '</div>'; 282 }); 283 html = html + '</div></div><a class="carousel-nav-controls carousel-control-prev" href="#' + id + '" role="button" data-slide="prev" data-bs-slide="prev">' + 284 '<span class="fa fa-chevron-left"></span><span class="sr-only">Previous</span></a>' + 285 '<a class="carousel-nav-controls carousel-control-next" href="#' + id + '" role="button" data-slide="next" data-bs-slide="next">' + 286 '<span class="fa fa-chevron-right"></span><span class="sr-only">Next</span></a></div>'; 287 $(this).html(html); 288 $(this).carousel(); 289 } 290 // if not carousel, add attribute data-gallery-lightbox with value baguetteBox for later initialization 291 // build html for lightbox 292 if ($(this).attr('data-gallery-layout') !== 'carousel') { 293 $(this).attr('data-gallery-lightbox', 'baguetteBox'); 294 $(this).find('img').each(function () { 295 var img = $(this), 296 href = img.attr('src'), 297 caption = img.attr('alt'); 298 img.wrap('<a href="' + href + '" data-caption="' + caption + '"></a>'); 299 }); 300 } 301 }); 302 $('[data-gallery-lightbox="baguetteBox"]').each(function (index, value) { 303 var captions = false;
304 if (this.dataset.galleryLightboxCaptions == 1) { 305 captions = true; 306 } 307 baguetteBox.run('#' + this.id, { 308 captions: captions, 309 overlayBackgroundColor: lightbox_color, 310 noScrollbars: true 311 // animation: 'slideIn', 312 // filter: /.+\.(gif|jpe?g|png|webp)|unsplash/i 313 }); 314 }); 315 $('[data-gallery-layout="masonry"]').each(function (index, value) { 316 new Macy({ 317 container: '#' + this.id, 318 mobileFirst: true, 319 columns: 2, 320 margin: { 321 y: 10, 322 x: 10, 323 }, 324 breakAt: { 325 1200: 5, 326 992: 4, 327 768: 3, 328 576: 2 329 }, 330 }); 331 }); 332 } 333 334 var voltLightbox = $('.volt-lightbox'); 335 if (voltLightbox.length) { 336 voltLightbox.each(function () { 337 var img = $(this), 338 href = img.attr('src'), 339 caption = img.attr('alt'); 340 if (img.parent().parent().hasClass('volt-gallery')) { 341 img.removeClass('volt-lightbox'); 342 } else { 343 img.wrap('<div class="volt-lightbox"><a href="' + href + '" data-caption="' + caption + '"></a></div>'); 344 } 345 }); 346 baguetteBox.run('.volt-lightbox', { 347 captions: lightbox_captions, 348 overlayBackgroundColor: lightbox_color, 349 noScrollbars: true 350 }); 351 } 352 353 reframe('iframe[class*="volt-reframe"]'); 354 $('iframe[class*="volt-reframe"]').each(function(index, value) { 355 $(value.parentElement).addClass(value.className); 356 }); 357 358 $('body .img-protected').on('contextmenu', function (t) { 359 return !1 360 }), 361 $('.img-protected').mousedown(function (t) { 362 t.preventDefault() 363 }) 364 365 if ($('.twitter-tweet').length) { 366 jQuery.ajax({ 367 url: 'https://platform.twitter.com/widgets.js', 368 dataType: 'script', 369 async: true 370 }); 371 } 372 373 if ($('.instagram-media').length) { 374 jQuery.ajax({ 375 url: 'https://www.instagram.com/embed.js', 376 dataType: 'script', 377 async: true 378 }); 379 } 380 381 var hashIndex = window.location.href.indexOf('#'); 382 if (hashIndex > -1 && scrollToTarget) { 383 scrollToTarget(window.location.href.substring(hashIndex)); 384 } 385 386 } 387 388 var splitStyles = function (styles, tags) { 389 var result = []; 390 styles = styles.replace(blankRegex, '').split(','); 391 styles.forEach(function (value, index) { 392 if (value.indexOf(':') != -1) { 393 result.push(new ContentTools.Style(value.substring(0, value.indexOf(':')), value.substring(value.indexOf(':') + 1), tags)); 394 } else { 395 result.push(new ContentTools.Style(value, value, tags)); 396 } 397 }); 398 return result; 399 } 400 401 var initializeStyles = function () { 402 ContentTools.StylePalette.add([ 403 new ContentTools.Style(ContentEdit._('Margin medium'), 'mb-3', ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'li', 'ol', 'ul', 'img', 'iframe']), 404 new ContentTools.Style(ContentEdit._('Margin large'), 'mb-5', ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'li', 'ol', 'ul', 'img', 'iframe']), 405 new ContentTools.Style(ContentEdit._('Lightbox'), 'volt-lightbox', ['img']), 406 new ContentTools.Style(ContentEdit._('Image Protection'), 'img-protected', ['img']), 407 new ContentTools.Style(ContentEdit._('Responsive Video'), 'volt-reframe', ['iframe']) 408 ]); 409 if (styles_img) { 410 ContentTools.StylePalette.add(splitStyles(styles_img, ['img'])); 411 } 412 if (styles_p) { 413 ContentTools.StylePalette.add(splitStyles(styles_p, ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p'])); 414 } 415 } 416 417 var initializeEditor = function () {
418 ////////////////////////////////////////////////// 419 // editor styles and language configuration 420 ////////////////////////////////////////////////// 421 if (!editor) { 422 if (language != 'en') { 423 if (language == 'browser') { 424 if (navigator.language && navigator.language.length >= 2) { 425 language = navigator.language.substring(0, 2).toLowerCase(); 426 } else { 427 language == 'en'; 428 } 429 } 430 if (language != 'en') { 431 $.ajax({ 432 url: '/js/volt-editor-i18n.json', 433 dataType: 'json' 434 }) 435 .done(function (response) { 436 if (response.hasOwnProperty(language)) { 437 ContentEdit.addTranslations(language, response[language]); 438 ContentEdit.LANGUAGE = language; 439 initializeStyles(); 440 } 441 }); 442 } else { 443 initializeStyles(); 444 } 445 } else { 446 initializeStyles(); 447 } 448 } 449
450 ////////////////////////////////////////////////// 451 // editor initialization 452 ////////////////////////////////////////////////// 453 editor = ContentTools.EditorApp.get(); 454 455 // Triggered when the editor saves the page. The event includes the passive key/value. 456 editor.addEventListener('saved', function (ev) { 457 var name, payload, regions, passive, xhr; 458 459 // Check that something changed 460 regions = ev.detail().regions; 461 passive = ev.detail().passive; 462 var regionsChanged = Object.keys(regions).length > 0; 463 if (!regionsChanged && !blogModalActive) { 464 return; 465 } 466 467 var blogItem; 468 if (blogModalActive) { 469 if (validateBlogItemInput()) { 470 blogItem = {}; 471 blogItem['volt-blog-item-title'] = $('[data-name=volt-blog-item-title]').val(); 472 if ($('.volt-blog-modal').attr('data-item-id')) { 473 blogItem['volt-blog-item-id'] = $('.volt-blog-modal').attr('data-item-id'); 474 } 475 blogItem['volt-blog-item-blog-id'] = $('.volt-blog').attr('data-blog-id'); 476 blogItem['volt-blog-item-slug'] = $('[data-name=volt-blog-item-slug]').val(); 477 blogItem['volt-blog-item-date'] = $('[data-name=volt-blog-item-date]').val() + 'T' + $('[data-name=volt-blog-item-time]').val(); 478 blogItem['volt-blog-item-draft'] = $('[data-name=volt-blog-item-draft]').prop('checked'); 479 blogItem['volt-blog-item-categories'] = $('[data-name=volt-blog-item-categories]').val(); 480 blogItem['volt-blog-item-authors'] = $('[data-name=volt-blog-item-authors]').val(); 481 blogItem['volt-blog-item-description'] = $('[data-name=volt-blog-item-description]').val(); 482 var tempRegions; 483 if (passive && editor.history._snapshots.length > 0) { 484 tempRegions = editor.history._snapshots[editor.history._snapshotIndex].regions; 485 } else { 486 passive = false; 487 } 488 if (regions['volt-blog-item-header']) { 489 if (emptyParagraphRegex.test(regions['volt-blog-item-header'])) { 490 blogItem['volt-blog-item-header'] = ''; 491 } else { 492 blogItem['volt-blog-item-header'] = regions['volt-blog-item-header']; 493 } 494 } else if (passive && tempRegions['volt-blog-item-header']) { 495 if (emptyParagraphRegex.test(tempRegions['volt-blog-item-header'])) { 496 blogItem['volt-blog-item-header'] = ''; 497 } else { 498 blogItem['volt-blog-item-header'] = tempRegions['volt-blog-item-header']; 499 } 500 } 501 if (regions['volt-blog-item-summary']) { 502 blogItem['volt-blog-item-summary'] = regions['volt-blog-item-summary']; 503 } else if (passive && tempRegions['volt-blog-item-summary']) { 504 blogItem['volt-blog-item-summary'] = tempRegions['volt-blog-item-summary']; 505 } 506 if (regions['volt-blog-item-main']) { 507 blogItem['volt-blog-item-main'] = regions['volt-blog-item-main']; 508 } else if (passive && tempRegions['volt-blog-item-main']) { 509 blogItem['volt-blog-item-main'] = tempRegions['volt-blog-item-main']; 510 } 511 } 512 } 513 514 if (regionsChanged || blogItem) { 515 // Set the editor as busy while we save our changes 516 this.busy(true); 517 518 if (regionsChanged) { 519 // Collect the contents of each region into a FormData instance 520 payload = new FormData();
521 for (name in regions) { 522 if (regions.hasOwnProperty(name)) { 523 payload.append(volt_content + name, regions[name]); 524 } 525 } 526 $.ajax({ 527 type: 'POST', 528 url: base_path + '?api=content', 529 data: payload, 530 contentType: false, 531 processData: false 532 }) 533 .done(function () { 534 editor.busy(false); 535 new ContentTools.FlashUI('ok'); 536 }) 537 .fail(function () { 538 editor.busy(false); 539 new ContentTools.FlashUI('no'); 540 }); 541 } 542 543 if (blogItem) { 544 $.ajax({ 545 type: 'POST', 546 url: base_path + '?api=blog', 547 data: blogItem, 548 }) 549 .done(function (response) { 550 if (ev._detail.passive) { 551 editor.busy(false); 552 new ContentTools.FlashUI('ok'); 553 $('.volt-blog-modal').attr('data-item-id', response._id); 554 } else { 555 location.reload(); 556 } 557 }) 558 .fail(function () { 559 editor.busy(false); 560 new ContentTools.FlashUI('no'); 561 }); 562 } 563 } 564 565 }); 566 567 // Triggered when the editor is started. 568 editor.addEventListener('start', function (ev) { 569 if (blogModalActive) { 570 $('.ct-ignition__button--blog').hide(); 571 $('.volt-blog-item-action a').css('display', 'none'); 572 } 573 }); 574 575 // Triggered when the editor is stopped. The event includes the save key/value. 576 editor.addEventListener('stop', function (ev) { 577 if (blogModalActive) { 578 $('.ct-ignition__button--blog').css('display', 'block') 579 $('.volt-blog-item-action a').fadeIn('slow').css('display', 'inline-block'); 580 } 581 }); 582 583 // upload image 584 ContentTools.IMAGE_UPLOADER = function (dialog) { 585 var image, xhr, xhrComplete, xhrProgress; 586 587 if (storedImages) { 588 dialog.addImages(storedImages); 589 } 590 591 // Set up the event handlers 592 dialog.addEventListener('imageuploader.cancelupload', function () { 593 // Cancel the current upload 594 595 // Stop the upload 596 if (xhr) { 597 xhr.upload.removeEventListener('progress', xhrProgress); 598 xhr.removeEventListener('readystatechange', xhrComplete); 599 xhr.abort(); 600 } 601 602 // Set the dialog to empty 603 dialog.state('empty'); 604 }); 605 606 // delete image 607 dialog.addEventListener('imageuploader.clear', function () { 608 var name = this._imageURL.substring(this._imageURL.lastIndexOf('/') + 1); 609 $.ajax({ 610 type: 'DELETE', 611 url: base_path + '?api=image&name=' + name 612 }); 613 614 // Clear the current image 615 dialog.clear(); 616 image = null; 617 }); 618 619 // upload image 620 dialog.addEventListener('imageuploader.fileready', function (ev) { 621 622 // Upload a file to the server 623 var formData; 624 var file = ev.detail().file; 625 626 // Define functions to handle upload progress and completion 627 xhrProgress = function (ev) { 628 // Set the progress for the upload 629 dialog.progress((ev.loaded / ev.total) * 100); 630 } 631 632 xhrComplete = function (ev) { 633 var response; 634 635 // Check the request is complete 636 if (ev.target.readyState != 4) { 637 return; 638 } 639 640 // Clear the request 641 xhr = null 642 xhrProgress = null 643 xhrComplete = null 644 645 // Handle the result of the upload 646 if (parseInt(ev.target.status) == 200) {
647 // Unpack the response (from JSON) 648 response = JSON.parse(ev.target.responseText); 649 650 // Store the image details 651 image = { 652 size: response.size, 653 url: response.url 654 }; 655 656 // Populate the dialog 657 dialog.populate(image.url, image.size); 658 659 } else { 660 // The request failed, notify the user 661 new ContentTools.FlashUI('no'); 662 } 663 } 664 665 // Set the dialog state to uploading and reset the progress bar to 0 666 dialog.state('uploading'); 667 dialog.progress(0); 668 669 // Build the form data to post to the server 670 formData = new FormData(); 671 formData.append('image', file); 672 673 // Make the request 674 xhr = new XMLHttpRequest(); 675 xhr.upload.addEventListener('progress', xhrProgress); 676 xhr.addEventListener('readystatechange', xhrComplete); 677 xhr.open('POST', base_path + '?api=image', true); 678 xhr.send(formData); 679 }); 680 681 // insert image 682 dialog.addEventListener('imageuploader.save', function () { 683 dialog.save(this._imageURL, this._imageSize, { 684 'alt': this._imageURL.substring(this._imageURL.lastIndexOf('/') + 1, this._imageURL.lastIndexOf('.')) 685 }); 686 initializeStoredImages(); 687 }); 688 689 } 690 } 691 692 ////////////////////////////////////////////////// 693 // content regions highlighting 694 ////////////////////////////////////////////////// 695 var loadContentJS = function (authorization_editor) { 696 var load = []; 697 $('.volt-content').each(function (index, element) { 698 if (element.dataset.name) { 699 load.push( 700 $.ajax({ 701 url: base_path, 702 data: { 703 api: 'content', 704 name: element.dataset.name 705 } 706 }) 707 .done(function (response) { 708 element.innerHTML = response; 709 }) 710 ); 711 } 712 }); 713 if (!authorization_editor) { 714 if (load.length > 0) { 715 $.when.apply($, load).then(initializeJSforContent); 716 } else if (blogActive) { 717 initializeJSforContent(); 718 } 719 } 720 } 721 722 var loadBlogJS = function () { 723 $('.volt-blog').each(function (index, element) { 724 $.ajax({ 725 url: base_path, 726 data: { 727 'api': 'blog', 728 'blog-id': element.dataset.blogId, 729 'blog-items': element.dataset.blogItems, 730 'blog-layout': element.dataset.blogLayout, 731 'blog-date-pattern': element.dataset.blogDatePattern, 732 'blog-hide-future-items': element.dataset.blogHideFutureItems, 733 'blog-author-text': element.dataset.blogAuthorText, 734 'blog-category-text': element.dataset.blogCategoryText, 735 'blog-tag-text': element.dataset.blogTagText, 736 'blog-separator-text': element.dataset.blogSeparatorText, 737 'blog-readmore-text': element.dataset.blogReadmoreText, 738 'blog-back-text': element.dataset.blogBackText, 739 'blog-prev-post-text': element.dataset.blogPrevPostText, 740 'blog-next-post-text': element.dataset.blogNextPostText, 741 'blog-prev-page-text': element.dataset.blogPrevPageText, 742 'blog-next-page-text': element.dataset.blogNextPageText, 743 'blog-heading-list': element.dataset.blogHeadingList, 744 'blog-heading-detail': element.dataset.blogHeadingDetail, 745 'blog-metadata-display': element.dataset.blogMetadataDisplay, 746 'blog-share-display': element.dataset.blogShareDisplay 747 } 748 }) 749 .done(function (response) { 750 element.innerHTML = response; 751 }) 752 }); 753 } 754 755 var afterEditorInit = function () { 756 $('.volt-content').each(function (index, element) { 757 if (!element.dataset.name) { 758 delete element.dataset.editable; 759 if (element.className.indexOf('gallery') !== -1) { 760 element.dataset.error = 'Gallery Name Missing'; 761 } else { 762 element.dataset.error = 'Content Name Missing'; 763 } 764 } 765 }); 766 $('.volt-content').each(function (index, element) { 767 if (element.dataset.name) { 768 $(element).addClass('volt-content-editor-start'); 769 } else { 770 $(element).addClass('volt-content-editor-error'); 771 } 772 }); 773 $('.ct-ignition__button--logout').click(function (e) { 774 performLogout(e); 775 }); 776 if (blogModalActive) { 777 $('.volt-blog-modal').parent().addClass('modal-xl'); 778 if ($('[data-name=volt-blog-item-time]').length) { 779 $('[data-name=volt-blog-item-time]').prop('type', 'time'); 780 } 781 // must be called in after init 782 $('.volt-blog-item').each(function (index, el) { 783 if ($(this).attr('data-item-readonly')) { 784 $(this).append('<div class="volt-blog-item-action mt-2"><a class="volt-blog-item-copy" data-name="volt-blog-item-copy"></a></div>'); 785 } else { 786 $(this).append('<div class="volt-blog-item-action mt-2"><a class="volt-blog-item-edit" data-name="volt-blog-item-edit"></a><a class="volt-blog-item-delete" data-name="volt-blog-item-delete"></a><a class="volt-blog-item-copy" data-name="volt-blog-item-copy"></a></div>'); 787 } 788 }); 789 $('.ct-ignition__button--blog').show(); 790 $('.volt-blog-item-action a').fadeIn('slow').css('display', 'inline-block'); 791 $('.ct-ignition__button--blog').click(function (e) { 792 createBlogItem(e); 793 }); 794 $('[data-name=volt-blog-item-edit]').click(function (e) { 795 editBlogItem(e); 796 }); 797 $('[data-name=volt-blog-item-delete]').click(function (e) { 798 deleteBlogItem(e); 799 }); 800 $('[data-name=volt-blog-item-copy]').click(function (e) { 801 copyBlogItem(e); 802 }); 803 $('[data-name=volt-blog-item-save]').click(function (e) { 804 saveBlogItem(e, true); 805 }); 806 $('[data-name=volt-blog-item-save-close]').click(function (e) { 807 saveBlogItem(e, false); 808 }); 809 $('[data-name=volt-blog-item-cancel]').click(function (e) { 810 cancelBlogItem(e); 811 }); 812 } 813 } 814
815 ////////////////////////////////////////////////// 816 // login and logout forms 817 ////////////////////////////////////////////////// 818 var toggleLoginForm = function (showLoginForm, showLogoutForm, showAlert, username) { 819 if (showLoginForm) { 820 $('.volt-login-form').show(); 821 } else { 822 $('.volt-login-form').hide(); 823 } 824 if (showLogoutForm) { 825 $('.volt-logout-form').show(); 826 } else { 827 $('.volt-logout-form').hide(); 828 } 829 if (showAlert) { 830 $('.volt-login-alert').show(); 831 } else { 832 $('.volt-login-alert').hide(); 833 } 834 if (username) { 835 $('.volt-login-username').show(); 836 } else { 837 $('.volt-login-username').hide(); 838 } 839 $('.volt-login-username').text(username); 840 } 841 842 var performLogin = function (e) { 843 e.stopPropagation(); 844 e.preventDefault(); 845 var username = $('[name=username]').val(); 846 var password = $('[name=password]').val(); 847 $.ajax({ 848 type: 'POST', 849 url: base_path, 850 data: { 851 api: 'login', 852 username: username, 853 password: password 854 }, 855 dataType: 'json', 856 beforeSend: function (request) { 857 // send csrf token 858 request.setRequestHeader("X-CSRF-Token", csrfToken); 859 } 860 }) 861 .done(function (response) { 862 if (response.login) { 863 if (location.search.indexOf('ref') != -1) { 864 window.location.href = location.search.substring(location.search.indexOf('ref=') + 4) 865 } else if (redirect_root) { 866 window.location.href = '/'; 867 } else { 868 location.reload(); 869 } 870 } 871 }) 872 .fail(function (response) { 873 login = false; 874 toggleLoginForm(true, false, true, response.username); 875 }); 876 } 877 878 var performLogout = function (e) { 879 e.stopPropagation(); 880 e.preventDefault(); 881 $.ajax({ 882 type: 'POST', 883 url: base_path, 884 data: { 885 api: 'logout' 886 }, 887 dataType: 'json' 888 }) 889 .always(function () { 890 location.reload(); 891 }); 892 } 893 894 $('[name=submit_login]').click(function (e) { 895 performLogin(e); 896 }); 897 $('[name=username]').keypress(function (e) { 898 if (e.which == 13) { 899 performLogin(e); 900 } 901 }); 902 $('[name=password]').keypress(function (e) { 903 if (e.which == 13) { 904 performLogin(e); 905 } 906 }); 907 $('[name=submit_logout]').click(function (e) { 908 performLogout(e); 909 }); 910 911 ////////////////////////////////////////////////// 912 // blog 913 ////////////////////////////////////////////////// 914 var createBlogItem = function (e) { 915 var date = new Date(); 916 $('[data-name=volt-blog-item-date]').val(getDateString(date)); 917 $('[data-name=volt-blog-item-time]').val(getTimeString(date)); 918 $('.ct-ignition').hide(); 919 if (!editor.isEditing()) { 920 editor.start(); 921 } 922 showBlogModal(); 923 } 924 925 var editBlogItem = function (e) { 926 $.ajax({ 927 url: base_path, 928 data: { 929 api: 'blog', 930 'blog-id': $('.volt-blog').attr('data-blog-id'), 931 id: e.target.parentElement.parentElement.dataset.itemId 932 } 933 }) 934 .done(function (response) { 935 loadBlogItemInput(response); 936 $('.ct-ignition').hide(); 937 if (!editor.isEditing()) { 938 editor.start(); 939 } 940 showBlogModal(); 941 }) 942 } 943 944 var deleteBlogItem = function (e) { 945 var result = confirm("Delete Post?"); 946 if (result) { 947 $.ajax({ 948 type: 'DELETE', 949 url: base_path + '?api=blog&blog-id=' + $('.volt-blog').attr('data-blog-id') + '&id=' + e.target.parentElement.parentElement.dataset.itemId 950 }) 951 .done(function () { 952 location.reload(); 953 }) 954 .fail(function () { 955 new ContentTools.FlashUI('no'); 956 }); 957 } 958 } 959 960 var saveBlogItem = function (e, passive) { 961 if (passive) { 962 editor.save(true); 963 } else { 964 editor.stop(true); 965 } 966 } 967 968 var cancelBlogItem = function (e) { 969 var result = editor.stop(false); 970 if (result) { 971 location.reload(); 972 } 973 } 974 975 var copyBlogItem = function (e) { 976 $.ajax({ 977 url: base_path, 978 data: { 979 api: 'blog', 980 'blog-id': $('.volt-blog').attr('data-blog-id'), 981 id: e.target.parentElement.parentElement.dataset.itemId 982 } 983 }) 984 .done(function (response) { 985 delete response._id; 986 response.title = response.title + ' - Copy'; 987 var date = new Date(); 988 response.date = getDateString(date) + 'T' + getTimeString(date); 989 loadBlogItemInput(response); 990 $('.ct-ignition').hide(); 991 if (!editor.isEditing()) { 992 editor.start(); 993 } 994 var modified = new Date().getTime(); 995 if (editor.regions()['volt-blog-item-header']) { 996 editor.regions()['volt-blog-item-header']._modified = modified; 997 } 998 if (editor.regions()['volt-blog-item-summary']) { 999 editor.regions()['volt-blog-item-summary']._modified = modified; 1000 } 1001 if (editor.regions()['volt-blog-item-main']) { 1002 editor.regions()['volt-blog-item-main']._modified = modified; 1003 } 1004 showBlogModal(); 1005 }); 1006 } 1007 1008 var showBlogModal = function () { 1009 $('[data-name=volt-blog-item-title]').removeClass('is-invalid'); 1010 $('[data-name=volt-blog-item-date]').removeClass('is-invalid'); 1011 $('[data-name=volt-blog-item-time]').removeClass('is-invalid'); 1012 blogModal.show(); 1013 } 1014 1015 var hideBlogModal = function () { 1016 blogModal.hide(); 1017 } 1018 1019 var clearBlogItemInput = function () { 1020 $('[data-name=volt-blog-item-title]').val(''); 1021 $('[data-name=volt-blog-item-slug]').val(''); 1022 $('[data-name=volt-blog-item-date]').val(''); 1023 $('[data-name=volt-blog-item-time]').val(''); 1024 $('[data-name=volt-blog-item-draft]').prop('checked', false); 1025 $('[data-name=volt-blog-item-categories]').val(''); 1026 $('[data-name=volt-blog-item-authors]').val(''); 1027 $('[data-name=volt-blog-item-description]').val(''); 1028 $('[data-name=volt-blog-item-header]').html(''); 1029 $('[data-name=volt-blog-item-summary]').html(''); 1030 $('[data-name=volt-blog-item-main]').html(''); 1031 } 1032 1033 var loadBlogItemInput = function (data) { 1034 if (data._id) { 1035 $('.volt-blog-modal').attr('data-item-id', data._id); 1036 } else { 1037 $('.volt-blog-modal').removeAttr('data-item-id'); 1038 } 1039 $('[data-name=volt-blog-item-title]').val(data.title); 1040 $('[data-name=volt-blog-item-slug]').val(data.slug); 1041 $('[data-name=volt-blog-item-date]').val(data.date.substring(0, 10)); 1042 $('[data-name=volt-blog-item-time]').val(data.date.substring(11, 16)); 1043 if (data.draft === 'true') { 1044 $('[data-name=volt-blog-item-draft]').prop('checked', true); 1045 } 1046 $('[data-name=volt-blog-item-categories]').val(data.categories); 1047 $('[data-name=volt-blog-item-authors]').val(data.authors); 1048 $('[data-name=volt-blog-item-description]').val(data.description); 1049 if (data.header) { 1050 $('[data-name=volt-blog-item-header]').html(data.header); 1051 } 1052 if (data.summary) { 1053 $('[data-name=volt-blog-item-summary]').html(data.summary); 1054 } 1055 if (data.main) { 1056 $('[data-name=volt-blog-item-main]').html(data.main); 1057 } 1058 } 1059
1060 var validateBlogItemInput = function (e) { 1061 var result = true; 1062 if ($('[data-name=volt-blog-item-title]')[0].checkValidity() && $('[data-name=volt-blog-item-title]').val().trim().length !== 0) { 1063 $('[data-name=volt-blog-item-title]').removeClass('is-invalid'); 1064 } else { 1065 result = false; 1066 $('[data-name=volt-blog-item-title]').addClass('is-invalid'); 1067 } 1068 if ($('[data-name=volt-blog-item-date]')[0].checkValidity() && $('[data-name=volt-blog-item-date]').val().trim().length === 10) { 1069 $('[data-name=volt-blog-item-date]').removeClass('is-invalid'); 1070 } else { 1071 result = false; 1072 $('[data-name=volt-blog-item-date]').addClass('is-invalid'); 1073 } 1074 if ($('[data-name=volt-blog-item-time]')[0].checkValidity() && $('[data-name=volt-blog-item-time]').val().trim().length === 5) { 1075 $('[data-name=volt-blog-item-time]').removeClass('is-invalid'); 1076 } else { 1077 result = false; 1078 $('[data-name=volt-blog-item-time]').addClass('is-invalid'); 1079 } 1080 return result; 1081 } 1082 1083 var padLeadingZero = function (string) { 1084 string = string + ''; 1085 if (string.length === 1) { 1086 return '0' + string; 1087 } 1088 return string; 1089 } 1090 1091 var getDateString = function (date) { 1092 return padLeadingZero(date.getUTCFullYear()) + '-' + padLeadingZero(date.getMonth() + 1) + '-' + padLeadingZero(date.getDate()); 1093 } 1094 1095 var getTimeString = function (date) { 1096 return padLeadingZero(date.getHours()) + ':' + padLeadingZero(date.getMinutes()); 1097 } 1098 1099});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.