PageSourceSearch

https://www.responsiblevacation.com/js/jquery.shorten.1.0.js?v=3.0.57

js responsiblevacation.com collected 2026-10-02 06:07:08 UTC 4,386 bytes, 149 lines download raw bytes

1/*
2* jQuery Shorten plugin 1.0.0
3*
4* Copyright (c) 2013 Viral Patel
5* http://viralpatel.net
6*
7* Licensed under the MIT license:
8*   http://www.opensource.org/licenses/mit-license.php
9*/
10
11
12(function($) {
13  $.fn.shorten = function(settings) {
14
15
16    "use strict";
17
18
19    var config = {
20      showChars: 100,
21      ellipsesText: "...",
22      moreText: "more",
23      lessText: "less",
24      errMsg: null
25    };
26
27
28    if (settings) {
29      $.extend(config, settings);
30    }
31
32
33    $(document).off("click", '.morelink');
34
35
36    $(document).on({ click: function() {
37
38
39      var $this = $(this);
40      if ($this.hasClass('less')) {
41        $this.removeClass('less');
42        $this.html(config.moreText);
43        $this.parent().prev().prev().show(); // shortcontent
44        $this.parent().prev().hide(); // allcontent
45
46      } else {
47        $this.addClass('less');
48        $this.html(config.lessText);
49        $this.parent().prev().prev().hide(); // shortcontent
50        $this.parent().prev().show(); // allcontent
51      }
52      return false;
53    }
54    }, '.morelink');
55
56
57    return this.each(function() {
58      var $this = $(this);
59
60
61      var content = $this.html();
62      var contentlen = $this.text().length;
63      if (contentlen > config.showChars) {
64        var c = content.substr(0, config.showChars);
65        if (c.indexOf('<') >= 0) // If there's HTML don't want to cut it
66        {
67          var inTag = false; // I'm in a tag?
68          var bag = ''; // Put the characters to be shown here
69          var countChars = 0; // Current bag size
70          var openTags = []; // Stack for opened tags, so I can close them later
71          var tagName = null;
72
73
74          for (var i = 0, r = 0; r <= config.showChars; i++) {
75            if (content[i] == '<' && !inTag) {
76              inTag = true;
77
78
79              // This could be "tag" or "/tag"
80              tagName = content.substring(i + 1, content.indexOf('>', i));
81
82
83              // If its a closing tag
84              if (tagName[0] == '/') {
85
86                if (tagName != '/' + openTags[0]) {
87                  config.errMsg = 'ERROR en HTML: the top of the stack should be the tag that closes';
88                } else {
89                  openTags.shift(); // Pops the last tag from the open tag stack (the tag is closed in the retult HTML!)
90                }
91
92
93              } else {
94                // There are some nasty tags that don't have a close tag like <br/>
95                if (tagName.toLowerCase() != 'br') {
96                  openTags.unshift(tagName); // Add to start the name of the tag that opens
97                }
98              }
99            }
100            if (inTag && content[i] == '>') {
101              inTag = false;
102            }
103
104
105            if (inTag) { bag += content.charAt(i); } // Add tag name chars to the result
106            else {
107              r++;
108              if (countChars <= config.showChars) {
109                bag += content.charAt(i); // Fix to ie 7 not allowing you to reference string characters using the []
110                countChars++;
111              } else // Now I have the characters needed
112              {
113                if (openTags.length > 0) // I have unclosed tags
114                {
115                  //console.log('They were open tags');
116                  //console.log(openTags);
117                  for (j = 0; j < openTags.length; j++) {
118                    //console.log('Cierro tag ' + openTags[j]);
119                    bag += '</' + openTags[j] + '>'; // Close all tags that were opened
120
121
122                    // You could shift the tag from the stack to check if you end with an empty stack, that means you have closed all open tags
123                  }
124                  break;
125                }
126              }
127            }
128          }
129          //c = bag.trim();
130          c = bag;
131        }
132
133
134        var html = '<span class="shortcontent">' + c + '&nbsp;' + config.ellipsesText +
135                '</span><span class="allcontent">' + content +
136                '</span>&nbsp;&nbsp;<span><a href="javascript://nop/" class="morelink">' + config.moreText + '</a></span>';
137
138
139        $this.html(html);
140        $(".allcontent").hide(); // Esconde el contenido completo para todos los textos
141      }
142    });
143
144
145  };
146
147
148})(jQuery);
149

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.