diff --git a/src/assets/js/tainacan-interface-truncate.js b/src/assets/js/tainacan-interface-truncate.js new file mode 100644 index 0000000..738b68b --- /dev/null +++ b/src/assets/js/tainacan-interface-truncate.js @@ -0,0 +1,42 @@ +(function($) { + $.fn.tainacan_interface_truncate = function (settings) { + var config = { + showChars: 350, + minChars: 100, + ellipsesText: "...", + moreText: "More", + lessText: "Less" + }; + + if (settings) { + $.extend(config, settings); + } + + var minimized_elements = $(this); + + minimized_elements.each(function(){ + var t = $(this).text(); + if(t.length < config.minChars) return; + + $(this).html( + t.slice(0,config.showChars)+''+ config.ellipsesText +' '+ config.moreText +''+ + ''+ t.slice(config.showChars,t.length)+' '+ config.lessText +'' + ); + + }); + + $('a.tainacan-interface-more', minimized_elements).click(function(event){ + event.preventDefault(); + minimized_elements.addClass('full-story'); + $(this).hide().prev().hide(); + $(this).next().show(); + }); + + $('a.tainacan-interface-less', minimized_elements).click(function(event){ + event.preventDefault(); + minimized_elements.removeClass('full-story'); + $(this).parent().hide().prev().show().prev().show(); + }); + return minimized_elements; + }; +})(jQuery);