- Timestamp:
- May 14, 2019 2:17:07 AM (5 years ago)
- Location:
- trunk/js
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/js/Msg.js
r636 r679 83 83 var msghash = Strangecode.Msg.hash(message); 84 84 if (!$(options.container).find('[data-msghash="' + msghash + '"]').length) { 85 $(options.container).append($('<div data-alert class="alert-box sc-js-msg ' + msg_class + '" data-msghash="' + msghash + '"></div>').hide().html(message).append('<a href="#" class="close">Ã</a>')) ;85 $(options.container).append($('<div data-alert class="alert-box sc-js-msg ' + msg_class + '" data-msghash="' + msghash + '"></div>').hide().html(message).append('<a href="#" class="close">Ã</a>')).show(); 86 86 $('.sc-js-msg').slideDown('fast'); 87 87 if ($.fn.foundation) { … … 107 107 } 108 108 109 if (options.gotohash ) {110 $( document.body).animate({109 if (options.gotohash && $('html, body').scrollTop() > $(options.container).offset().top) { 110 $('html, body').animate({ 111 111 'scrollTop': $(options.container).offset().top 112 112 }, 'fast'); -
trunk/js/Utilities.js
r672 r679 39 39 */ 40 40 if (!String.prototype.format) { 41 String.prototype.format = function () {41 String.prototype.format = function () { 42 42 var args = arguments; 43 return this.replace(/{(\d+)}/g, function (match, number) {43 return this.replace(/{(\d+)}/g, function (match, number) { 44 44 return typeof args[number-1] != 'undefined' ? args[number-1] : match; 45 45 }); … … 61 61 * @since 30 Jun 2008 12:32:19 62 62 */ 63 jQuery.fn.nospam = function () {64 return this.each(function (){63 jQuery.fn.nospam = function () { 64 return this.each(function (){ 65 65 $(this).text($(this).text().replace(' at ', '@').replace(' dot ', '.')); 66 66 if (this.href) { … … 131 131 * @since 30 Jun 2013 132 132 */ 133 $.fn.slug = function () {133 $.fn.slug = function () { 134 134 str = this.text().trim().toLowerCase(); 135 135 var from = 'áéÃóúà ÚìòùÀëïöÌÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃâêîÎûÃÃÃÃÃñçÃ@·/_,:;'; … … 173 173 */ 174 174 if (!String.prototype.ucfirst) { 175 String.prototype.ucfirst = function () {175 String.prototype.ucfirst = function () { 176 176 return this.charAt(0).toUpperCase() + this.slice(1); 177 177 }; … … 193 193 * @since 06 Mar 2019 194 194 */ 195 Strangecode.humanTime = function (seconds, max_unit) {195 Strangecode.humanTime = function (seconds, max_unit) { 196 196 // Units: array of seconds in the unit, singular and plural unit names. 197 197 var units = { … … 227 227 // https://github.com/benjamingr/RegExp.escape 228 228 if(!RegExp.escape){ 229 RegExp.escape = function (s){229 RegExp.escape = function (s){ 230 230 return String(s).replace(/[\\^$*+?.()|[\]{}]/g, '\\$&'); 231 231 }; 232 232 } 233 234 // Throttle will ensure that a function is called at most once 235 // in a specified time period (for instance, once per 10 seconds). This means 236 // throttling will prevent a function from running if it has run ârecentlyâ. 237 // Throttling also ensures a function is run regularly at a fixed rate. 238 // https://blog.bitsrc.io/understanding-throttling-and-debouncing-973131c1ba07 239 Strangecode.throttle = function (f, t) { 240 return function (args) { 241 let previousCall = this.lastCall; 242 this.lastCall = Date.now(); 243 if (typeof previousCall === 'undefined' || (this.lastCall - previousCall) > t) { 244 // Throttle time has elapsed. 245 f(args); 246 } 247 } 248 } 249 250 // Debounce will ignore all calls to it until the calls have stopped for a 251 // specified time period. Only then will it call the original function. For 252 // instance, if we specify the time as two seconds, and the debounced function is 253 // called 10 times with an interval of one second between each call, the function 254 // will not call the original function until two seconds after the last (tenth) 255 // call. 256 // https://blog.bitsrc.io/understanding-throttling-and-debouncing-973131c1ba07 257 Strangecode.debounce = function (f, t) { 258 return function (args) { 259 let previousCall = this.lastCall; 260 this.lastCall = Date.now(); 261 if (previousCall && ((this.lastCallâ-âpreviousCall) <= t)) { 262 clearTimeout(this.lastCallTimer); 263 } 264 this.lastCallTimer = setTimeout(() => f(args), t); 265 } 266 }
Note: See TracChangeset
for help on using the changeset viewer.