Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/ninja-fo.../deprecat.../js/dev
File: jquery.rating.js
/*
[0] Fix | Delete
### jQuery Star Rating Plugin v4.11 - 2013-03-14 ###
[1] Fix | Delete
* Home: http://www.fyneworks.com/jquery/star-rating/
[2] Fix | Delete
* Code: http://code.google.com/p/jquery-star-rating-plugin/
[3] Fix | Delete
*
[4] Fix | Delete
* Licensed under http://en.wikipedia.org/wiki/MIT_License
[5] Fix | Delete
###
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/*# AVOID COLLISIONS #*/
[9] Fix | Delete
;if(window.jQuery) (function($){
[10] Fix | Delete
/*# AVOID COLLISIONS #*/
[11] Fix | Delete
[12] Fix | Delete
// IE6 Background Image Fix
[13] Fix | Delete
if ((!$.support.opacity && !$.support.style)) try { document.execCommand("BackgroundImageCache", false, true)} catch(e) { };
[14] Fix | Delete
// Thanks to http://www.visualjquery.com/rating/rating_redux.html
[15] Fix | Delete
[16] Fix | Delete
// plugin initialization
[17] Fix | Delete
$.fn.rating = function(options){
[18] Fix | Delete
if(this.length==0) return this; // quick fail
[19] Fix | Delete
[20] Fix | Delete
// Handle API methods
[21] Fix | Delete
if(typeof arguments[0]=='string'){
[22] Fix | Delete
// Perform API methods on individual elements
[23] Fix | Delete
if(this.length>1){
[24] Fix | Delete
var args = arguments;
[25] Fix | Delete
return this.each(function(){
[26] Fix | Delete
$.fn.rating.apply($(this), args);
[27] Fix | Delete
});
[28] Fix | Delete
};
[29] Fix | Delete
// Invoke API method handler
[30] Fix | Delete
$.fn.rating[arguments[0]].apply(this, $.makeArray(arguments).slice(1) || []);
[31] Fix | Delete
// Quick exit...
[32] Fix | Delete
return this;
[33] Fix | Delete
};
[34] Fix | Delete
[35] Fix | Delete
// Initialize options for this call
[36] Fix | Delete
var options = $.extend(
[37] Fix | Delete
{}/* new object */,
[38] Fix | Delete
$.fn.rating.options/* default options */,
[39] Fix | Delete
options || {} /* just-in-time options */
[40] Fix | Delete
);
[41] Fix | Delete
[42] Fix | Delete
// Allow multiple controls with the same name by making each call unique
[43] Fix | Delete
$.fn.rating.calls++;
[44] Fix | Delete
[45] Fix | Delete
// loop through each matched element
[46] Fix | Delete
this
[47] Fix | Delete
.not('.ninja-forms-star-rating-applied')
[48] Fix | Delete
.addClass('ninja-forms-star-rating-applied')
[49] Fix | Delete
.each(function(){
[50] Fix | Delete
[51] Fix | Delete
// Load control parameters / find context / etc
[52] Fix | Delete
var control, input = $(this);
[53] Fix | Delete
var eid = (this.name || 'unnamed-rating').replace(/\[|\]/g, '_').replace(/^\_+|\_+$/g,'');
[54] Fix | Delete
var context = $(this.form || document.body);
[55] Fix | Delete
[56] Fix | Delete
// FIX: http://code.google.com/p/jquery-star-rating-plugin/issues/detail?id=23
[57] Fix | Delete
var raters = context.data('rating');
[58] Fix | Delete
if(!raters || raters.call!=$.fn.rating.calls) raters = { count:0, call:$.fn.rating.calls };
[59] Fix | Delete
var rater = raters[eid] || context.data('rating'+eid);
[60] Fix | Delete
[61] Fix | Delete
// if rater is available, verify that the control still exists
[62] Fix | Delete
if(rater) control = rater.data('rating');
[63] Fix | Delete
[64] Fix | Delete
if(rater && control)//{// save a byte!
[65] Fix | Delete
// add star to control if rater is available and the same control still exists
[66] Fix | Delete
control.count++;
[67] Fix | Delete
[68] Fix | Delete
//}// save a byte!
[69] Fix | Delete
else{
[70] Fix | Delete
// create new control if first star or control element was removed/replaced
[71] Fix | Delete
[72] Fix | Delete
// Initialize options for this rater
[73] Fix | Delete
control = $.extend(
[74] Fix | Delete
{}/* new object */,
[75] Fix | Delete
options || {} /* current call options */,
[76] Fix | Delete
($.metadata? input.metadata(): ($.meta?input.data():null)) || {}, /* metadata options */
[77] Fix | Delete
{ count:0, stars: [], inputs: [] }
[78] Fix | Delete
);
[79] Fix | Delete
[80] Fix | Delete
// increment number of rating controls
[81] Fix | Delete
control.serial = raters.count++;
[82] Fix | Delete
[83] Fix | Delete
// create rating element
[84] Fix | Delete
rater = $('<span class="ninja-forms-star-rating-control"/>');
[85] Fix | Delete
input.before(rater);
[86] Fix | Delete
[87] Fix | Delete
// Mark element for initialization (once all stars are ready)
[88] Fix | Delete
rater.addClass('rating-to-be-drawn');
[89] Fix | Delete
[90] Fix | Delete
// Accept readOnly setting from 'disabled' property
[91] Fix | Delete
if(input.attr('disabled') || input.hasClass('disabled')) control.readOnly = true;
[92] Fix | Delete
[93] Fix | Delete
// Accept required setting from class property (class='required')
[94] Fix | Delete
if(input.hasClass('required')) control.required = true;
[95] Fix | Delete
[96] Fix | Delete
// Create 'cancel' button
[97] Fix | Delete
rater.append(
[98] Fix | Delete
control.cancel = $('<div class="rating-cancel"><a title="' + control.cancel + '">' + control.cancelValue + '</a></div>')
[99] Fix | Delete
.on('mouseover',function(){
[100] Fix | Delete
$(this).rating('drain');
[101] Fix | Delete
$(this).addClass('ninja-forms-star-rating-hover');
[102] Fix | Delete
//$(this).rating('focus');
[103] Fix | Delete
})
[104] Fix | Delete
.on('mouseout',function(){
[105] Fix | Delete
$(this).rating('draw');
[106] Fix | Delete
$(this).removeClass('ninja-forms-star-rating-hover');
[107] Fix | Delete
//$(this).rating('blur');
[108] Fix | Delete
})
[109] Fix | Delete
.on('click',function(){
[110] Fix | Delete
$(this).rating('select');
[111] Fix | Delete
})
[112] Fix | Delete
.data('rating', control)
[113] Fix | Delete
);
[114] Fix | Delete
[115] Fix | Delete
}; // first element of group
[116] Fix | Delete
[117] Fix | Delete
// insert rating star (thanks Jan Fanslau rev125 for blind support https://code.google.com/p/jquery-star-rating-plugin/issues/detail?id=125)
[118] Fix | Delete
var star = $('<div role="text" aria-label="'+ this.title +'" class="ninja-forms-star-rating rater-'+ control.serial +'"><a title="' + (this.title || this.value) + '">' + this.value + '</a></div>');
[119] Fix | Delete
rater.append(star);
[120] Fix | Delete
[121] Fix | Delete
// inherit attributes from input element
[122] Fix | Delete
if(this.id) star.attr('id', this.id);
[123] Fix | Delete
if(this.className) star.addClass(this.className);
[124] Fix | Delete
[125] Fix | Delete
// Half-stars?
[126] Fix | Delete
if(control.half) control.split = 2;
[127] Fix | Delete
[128] Fix | Delete
// Prepare division control
[129] Fix | Delete
if(typeof control.split=='number' && control.split>0){
[130] Fix | Delete
var stw = ($.fn.width ? star.width() : 0) || control.starWidth;
[131] Fix | Delete
var spi = (control.count % control.split), spw = Math.floor(stw/control.split);
[132] Fix | Delete
star
[133] Fix | Delete
// restrict star's width and hide overflow (already in CSS)
[134] Fix | Delete
.width(spw)
[135] Fix | Delete
// move the star left by using a negative margin
[136] Fix | Delete
// this is work-around to IE's stupid box model (position:relative doesn't work)
[137] Fix | Delete
.find('a').css({ 'margin-left':'-'+ (spi*spw) +'px' })
[138] Fix | Delete
};
[139] Fix | Delete
[140] Fix | Delete
// readOnly?
[141] Fix | Delete
if(control.readOnly)//{ //save a byte!
[142] Fix | Delete
// Mark star as readOnly so user can customize display
[143] Fix | Delete
star.addClass('ninja-forms-star-rating-readonly');
[144] Fix | Delete
//} //save a byte!
[145] Fix | Delete
else//{ //save a byte!
[146] Fix | Delete
// Enable hover css effects
[147] Fix | Delete
star.addClass('ninja-forms-star-rating-live')
[148] Fix | Delete
// Attach mouse events
[149] Fix | Delete
.on('mouseover',function(){
[150] Fix | Delete
$(this).rating('fill');
[151] Fix | Delete
$(this).rating('focus');
[152] Fix | Delete
})
[153] Fix | Delete
.on('mouseout',function(){
[154] Fix | Delete
$(this).rating('draw');
[155] Fix | Delete
$(this).rating('blur');
[156] Fix | Delete
})
[157] Fix | Delete
.on('click',function(){
[158] Fix | Delete
$(this).rating('select');
[159] Fix | Delete
})
[160] Fix | Delete
;
[161] Fix | Delete
//}; //save a byte!
[162] Fix | Delete
[163] Fix | Delete
// set current selection
[164] Fix | Delete
if(this.checked) control.current = star;
[165] Fix | Delete
[166] Fix | Delete
// set current select for links
[167] Fix | Delete
if(this.nodeName=="A"){
[168] Fix | Delete
if($(this).hasClass('selected'))
[169] Fix | Delete
control.current = star;
[170] Fix | Delete
};
[171] Fix | Delete
[172] Fix | Delete
// hide input element
[173] Fix | Delete
input.hide();
[174] Fix | Delete
[175] Fix | Delete
// backward compatibility, form element to plugin
[176] Fix | Delete
input.on('change.rating',function(event){
[177] Fix | Delete
if(event.selfTriggered) return false;
[178] Fix | Delete
$(this).rating('select');
[179] Fix | Delete
});
[180] Fix | Delete
[181] Fix | Delete
// attach reference to star to input element and vice-versa
[182] Fix | Delete
star.data('rating.input', input.data('rating.star', star));
[183] Fix | Delete
[184] Fix | Delete
// store control information in form (or body when form not available)
[185] Fix | Delete
control.stars[control.stars.length] = star[0];
[186] Fix | Delete
control.inputs[control.inputs.length] = input[0];
[187] Fix | Delete
control.rater = raters[eid] = rater;
[188] Fix | Delete
control.context = context;
[189] Fix | Delete
[190] Fix | Delete
input.data('rating', control);
[191] Fix | Delete
rater.data('rating', control);
[192] Fix | Delete
star.data('rating', control);
[193] Fix | Delete
context.data('rating', raters);
[194] Fix | Delete
context.data('rating'+eid, rater); // required for ajax forms
[195] Fix | Delete
}); // each element
[196] Fix | Delete
[197] Fix | Delete
// Initialize ratings (first draw)
[198] Fix | Delete
$('.rating-to-be-drawn').rating('draw').removeClass('rating-to-be-drawn');
[199] Fix | Delete
[200] Fix | Delete
return this; // don't break the chain...
[201] Fix | Delete
};
[202] Fix | Delete
[203] Fix | Delete
/*--------------------------------------------------------*/
[204] Fix | Delete
[205] Fix | Delete
/*
[206] Fix | Delete
### Core functionality and API ###
[207] Fix | Delete
*/
[208] Fix | Delete
$.extend($.fn.rating, {
[209] Fix | Delete
// Used to append a unique serial number to internal control ID
[210] Fix | Delete
// each time the plugin is invoked so same name controls can co-exist
[211] Fix | Delete
calls: 0,
[212] Fix | Delete
[213] Fix | Delete
focus: function(){
[214] Fix | Delete
var control = this.data('rating'); if(!control) return this;
[215] Fix | Delete
if(!control.focus) return this; // quick fail if not required
[216] Fix | Delete
// find data for event
[217] Fix | Delete
var input = $(this).data('rating.input') || $( this.tagName=='INPUT' ? this : null );
[218] Fix | Delete
// focus handler, as requested by focusdigital.co.uk
[219] Fix | Delete
if(control.focus) control.focus.apply(input[0], [input.val(), $('a', input.data('rating.star'))[0]]);
[220] Fix | Delete
}, // $.fn.rating.focus
[221] Fix | Delete
[222] Fix | Delete
blur: function(){
[223] Fix | Delete
var control = this.data('rating'); if(!control) return this;
[224] Fix | Delete
if(!control.blur) return this; // quick fail if not required
[225] Fix | Delete
// find data for event
[226] Fix | Delete
var input = $(this).data('rating.input') || $( this.tagName=='INPUT' ? this : null );
[227] Fix | Delete
// blur handler, as requested by focusdigital.co.uk
[228] Fix | Delete
if(control.blur) control.blur.apply(input[0], [input.val(), $('a', input.data('rating.star'))[0]]);
[229] Fix | Delete
}, // $.fn.rating.blur
[230] Fix | Delete
[231] Fix | Delete
fill: function(){ // fill to the current mouse position.
[232] Fix | Delete
var control = this.data('rating'); if(!control) return this;
[233] Fix | Delete
// do not execute when control is in read-only mode
[234] Fix | Delete
if(control.readOnly) return;
[235] Fix | Delete
// Reset all stars and highlight them up to this element
[236] Fix | Delete
this.rating('drain');
[237] Fix | Delete
this.prevAll().addBack().filter('.rater-'+ control.serial).addClass('ninja-forms-star-rating-hover');
[238] Fix | Delete
},// $.fn.rating.fill
[239] Fix | Delete
[240] Fix | Delete
drain: function() { // drain all the stars.
[241] Fix | Delete
var control = this.data('rating'); if(!control) return this;
[242] Fix | Delete
// do not execute when control is in read-only mode
[243] Fix | Delete
if(control.readOnly) return;
[244] Fix | Delete
// Reset all stars
[245] Fix | Delete
control.rater.children().filter('.rater-'+ control.serial).removeClass('ninja-forms-star-rating-on').removeClass('ninja-forms-star-rating-hover');
[246] Fix | Delete
},// $.fn.rating.drain
[247] Fix | Delete
[248] Fix | Delete
draw: function(){ // set value and stars to reflect current selection
[249] Fix | Delete
var control = this.data('rating'); if(!control) return this;
[250] Fix | Delete
// Clear all stars
[251] Fix | Delete
this.rating('drain');
[252] Fix | Delete
// Set control value
[253] Fix | Delete
var current = $( control.current );//? control.current.data('rating.input') : null );
[254] Fix | Delete
var starson = current.length ? current.prevAll().addBack().filter('.rater-'+ control.serial) : null;
[255] Fix | Delete
if(starson) starson.addClass('ninja-forms-star-rating-on');
[256] Fix | Delete
// Show/hide 'cancel' button
[257] Fix | Delete
control.cancel[control.readOnly || control.required?'hide':'show']();
[258] Fix | Delete
// Add/remove read-only classes to remove hand pointer
[259] Fix | Delete
this.siblings()[control.readOnly?'addClass':'removeClass']('ninja-forms-star-rating-readonly');
[260] Fix | Delete
},// $.fn.rating.draw
[261] Fix | Delete
[262] Fix | Delete
[263] Fix | Delete
[264] Fix | Delete
[265] Fix | Delete
[266] Fix | Delete
select: function(value,wantCallBack){ // select a value
[267] Fix | Delete
var control = this.data('rating'); if(!control) return this;
[268] Fix | Delete
// do not execute when control is in read-only mode
[269] Fix | Delete
if(control.readOnly) return;
[270] Fix | Delete
// clear selection
[271] Fix | Delete
control.current = null;
[272] Fix | Delete
// programmatically (based on user input)
[273] Fix | Delete
if(typeof value!='undefined' || this.length>1){
[274] Fix | Delete
// select by index (0 based)
[275] Fix | Delete
if(typeof value=='number')
[276] Fix | Delete
return $(control.stars[value]).rating('select',undefined,wantCallBack);
[277] Fix | Delete
// select by literal value (must be passed as a string
[278] Fix | Delete
if(typeof value=='string'){
[279] Fix | Delete
//return
[280] Fix | Delete
$.each(control.stars, function(){
[281] Fix | Delete
//console.log($(this).data('rating.input'), $(this).data('rating.input').val(), value, $(this).data('rating.input').val()==value?'BINGO!':'');
[282] Fix | Delete
if($(this).data('rating.input').val()==value) $(this).rating('select',undefined,wantCallBack);
[283] Fix | Delete
});
[284] Fix | Delete
// don't break the chain
[285] Fix | Delete
return this;
[286] Fix | Delete
};
[287] Fix | Delete
}
[288] Fix | Delete
else{
[289] Fix | Delete
control.current = this[0].tagName=='INPUT' ?
[290] Fix | Delete
this.data('rating.star') :
[291] Fix | Delete
(this.is('.rater-'+ control.serial) ? this : null);
[292] Fix | Delete
};
[293] Fix | Delete
// Update rating control state
[294] Fix | Delete
this.data('rating', control);
[295] Fix | Delete
// Update display
[296] Fix | Delete
this.rating('draw');
[297] Fix | Delete
// find current input and its sibblings
[298] Fix | Delete
var current = $( control.current ? control.current.data('rating.input') : null );
[299] Fix | Delete
var lastipt = $( control.inputs ).filter(':checked');
[300] Fix | Delete
var deadipt = $( control.inputs ).not(current);
[301] Fix | Delete
// check and uncheck elements as required
[302] Fix | Delete
deadipt.prop('checked',false);//.removeAttr('checked');
[303] Fix | Delete
current.prop('checked',true);//.attr('checked','checked');
[304] Fix | Delete
// trigger change on current or last selected input
[305] Fix | Delete
$(current.length? current : lastipt ).trigger({ type:'change', selfTriggered:true });
[306] Fix | Delete
// click callback, as requested here: http://plugins.jquery.com/node/1655
[307] Fix | Delete
if((wantCallBack || wantCallBack == undefined) && control.callback) control.callback.apply(current[0], [current.val(), $('a', control.current)[0]]);// callback event
[308] Fix | Delete
// don't break the chain
[309] Fix | Delete
return this;
[310] Fix | Delete
},// $.fn.rating.select
[311] Fix | Delete
[312] Fix | Delete
[313] Fix | Delete
[314] Fix | Delete
[315] Fix | Delete
[316] Fix | Delete
readOnly: function(toggle, disable){ // make the control read-only (still submits value)
[317] Fix | Delete
var control = this.data('rating'); if(!control) return this;
[318] Fix | Delete
// setread-only status
[319] Fix | Delete
control.readOnly = toggle || toggle==undefined ? true : false;
[320] Fix | Delete
// enable/disable control value submission
[321] Fix | Delete
if(disable) $(control.inputs).attr("disabled", "disabled");
[322] Fix | Delete
else $(control.inputs).removeAttr("disabled");
[323] Fix | Delete
// Update rating control state
[324] Fix | Delete
this.data('rating', control);
[325] Fix | Delete
// Update display
[326] Fix | Delete
this.rating('draw');
[327] Fix | Delete
},// $.fn.rating.readOnly
[328] Fix | Delete
[329] Fix | Delete
disable: function(){ // make read-only and never submit value
[330] Fix | Delete
this.rating('readOnly', true, true);
[331] Fix | Delete
},// $.fn.rating.disable
[332] Fix | Delete
[333] Fix | Delete
enable: function(){ // make read/write and submit value
[334] Fix | Delete
this.rating('readOnly', false, false);
[335] Fix | Delete
}// $.fn.rating.select
[336] Fix | Delete
[337] Fix | Delete
});
[338] Fix | Delete
[339] Fix | Delete
/*--------------------------------------------------------*/
[340] Fix | Delete
[341] Fix | Delete
/*
[342] Fix | Delete
### Default Settings ###
[343] Fix | Delete
eg.: You can override default control like this:
[344] Fix | Delete
$.fn.rating.options.cancel = 'Clear';
[345] Fix | Delete
*/
[346] Fix | Delete
$.fn.rating.options = { //$.extend($.fn.rating, { options: {
[347] Fix | Delete
cancel: 'Cancel Rating', // advisory title for the 'cancel' link
[348] Fix | Delete
cancelValue: '', // value to submit when user click the 'cancel' link
[349] Fix | Delete
split: 0, // split the star into how many parts?
[350] Fix | Delete
[351] Fix | Delete
// Width of star image in case the plugin can't work it out. This can happen if
[352] Fix | Delete
// the jQuery.dimensions plugin is not available OR the image is hidden at installation
[353] Fix | Delete
starWidth: 16//,
[354] Fix | Delete
[355] Fix | Delete
//NB.: These don't need to be pre-defined (can be undefined/null) so let's save some code!
[356] Fix | Delete
//half: false, // just a shortcut to control.split = 2
[357] Fix | Delete
//required: false, // disables the 'cancel' button so user can only select one of the specified values
[358] Fix | Delete
//readOnly: false, // disable rating plugin interaction/ values cannot be.one('change', //focus: function(){}, // executed when stars are focused
[359] Fix | Delete
//blur: function(){}, // executed when stars are focused
[360] Fix | Delete
//callback: function(){}, // executed when a star is clicked
[361] Fix | Delete
}; //} });
[362] Fix | Delete
[363] Fix | Delete
/*--------------------------------------------------------*/
[364] Fix | Delete
[365] Fix | Delete
[366] Fix | Delete
// auto-initialize plugin
[367] Fix | Delete
$(function(){
[368] Fix | Delete
$('input[type=radio].ninja-forms-star').rating();
[369] Fix | Delete
});
[370] Fix | Delete
[371] Fix | Delete
[372] Fix | Delete
/*# AVOID COLLISIONS #*/
[373] Fix | Delete
})(jQuery);
[374] Fix | Delete
/*# AVOID COLLISIONS #*/
[375] Fix | Delete
[376] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function