PageSourceSearch

https://gadsdenstate.edu/admin/plugins/news-press/pkg/js/news-press.js

js gadsdenstate.edu collected 2026-10-01 12:33:15 UTC 24,248 bytes, 582 lines download raw bytes

1/* ==========================================================================
2   Project:     TWD CMS 7 - News & Press
3   Date:        06/11/20 - File created
4   Created by:  Third Wave Digital (www.thirdwavedigital.com)
5   ========================================================================== */
6
7   var cmsNewsPress = function() {
8     var $newspressList = $(".cms-newspress-list"),
9      $newspressProfile = $(".cms-newspress-profile"),
10      $newspressAddEdit = $(".cms-newspress-addedit"),
11      $newspressTags = $(".cms-newspress-tags"),
12      $newspressCategories = $(".cms-newspress-categories"),
13      $newspressCategoryDetails = $(".cms-newspress-category-details"),
14      $newspressMain = $(".cms-newspress-main"),
15      $newspressSettings = $("[class*='cms-newspress-settings']"),
16      $newspressMasonry = $(".cms-newspress-masonry");
17      
18 /* ==========================================================================
19      News & Press List
20 ========================================================================== */   
21 
22 if ($newspressList.length) {
23
24      // Querystring?
25      if (getParameterByName("category") != "") {
26           localStorage.removeItem("cms-newspress-list-tab");
27           var $newspressTable = $newspressList.find("table").dataTable();
28           $newspressTable.fnFilter(getParameterByName("category"));
29      }
30 
31      if (getParameterByName("published") != "") {
32           localStorage.removeItem("cms-newspress-list-tab");
33           var tab = getParameterByName("published") == "1" ? "newspress-published" : "newspress-unpublished";
34           $newspressList.find(".nav-link").removeClass("active").end()
35                .find(".tab-pane").removeClass("show active").end()
36                .find(".cms-nav-tabs a[href='#" + tab + "']").tab("show");
37      }
38 
39      // Retain Tab State
40      var activeTab = localStorage.getItem("cms-newspress-list-tab");
41      
42      $newspressList.find("a[data-toggle='tab']").on("show.bs.tab", function(e) {
43           localStorage.setItem("cms-newspress-list-tab", $(e.target).attr("href"));
44      })
45           
46      if(activeTab) {
47           $newspressList.find(".nav-link").removeClass("active").end()
48                .find(".tab-pane").removeClass("show active").end()
49                .find(".cms-nav-tabs a[href='" + activeTab + "']").tab("show");
50      }
51 
52      // Delete
53      $newspressList.find(".btn-delete").on("click",function(e) {
54           var id = $(this).data('news_pk');
55           bootbox.confirm({
56                message: "Are you sure you want to delete this news article?",
57                buttons: {
58                     confirm: {
59                          label: "Yes"
60                     },
61                     cancel: {
62                          label: "No",
63                          className: "btn-secondary"
64                     }
65                },
66                callback: function (result) {
67                     if( result ) {
68                          window.location.assign('index.cms?delete_id='+id);
69                     }
70                }
71           })
72      })
73
74      // Datatables
75      $newspressList.find(".newspress-published, .newspress-unpublished").dataTable( {
76          "aaSorting": [[2,"desc"]],
77          "aoColumns" : [{"bSortable":false},null,null,{"bSortable":false}],
78          "columnDefs": [
79               { "type": "date", "targets":2 }
80             ],
81             "aLengthMenu": [[20, 100, -1], [20, 100, "All"]],
82             "iDisplayLength" : 20,
83             "autoWidth": false
84     })
85 
86 }
87 
88 /* ==========================================================================
89      News & Press Tags
90 ========================================================================== */   
91 
92 if ($newspressTags.length) {
93      // Title
94      $newspressTags.find(".btn-edit").on("click",function(e) {
95           $newspressTags.find("table .flex-row.d-none").removeClass("d-none").addClass("d-flex").end()
96                .find("table .input-group").addClass("d-none");
97 
98           $(this).parent().removeClass("d-flex").addClass("d-none").end()
99                .parent().next(".input-group").removeClass("d-none");
100      })
101 
102      // Delete
103      $newspressTags.find(".btn-delete").on("click",function(e) {
104           var id = $(this).data('tag_pk');
105           bootbox.confirm({
106                message: "Are you sure you want to delete this tag?",
107                buttons: {
108                     confirm: {
109                          label: "Yes"
110                     },
111                     cancel: {
112                          label: "No",
113                          className: "btn-secondary"
114                     }
115                },
116                callback: function (result) {
117                     if( result ) {
118                          window.location.assign('tags.cms?delete_id='+id);
119                     }
120                }
121           })
122      })
123
124      // Datatable
125      $newspressTags.find("table").dataTable( {
126          "aaSorting": [[0,"asc"]],
127          "aoColumns" : [null,null,{"bSortable":false}],
128          "aLengthMenu": [[20, 100, -1], [20, 100, "All"]],
129            "iDisplayLength" : 20
130     })	
131 }
132 
133 /* ==========================================================================
134      News & Press Categories
135 ========================================================================== */   
136 
137 if ($newspressCategories.length) {
138     
139      // Feature
140      $newspressCategories.find(".btn-feature").on("click",function(e) {
141           $newspressCategories.find(".btn-feature span").removeClass("fas text-primary").addClass("far text-muted");
142           $(this).find("span").removeClass("far text-muted").addClass("fas text-primary").end()
143                .tooltip("hide");
144      })
145 
146      // Delete
147      $newspressCategories.find(".btn-delete").on("click",function(e) {
148           var id = $(this).data('cat_pk');
149           bootbox.confirm({
150                message: "Are you sure you want to delete this category?",
151                buttons: {
152                     confirm: {
153                          label: "Yes"
154                     },
155                     cancel: {
156                          label: "No",
157                          className: "btn-secondary"
158                     }
159                },
160                callback: function (result) {
161                     if( result ) {
162                          window.location.assign('categories.cms?delete_id='+id);
163                     }
164                }
165           })
166      })
167 
168      // File Upload
169      $newspressCategories.find(".custom-file-input").on("change",function(e) {
170           if (e.target.files[0] !== undefined) {
171                $(this).parent().find(".custom-file-label").html(e.target.files[0].name);
172                $(this).valid();
173           }
174      })
175 
176      // Popover
177      $("[data-toggle='popover']").popover({
178           trigger: "focus",
179           placement: "right",
180           html: true,
181           content: function () {
182                return "<img class='img-fluid' src='"+$(this).find('img').attr('src') + "' />";
183           }
184      })
185
186      // Datatable
187      $newspressCategories.find("table").dataTable( {
188          "aaSorting": [[1,"asc"]],
189          "aoColumns" : [{"bSortable":false},null,null,{"bSortable":false}],
190          "aLengthMenu": [[20, 100, -1], [20, 100, "All"]],
191          "iDisplayLength" : 20
192     })	
193   
194 }
195 
196 /* ==========================================================================
197      News & Press Categories
198 ========================================================================== */   
199 
200 if ($newspressCategoryDetails.length) {
201      // File Upload
202      $newspressCategoryDetails.find(".custom-file-input").on("change",function(e) {
203           if (e.target.files[0] !== undefined) {
204                $(this).parent().find(".custom-file-label").html(e.target.files[0].name);
205                $(this).valid();
206           }
207      })
208 
209      // Validate
210      $newspressCategoryDetails.find("form").validate({
211 
212      })
213 }
214 
215 /* ==========================================================================
216      News & Press Profile
217 ========================================================================== */   
218 
219 if ($newspressProfile.length) {
220      // Ckeditor
221      var editor = CKEDITOR.replace("setting_boilerplate", {})
222           
223      editor.config.forcePasteAsPlainText = true;
224      editor.config.height = 200;
225      editor.config.allowedContent = true;
226      editor.config.scayt_autoStartup = true;
227      editor.config.protectedSource.push(/<span[^>]*><\/span>/g);
228      editor.config.extraPlugins = 'balloonpanel,a11ychecker,cmslink';
229      editor.config.removePlugins = 'link,scayt';
230 
231      // Validate
232      $newspressProfile.find("form:not('#boilerplateform')").validate({
233 
234      })
235 
236      // Retain Tab State
237      var activeTab = localStorage.getItem("cms-newspress-profile-tab");
238 
239      $newspressProfile.find("a[data-toggle='tab']").on("show.bs.tab", function(e) {
240           localStorage.setItem("cms-newspress-profile-tab", $(e.target).attr("href"));
241      })
242 
243      if(activeTab) {
244      $newspressProfile.find(".nav-link").removeClass("active").end()
245           .find(".tab-pane").removeClass("show active").end()
246           .find(".cms-nav-tabs a[href='" + activeTab + "']").tab("show");
247      }
248 
249      // Delete
250      $newspressProfile.find(".btn-delete").on("click",function(e) {
251           var id = $(this).data('contact_pk');
252           bootbox.confirm({
253                message: "Are you sure you want to delete this contact?",
254                buttons: {
255                     confirm: {
256                          label: "Yes"
257                     },
258                     cancel: {
259                          label: "No",
260                          className: "btn-secondary"
261                     }
262                },
263                callback: function (result) {
264                     if( result ) {
265                          window.location.assign('profiles.cms?delete_id='+id);
266                     }
267                }
268           })
269      })
270
271     // Datatables
272     $newspressProfile.find(".newspress-mediacontacts").dataTable( {
273     "aaSorting": [[0,"asc"]],
274     "aoColumns" : [null,{"bSortable":false}],
275     "aLengthMenu": [[20, 100, -1], [20, 100, "All"]],
276     "iDisplayLength" : 20
277     })
278 }
279 
280 /* ==========================================================================
281      News & Press Add/Edit
282 ========================================================================== */   
283 
284 if ($newspressAddEdit.length) {
285      // Date   val(moment().format("MM-DD-YYYY")).
286      $newspressAddEdit.find(".datepicker").bootstrapMaterialDatePicker({
287           date: true,
288           time: false,
289           format: "MM-DD-YYYY",
290           clearButton: true
291      })
292 
293      // Time   val(moment().format("h:mm A")).
294      $newspressAddEdit.find(".timepicker").bootstrapMaterialDatePicker({
295           date: false,
296           time: true,
297           shortTime: true,
298           format: "h:mm A",
299           clearButton: true
300      })
301 
302      // Maxlength
303      $newspressAddEdit.find("[minlength],[maxlength]").maxlength({
304           alwaysShow: true,
305           warningClass: "form-text text-muted",
306           limitReachedClass: "form-text text-muted",
307           placement: "top-right-inside"
308      })
309 
310     $newspressAddEdit.find("input[name='news_title']").on("keyup",function(e) {
311          var val = $(this).val();  
312          $newspressAddEdit.find("input[name='news_slug']").val(formatPermalink(val)).trigger('change');
313     });
314
315     $newspressAddEdit.find("input[name='news_slug']").on("input change blur focus", function(e) {
316          var val = formatPermalink($(this).val());
317          $(this).val(val);
318          
319          var val = $(this).val();
320          // check if the slug is unique, and note the field if it's not
321          var uniqueCheckParams = {
322               method: 'isSlugUnique',
323               slug: val,
324               news_pk: $newspressAddEdit.find('input[name="news_pk"]').val(),
325               returnFormat: 'json'
326          };
327
328          // this endpoint will return either true or false, true if it is unique or false otherwise
329          $.get('/admin/plugins/news-press/pkg/com/news.cfc', uniqueCheckParams, function (data, textStatus, jqXHR) {
330               var isUnique = JSON.parse(data);
331               // added to squelch when several attempts are made with a non-unique value
332               $("#news_slug-error").addClass("d-none");
333               var validator = $newspressAddEdit.find('form:first').validate();
334               if( !isUnique ) {
335                    validator.showErrors({
336                         "news_slug": "Slug is not unique."
337                    });
338               } else {
339                    validator.resetForm();
340              }
341          });
342     })
343
344     var formatPermalink = function(val) {
345          // Create url friendly value
346          val = val.trim().replace(/[^a-zA-Z0-9-_]/g, '-');
347           
348          // account for multiple instances of -
349          var cont = val.indexOf('--');
350          while (cont > -1) {
351               val = val.replace('--','-');
352               cont = val.indexOf('--');		 	
353          }
354          // make sure the first character is not -
355          var strip = (val.charAt(0) == '-');
356          while(strip) {
357               val = val.slice(1);
358               strip = (val.charAt(0) == '-')
359          }
360           
361          // lower case the return
362          val = val.toLowerCase();
363          
364          return val;
365     }
366
367      // Validate
368      $newspressAddEdit.find("form").validate({
369 
370      })
371 
372      // Ckeditor
373      var editor = CKEDITOR.replace("news_content", {
374           on: {
375                contentDom: loadAssets
376           }
377      })
378                
379      function loadAssets(event) {
380           if (event.editor.mode != 'source') {
381                     var editorHead = event.editor.document.$.head,
382                          jQuery = document.createElement('script'),
383                          bootstrapJs = document.createElement('script'),
384                          cmstabsJs = document.createElement('script');
385 
386                     jQuery.src = '/admin/assets/js/vendor/jquery-1.11.0.min.js';
387                     bootstrapJs.src = '/admin/assets/js/vendor/bootstrap/js/bootstrap.min.js';
388                     cmstabsJs.src = '/admin/assets/js/vendor/ckeditor/plugins/cmstabs/js/bootstrap.tabs.custom.js';
389 
390                editorHead.appendChild(jQuery);
391 
392                jQuery.onload = function() {
393                          editorHead.appendChild(bootstrapJs);
394                          editorHead.appendChild(cmstabsJs);
395                }
396           }
397      };
398           
399      editor.config.forcePasteAsPlainText = true;
400      editor.config.height = 500;
401      editor.config.contentsCss = ['/admin/assets/js/vendor/bootstrap/css/bootstrap.min.css','/admin/assets/css/fontawesome/css/all.min.css','/css/main.css','/skins/cmsdefault/editor/style.css'];
402      editor.config.bodyClass = "container-fluid";
403      editor.config.allowedContent = true;
404      //editor.config.scayt_autoStartup = true;
405      editor.config.protectedSource.push(/<span[^>]*><\/span>/g);
406      editor.config.filebrowserBrowseUrl 		= '/admin/assets/js/vendor/ckfinder/ckfinder.html';
407      editor.config.filebrowserImageBrowseUrl = '/admin/assets/js/vendor/ckfinder/ckfinder.html?Type=Images';
408      editor.config.filebrowserUploadUrl 		= '/admin/assets/js/vendor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
409      editor.config.filebrowserImageUploadUrl = '/admin/assets/js/vendor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';
410      editor.config.magicline_everywhere = true;
411      editor.config.magicline_color = "#ccc";
412      editor.config.extraPlugins = 'balloonpanel,a11ychecker,cmsgrid,cmstabs,cmsclasses,cmsgrid,cmsaccordion,cmslink';
413      editor.config.removePlugins = 'scayt,link';
414 
415      // File Upload
416      $newspressAddEdit.find(".custom-file-input").on("change",function(e) {
417           if (e.target.files[0] !== undefined) {
418                $(this).parent().find(".custom-file-label").html(e.target.files[0].name);
419                $(this).valid();
420           }
421      })
422 
423      // Toggle "Link to Source" Details
424      $newspressAddEdit.find("#link").on("change",function(e) {
425           $newspressAddEdit.find("div[data-toggleparent='link']").toggleClass("d-none");
426      })
427 }
428 
429 /* ==========================================================================
430      News & Press Page - Main
431 ========================================================================== */   
432 
433 if ($newspressMain.length) {          
434     // News & Press Settings
435     if ($newspressSettings.length) {
436          // Validate
437          $.validator.setDefaults({
438               highlight: function(element) {
439                    if (!$(element).hasClass("custom-control-input")) {
440                         $(element).addClass('is-invalid');
441                         $(element).parent().find('label').addClass('active');
442                    }
443               },
444               unhighlight: function(element) {
445                    $(element).removeClass('is-invalid');
446               },
447               errorElement: 'span',
448               errorClass: 'error text-danger my-1 small',
449               errorPlacement: function(error, element) {
450                    if(element.parent('.place-validation-after').length) {
451                         error.insertAfter(element.parent());
452                    } else if(element.parents(".place-validation-after").length){
453                         error.insertAfter(element.parents(".place-validation-after"));
454                    } else {
455                         error.insertAfter(element);
456                    }
457               },
458               ignore: []
459          })
460          $.validator.messages.required = "<span class='fas fa-exclamation-triangle mr-1' aria-hidden='true'></span> Required";  
461          
462          $("div[class*='cms-newspress-settings'] form").validate({
463               messages: {
464                    categories: '<div class="mt-n2 mb-2"><span class="fas fa-exclamation-triangle mr-1" aria-hidden="true"></span> At least one category must be selected</div>'
465               },
466               errorPlacement: function(error, element) {
467                    if (element.parent(".custom-checkbox").length) {
468                         error.insertAfter(element.parents(".table"));
469                    }
470               }
471          });
472
473          $newspressSettings.find("#show_title").on("change", function(e) {
474               $(this).is(":checked") ?  $newspressMain.find(".cms-newspress-title").removeClass("d-none") : $newspressMain.find(".cms-newspress-title").addClass("d-none");
475               if (!$newspressSettings.find("#show_teaser").is(":checked")) $newspressSettings.find("#show_teaser").trigger("click");
476          })
477          $newspressSettings.find("#show_teaser").on("change", function(e) {
478               $(this).is(":checked") ?  $newspressMain.find(".cms-newspress-teaser").removeClass("d-none") : $newspressMain.find(".cms-newspress-teaser").addClass("d-none");
479               if (!$newspressSettings.find("#show_title").is(":checked")) $newspressSettings.find("#show_title").trigger("click");
480          })
481          $newspressSettings.find("#show_categories").on("change", function(e) {
482               $(this).is(":checked") ?  $newspressMain.find(".cms-newspress-categories").removeClass("d-none") : $newspressMain.find(".cms-newspress-categories").addClass("d-none");
483          })
484          $newspressSettings.find("#show_tags").on("change", function(e) {
485               $(this).is(":checked") ?  $newspressMain.find(".cms-newspress-tags").removeClass("d-none") : $newspressMain.find(".cms-newspress-tags").addClass("d-none");
486          })
487          // Manage user interaction of 'all categories' here
488          $newspressSettings.find('input[name="categories_all"]').on("change", function(e) {
489               let checked = $(this).is(":checked");
490               if( checked ) {
491                    $newspressSettings.find('tr.page_category_options').addClass('d-none');
492                    $newspressSettings.find('input[id^="categories_picker_"]').attr('required', false);
493               } else {
494                    $newspressSettings.find('tr.page_category_options').removeClass('d-none');
495                    $newspressSettings.find('input[id^="categories_picker_"]').attr('required', true);                    
496               }
497          });
498          $newspressSettings.find('input[name="categories_all"]').trigger('change');
499     }
500
501      // Datatable
502      if ($newspressMain.find("table").length) {
503          $newspressMain.find("table").dataTable( {
504               "aaSorting": false,
505               "aoColumns" : [null,{"bSortable":false}],
506               "columnDefs": [
507                    { "type": "date", "targets":0 }
508               ],
509               "aLengthMenu": [[20, 100, -1], [20, 100, "All"]],
510               "iDisplayLength" : 20
511          })
512     }
513
514 }
515 
516 /* ==========================================================================
517      News & Press Page - Settings
518 ========================================================================== */   
519 
520 if ($newspressSettings.length) {
521      // Toggle
522      $newspressSettings.find("button[aria-controls]").on("click",function(e) {
523           $newspressSettings
524                .find(".collapse").collapse("hide").end()
525                .find("button[aria-controls]").not(this).removeClass("active");
526      })
527      $newspressSettings.find(".collapse").on("show.bs.collapse", function (e) {
528           $newspressSettings.find(".cms-newspress-submit").removeClass("d-none");
529           $.each(e.target.classList,function(idx,target) {
530                $newspressSettings.find("button[aria-controls="+target+"]").addClass("active");
531           })
532      })
533      
534      $newspressSettings.find(".collapse").on("hide.bs.collapse", function (e) {
535           $newspressSettings.find(".cms-newspress-submit").addClass("d-none");
536           $.each(e.target.classList,function(idx,target) {
537                $newspressSettings.find("button[aria-controls="+target+"]").removeClass("active");
538           })
539      })
540 
541 }
542
543 /* ==========================================================================
544      News & Press Page - Masonry
545 ========================================================================== */   
546
547 if ($newspressMasonry.length) {
548     // Masonry layout
549     var $grid = $('.cms-newspress-masonry > ul:first-child');
550     
551     $grid.masonry({
552          itemSelector: '.cms-newspress-item',
553          columnWidth: '.grid-sizer',
554          gutter: 0,
555          horizontalOrder: true,
556          percentPosition: true
557     })
558
559     //Listen for lazyunveilread and trigger masonry re-draw 
560     document.addEventListener("lazyunveilread", function(e) {           
561          $grid.masonry("layout");
562     })
563 }
564 
565 /* ==========================================================================
566      Utils
567 ========================================================================== */   
568      
569 function getParameterByName(name) {
570      name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
571      var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
572           results = regex.exec(location.search);
573      return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
574 }
575 
576 }
577 
578 $(document).ready(function() {
579     
580     cmsNewsPress();
581     
582 })

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.