1/* globals 2 jQuery, CsLogger 3 */ 4/* exported 5 */ 6"use strict"; 7(function ($, window, document, undefined) { 8 // default settings. 9 var _pluginName = "text1"; 10 var _defaultsOptions = { 11 debug: false, 12 scrollReveal: true 13 }; 14 var _logger = new CsLogger(_pluginName); 15 16 17 // constructor. 18 function Text1(element, options) { 19 this._element = element; 20 this._options = $.extend({}, _defaultsOptions, options); 21 this._defaultOptions = _defaultsOptions; 22 this._name = _pluginName; 23 this.init(); 24 } 25 26 // remove empty <p> tags. 27 function removeEmptyParagraphs(element) { 28 var elementContainer = document.getElementById(element.id); 29 var totalParagraphs = elementContainer.getElementsByTagName('p'); 30 $(totalParagraphs).each(function () { 31 if ($(this).text().trim() === '') { 32 $(this).remove(); 33 } 34 }); 35 } 36 37 // (void) validate the options passed into the plugin. 38 function validateOptions(options) { 39 if (typeof (options.debug) == "boolean" && options.debug == true) { 40 _logger.enable(); 41 } 42 _logger.obj("validateOptions() | opts:", options); 43 } 44 45 // (void) ensure the selected element is valid. 46 function validateElement(element) { 47 _logger.log("validateElement()"); 48 if (element == undefined || $(element).length == 0) { 49 _logger.error("selected element is not valid."); 50 return; 51 } 52 } 53 54 // prototype extensions. 55 Text1.prototype = { 56 57 // (void) initialise. 58 init: function () { 59 validateOptions(this._options); 60 validateElement(this._element); 61 removeEmptyParagraphs(this._element); 62 _logger.log("init()"); 63 } 64 }; 65 66 // A really lightweight plugin wrapper around the constructor, 67 // preventing against multiple instantiations 68 $.fn[_pluginName] = function (options) { 69 return this.each(function () { 70 if (!$.data(this, "plugin_" + _pluginName)) { 71 $.data(this, "plugin_" + _pluginName, 72 new Text1(this, options)); 73 } 74 }); 75 }; 76 77})(jQuery, window, document);
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.