Skip to content
Snippets Groups Projects
Select Git revision
  • 8a62cabb0e3e55efc1f95643677f6facba904f54
  • master default protected
  • 1-issue-czi-wtf
  • update-deps
4 results

marquee.js

Blame
  • Forked from FS Info TU Dortmund / Infoscreen / Infoscreen
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    marquee.js 1.18 KiB
    const
    	MARQUEE_SPEED_PRECISION = 2;				// defines the number of decimal places for speed calculation
    	
    function initMarquee(panel) {
    	var marquee=$(panel).find('marquee');
    	for (var i=0;i<marquee.size();i++) {
    		marqueeToCSS(marquee[i]);
    	}
    }
    
    function marqueeToCSS(marquee) {
    	// TODO insert font and font-size
    	var
    		speed = $(marquee).attr("data-speed") || "1.0",
    		content = $(marquee).html(),
    		result = '';
    	// generate css html
    	result += '<div data-marquee data-css-marquee>';
    	result += '<div data-css-marquee-text>';
    	result += content;
    	result += '</div>';
    	result += '</div>';
    	// create html and replace marquee
    	var element = document.createElement('hidden');
    	$(element).html(result);
    	$(marquee).replaceWith(element);
    	// corrections
    	var text = $(element).find("div[data-css-marquee-text]")[0];
    	$($(element).find("div[data-css-marquee]")[0]).css("user-select","none");
    	var textWidth = $(text).outerWidth();
    	$(text).css("animation",'marquee ' + (textWidth / speed).toFixed(MARQUEE_SPEED_PRECISION) + 's linear infinite');
    	$(text).html(repeatString(content, 5));
    	$(element).replaceWith($(element).html());
    }
    
    function repeatString(str, times) {
    	return (new Array(times + 1)).join(str);
    }