wire/modules/Fieldtype/FieldtypeComments/comments.js
/**
 * Handle the 5-star rating system for comments
 *
 */
Handle the 5-star rating system for comments
Handle the 5 - star rating system for comments
function CommentFormStars() {
	function decodeEntities(encodedString) {
		if(encodedString.indexOf('&') == -1) return encodedString;
		var textarea = document.createElement('textarea');
		textarea.innerHTML = encodedString;
		return textarea.value;
	}
	function setStars($parent, star) {
		var onClass, offClass, starOn, starOff;
		onClass = $parent.attr('data-onclass');
		offClass = $parent.attr('data-offclass');
		starOn = $parent.attr('data-on');
		if(typeof onClass == "undefined") onClass = 'CommentStarOff';
		if(typeof offClass == "undefined") offClass = 'CommentStarOff';
		if(typeof starOn != "undefined") {
			starOff = $parent.attr('data-off');
			starOn = decodeEntities(starOn);
			starOff = decodeEntities(starOff);
		} else {
			starOn = '';
			starOff = '';
		}
		$parent.children('span').each(function() {
			var val = parseInt(jQuery(this).attr('data-value'));
			if(val <= star) {
				if(starOn.length) jQuery(this).html(starOn);
				jQuery(this).addClass(onClass).removeClass(offClass);
			} else {
				if(starOff.length) jQuery(this).html(starOff);
				jQuery(this).removeClass(onClass).addClass(offClass);
			}
		});
	}
	jQuery('.CommentFormStars input').hide();
	jQuery(document).on('click', '.CommentStarsInput span', function(e) {
		var value = parseInt(jQuery(this).attr('data-value'));
		var $parent = jQuery(this).parent();
		var $input = $parent.prev('input');
		$input.val(value).attr('value', value); 
		setStars($parent, value);
		$input.change();
		return false;
	});
}
function CommentFormStars ( ) { function decodeEntities ( encodedString ) { if ( encodedString . indexOf ( '&' ) == - 1 ) return encodedString ; var textarea = document . createElement ( 'textarea' ) ; textarea . innerHTML = encodedString ; return textarea . value ; } function setStars ( $parent , star ) { var onClass , offClass , starOn , starOff ; onClass = $parent . attr ( 'data-onclass' ) ; offClass = $parent . attr ( 'data-offclass' ) ; starOn = $parent . attr ( 'data-on' ) ; if ( typeof onClass == "undefined" ) onClass = 'CommentStarOff' ; if ( typeof offClass == "undefined" ) offClass = 'CommentStarOff' ; if ( typeof starOn != "undefined" ) { starOff = $parent . attr ( 'data-off' ) ; starOn = decodeEntities ( starOn ) ; starOff = decodeEntities ( starOff ) ; } else { starOn = '' ; starOff = '' ; } $parent . children ( 'span' ) . each ( function ( ) { var val = parseInt ( jQuery ( this ) . attr ( 'data-value' ) ) ; if ( val <= star ) { if ( starOn . length ) jQuery ( this ) . html ( starOn ) ; jQuery ( this ) . addClass ( onClass ) . removeClass ( offClass ) ; } else { if ( starOff . length ) jQuery ( this ) . html ( starOff ) ; jQuery ( this ) . removeClass ( onClass ) . addClass ( offClass ) ; } } ) ; } jQuery ( '.CommentFormStars input' ) . hide ( ) ; jQuery ( document ) . on ( 'click' , '.CommentStarsInput span' , function ( e ) { var value = parseInt ( jQuery ( this ) . attr ( 'data-value' ) ) ; var $parent = jQuery ( this ) . parent ( ) ; var $input = $parent . prev ( 'input' ) ; $input . val ( value ) . attr ( 'value' , value ) ; setStars ( $parent , value ) ; $input . change ( ) ; return false ; } ) ; }
Handle the 5-star rating system for comments
Handle the 5 - star rating system for comments
// redundancy intended, val() not working on webkit mobile for some reason /*
	// removed because on newer jQuery versions (?) adding a mouseover event here 
	// is preventing the above click event from firing
	$(document).on('mouseover', ".CommentStarsInput span", function(e) {
		var $parent = $(this).parent();
		var value = parseInt($(this).attr('data-value'));
		setStars($parent, value);
	}).on('mouseout', ".CommentStarsInput span", function(e) {
		var $parent = $(this).parent();
		var $input = $parent.prev('input');
		var value = parseInt($input.val());
		setStars($parent, value);
	});
	*/