r72066 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72065‎ | r72066 | r72067 >
Date:23:41, 31 August 2010
Author:adam
Status:deferred
Tags:
Comment:
ArticleAssessment in progress commit...need to head home for the night and will be working more on it later at home
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/css/ArticleAssessment.css (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/js/jquery.cookie.js (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/js/jquery.stars.js (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/js/jquery.tipsy.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/css/ArticleAssessment.css
@@ -91,6 +91,7 @@
9292 }
9393 .article-assessment-wrapper .rating-field-label{
9494 float: left;
 95+ font-weight: bold;
9596 line-height: 24px;
9697 }
9798 .article-assessment-wrapper .rating-field-label {
Index: trunk/extensions/ArticleAssessmentPilot/js/jquery.tipsy.js
@@ -4,199 +4,199 @@
55 // released under the MIT license
66
77 (function($) {
8 -
9 - function Tipsy(element, options) {
10 - this.$element = $(element);
11 - this.options = options;
12 - this.enabled = true;
13 - this.fixTitle();
14 - }
15 -
16 - Tipsy.prototype = {
17 - show: function() {
18 - var title = this.getTitle();
19 - if (title && this.enabled) {
20 - var $tip = this.tip();
21 -
22 - $tip.find('.tipsy-inner')[this.options.html ? 'html' : 'text'](title);
23 - $tip[0].className = 'tipsy'; // reset classname in case of dynamic gravity
24 - $tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).appendTo(document.body);
25 -
26 - var pos = $.extend({}, this.$element.offset(), {
27 - width: this.$element[0].offsetWidth,
28 - height: this.$element[0].offsetHeight
29 - });
30 -
31 - var actualWidth = $tip[0].offsetWidth, actualHeight = $tip[0].offsetHeight;
32 - var gravity = (typeof this.options.gravity == 'function')
33 - ? this.options.gravity.call(this.$element[0])
34 - : this.options.gravity;
35 -
36 - var tp;
37 - switch (gravity.charAt(0)) {
38 - case 'n':
39 - tp = {top: pos.top + pos.height + this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
40 - break;
41 - case 's':
42 - tp = {top: pos.top - actualHeight - this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
43 - break;
44 - case 'e':
45 - tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - this.options.offset};
46 - break;
47 - case 'w':
48 - tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + this.options.offset};
49 - break;
50 - }
51 -
52 - if (gravity.length == 2) {
53 - if (gravity.charAt(1) == 'w') {
54 - tp.left = pos.left + pos.width / 2 - 15;
55 - } else {
56 - tp.left = pos.left + pos.width / 2 - actualWidth + 15;
57 - }
58 - }
59 -
60 - $tip.css(tp).addClass('tipsy-' + gravity);
61 -
62 - if (this.options.fade) {
63 - $tip.stop().css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: this.options.opacity});
64 - } else {
65 - $tip.css({visibility: 'visible', opacity: this.options.opacity});
66 - }
67 - }
68 - },
69 -
70 - hide: function() {
71 - if (this.options.fade) {
72 - this.tip().stop().fadeOut(function() { $(this).remove(); });
73 - } else {
74 - this.tip().remove();
75 - }
76 - },
77 -
78 - fixTitle: function() {
79 - var $e = this.$element;
80 - if ($e.attr('title') || typeof($e.attr('original-title')) != 'string') {
81 - $e.attr('original-title', $e.attr('title') || '').removeAttr('title');
82 - }
83 - },
84 -
85 - getTitle: function() {
86 - var title, $e = this.$element, o = this.options;
87 - this.fixTitle();
88 - var title, o = this.options;
89 - if (typeof o.title == 'string') {
90 - title = $e.attr(o.title == 'title' ? 'original-title' : o.title);
91 - } else if (typeof o.title == 'function') {
92 - title = o.title.call($e[0]);
93 - }
94 - title = ('' + title).replace(/(^\s*|\s*$)/, "");
95 - return title || o.fallback;
96 - },
97 -
98 - tip: function() {
99 - if (!this.$tip) {
100 - this.$tip = $('<div class="tipsy"></div>').html('<div class="tipsy-arrow"></div><div class="tipsy-inner"></div>');
101 - }
102 - return this.$tip;
103 - },
104 -
105 - validate: function() {
106 - if (!this.$element[0].parentNode) {
107 - this.hide();
108 - this.$element = null;
109 - this.options = null;
110 - }
111 - },
112 -
113 - enable: function() { this.enabled = true; },
114 - disable: function() { this.enabled = false; },
115 - toggleEnabled: function() { this.enabled = !this.enabled; }
116 - };
117 -
118 - $.fn.tipsy = function(options) {
119 -
120 - if (options === true) {
121 - return this.data('tipsy');
122 - } else if (typeof options == 'string') {
123 - var tipsy = this.data('tipsy');
124 - if (tipsy) tipsy[options]();
125 - return this;
126 - }
127 -
128 - options = $.extend({}, $.fn.tipsy.defaults, options);
129 -
130 - function get(ele) {
131 - var tipsy = $.data(ele, 'tipsy');
132 - if (!tipsy) {
133 - tipsy = new Tipsy(ele, $.fn.tipsy.elementOptions(ele, options));
134 - $.data(ele, 'tipsy', tipsy);
135 - }
136 - return tipsy;
137 - }
138 -
139 - function enter() {
140 - var tipsy = get(this);
141 - tipsy.hoverState = 'in';
142 - if (options.delayIn == 0) {
143 - tipsy.show();
144 - } else {
145 - tipsy.fixTitle();
146 - setTimeout(function() { if (tipsy.hoverState == 'in') tipsy.show(); }, options.delayIn);
147 - }
148 - };
149 -
150 - function leave() {
151 - var tipsy = get(this);
152 - tipsy.hoverState = 'out';
153 - if (options.delayOut == 0) {
154 - tipsy.hide();
155 - } else {
156 - setTimeout(function() { if (tipsy.hoverState == 'out') tipsy.hide(); }, options.delayOut);
157 - }
158 - };
159 -
160 - if (!options.live) this.each(function() { get(this); });
161 -
162 - if (options.trigger != 'manual') {
163 - var binder = options.live ? 'live' : 'bind',
164 - eventIn = options.trigger == 'hover' ? 'mouseenter' : 'focus',
165 - eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur';
166 - this[binder](eventIn, enter)[binder](eventOut, leave);
167 - }
168 -
169 - return this;
170 -
171 - };
172 -
173 - $.fn.tipsy.defaults = {
174 - delayIn: 0,
175 - delayOut: 0,
176 - fade: false,
177 - fallback: '',
178 - gravity: 'n',
179 - html: false,
180 - live: false,
181 - offset: 0,
182 - opacity: 0.8,
183 - title: 'title',
184 - trigger: 'hover'
185 - };
186 -
187 - // Overwrite this method to provide options on a per-element basis.
188 - // For example, you could store the gravity in a 'tipsy-gravity' attribute:
189 - // return $.extend({}, options, {gravity: $(ele).attr('tipsy-gravity') || 'n' });
190 - // (remember - do not modify 'options' in place!)
191 - $.fn.tipsy.elementOptions = function(ele, options) {
192 - return $.metadata ? $.extend({}, options, $(ele).metadata()) : options;
193 - };
194 -
195 - $.fn.tipsy.autoNS = function() {
196 - return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n';
197 - };
198 -
199 - $.fn.tipsy.autoWE = function() {
200 - return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w';
201 - };
202 -
 8+
 9+ function Tipsy(element, options) {
 10+ this.$element = $(element);
 11+ this.options = options;
 12+ this.enabled = true;
 13+ this.fixTitle();
 14+ }
 15+
 16+ Tipsy.prototype = {
 17+ show: function() {
 18+ var title = this.getTitle();
 19+ if (title && this.enabled) {
 20+ var $tip = this.tip();
 21+
 22+ $tip.find('.tipsy-inner')[this.options.html ? 'html' : 'text'](title);
 23+ $tip[0].className = 'tipsy'; // reset classname in case of dynamic gravity
 24+ $tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).appendTo(document.body);
 25+
 26+ var pos = $.extend({}, this.$element.offset(), {
 27+ width: this.$element[0].offsetWidth,
 28+ height: this.$element[0].offsetHeight
 29+ });
 30+
 31+ var actualWidth = $tip[0].offsetWidth, actualHeight = $tip[0].offsetHeight;
 32+ var gravity = (typeof this.options.gravity == 'function')
 33+ ? this.options.gravity.call(this.$element[0])
 34+ : this.options.gravity;
 35+
 36+ var tp;
 37+ switch (gravity.charAt(0)) {
 38+ case 'n':
 39+ tp = {top: pos.top + pos.height + this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
 40+ break;
 41+ case 's':
 42+ tp = {top: pos.top - actualHeight - this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
 43+ break;
 44+ case 'e':
 45+ tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - this.options.offset};
 46+ break;
 47+ case 'w':
 48+ tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + this.options.offset};
 49+ break;
 50+ }
 51+
 52+ if (gravity.length == 2) {
 53+ if (gravity.charAt(1) == 'w') {
 54+ tp.left = pos.left + pos.width / 2 - 15;
 55+ } else {
 56+ tp.left = pos.left + pos.width / 2 - actualWidth + 15;
 57+ }
 58+ }
 59+
 60+ $tip.css(tp).addClass('tipsy-' + gravity);
 61+
 62+ if (this.options.fade) {
 63+ $tip.stop().css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: this.options.opacity});
 64+ } else {
 65+ $tip.css({visibility: 'visible', opacity: this.options.opacity});
 66+ }
 67+ }
 68+ },
 69+
 70+ hide: function() {
 71+ if (this.options.fade) {
 72+ this.tip().stop().fadeOut(function() { $(this).remove(); });
 73+ } else {
 74+ this.tip().remove();
 75+ }
 76+ },
 77+
 78+ fixTitle: function() {
 79+ var $e = this.$element;
 80+ if ($e.attr('title') || typeof($e.attr('original-title')) != 'string') {
 81+ $e.attr('original-title', $e.attr('title') || '').removeAttr('title');
 82+ }
 83+ },
 84+
 85+ getTitle: function() {
 86+ var title, $e = this.$element, o = this.options;
 87+ this.fixTitle();
 88+ var title, o = this.options;
 89+ if (typeof o.title == 'string') {
 90+ title = $e.attr(o.title == 'title' ? 'original-title' : o.title);
 91+ } else if (typeof o.title == 'function') {
 92+ title = o.title.call($e[0]);
 93+ }
 94+ title = ('' + title).replace(/(^\s*|\s*$)/, "");
 95+ return title || o.fallback;
 96+ },
 97+
 98+ tip: function() {
 99+ if (!this.$tip) {
 100+ this.$tip = $('<div class="tipsy"></div>').html('<div class="tipsy-arrow"></div><div class="tipsy-inner"></div>');
 101+ }
 102+ return this.$tip;
 103+ },
 104+
 105+ validate: function() {
 106+ if (!this.$element[0].parentNode) {
 107+ this.hide();
 108+ this.$element = null;
 109+ this.options = null;
 110+ }
 111+ },
 112+
 113+ enable: function() { this.enabled = true; },
 114+ disable: function() { this.enabled = false; },
 115+ toggleEnabled: function() { this.enabled = !this.enabled; }
 116+ };
 117+
 118+ $.fn.tipsy = function(options) {
 119+
 120+ if (options === true) {
 121+ return this.data('tipsy');
 122+ } else if (typeof options == 'string') {
 123+ var tipsy = this.data('tipsy');
 124+ if (tipsy) tipsy[options]();
 125+ return this;
 126+ }
 127+
 128+ options = $.extend({}, $.fn.tipsy.defaults, options);
 129+
 130+ function get(ele) {
 131+ var tipsy = $.data(ele, 'tipsy');
 132+ if (!tipsy) {
 133+ tipsy = new Tipsy(ele, $.fn.tipsy.elementOptions(ele, options));
 134+ $.data(ele, 'tipsy', tipsy);
 135+ }
 136+ return tipsy;
 137+ }
 138+
 139+ function enter() {
 140+ var tipsy = get(this);
 141+ tipsy.hoverState = 'in';
 142+ if (options.delayIn == 0) {
 143+ tipsy.show();
 144+ } else {
 145+ tipsy.fixTitle();
 146+ setTimeout(function() { if (tipsy.hoverState == 'in') tipsy.show(); }, options.delayIn);
 147+ }
 148+ };
 149+
 150+ function leave() {
 151+ var tipsy = get(this);
 152+ tipsy.hoverState = 'out';
 153+ if (options.delayOut == 0) {
 154+ tipsy.hide();
 155+ } else {
 156+ setTimeout(function() { if (tipsy.hoverState == 'out') tipsy.hide(); }, options.delayOut);
 157+ }
 158+ };
 159+
 160+ if (!options.live) this.each(function() { get(this); });
 161+
 162+ if (options.trigger != 'manual') {
 163+ var binder = options.live ? 'live' : 'bind',
 164+ eventIn = options.trigger == 'hover' ? 'mouseenter' : 'focus',
 165+ eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur';
 166+ this[binder](eventIn, enter)[binder](eventOut, leave);
 167+ }
 168+
 169+ return this;
 170+
 171+ };
 172+
 173+ $.fn.tipsy.defaults = {
 174+ delayIn: 0,
 175+ delayOut: 0,
 176+ fade: false,
 177+ fallback: '',
 178+ gravity: 'n',
 179+ html: false,
 180+ live: false,
 181+ offset: 0,
 182+ opacity: 0.8,
 183+ title: 'title',
 184+ trigger: 'hover'
 185+ };
 186+
 187+ // Overwrite this method to provide options on a per-element basis.
 188+ // For example, you could store the gravity in a 'tipsy-gravity' attribute:
 189+ // return $.extend({}, options, {gravity: $(ele).attr('tipsy-gravity') || 'n' });
 190+ // (remember - do not modify 'options' in place!)
 191+ $.fn.tipsy.elementOptions = function(ele, options) {
 192+ return $.metadata ? $.extend({}, options, $(ele).metadata()) : options;
 193+ };
 194+
 195+ $.fn.tipsy.autoNS = function() {
 196+ return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n';
 197+ };
 198+
 199+ $.fn.tipsy.autoWE = function() {
 200+ return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w';
 201+ };
 202+
203203 })(jQuery);
Index: trunk/extensions/ArticleAssessmentPilot/js/jquery.cookie.js
@@ -19,19 +19,19 @@
2020 * @desc Create a session cookie.
2121 * @example $.cookie('the_cookie', null);
2222 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
23 - * used when the cookie was set.
 23+ * used when the cookie was set.
2424 *
2525 * @param String name The name of the cookie.
2626 * @param String value The value of the cookie.
2727 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
2828 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
29 - * If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
30 - * If set to null or omitted, the cookie will be a session cookie and will not be retained
31 - * when the the browser exits.
 29+ * If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 30+ * If set to null or omitted, the cookie will be a session cookie and will not be retained
 31+ * when the the browser exits.
3232 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
3333 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
3434 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
35 - * require a secure protocol (like HTTPS).
 35+ * require a secure protocol (like HTTPS).
3636 * @type undefined
3737 *
3838 * @name $.cookie
@@ -54,44 +54,44 @@
5555 * @author Klaus Hartl/klaus.hartl@stilbuero.de
5656 */
5757 jQuery.cookie = function(name, value, options) {
58 - if (typeof value != 'undefined') { // name and value given, set cookie
59 - options = options || {};
60 - if (value === null) {
61 - value = '';
62 - options.expires = -1;
63 - }
64 - var expires = '';
65 - if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
66 - var date;
67 - if (typeof options.expires == 'number') {
68 - date = new Date();
69 - date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
70 - } else {
71 - date = options.expires;
72 - }
73 - expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
74 - }
75 - // CAUTION: Needed to parenthesize options.path and options.domain
76 - // in the following expressions, otherwise they evaluate to undefined
77 - // in the packed version for some reason...
78 - var path = options.path ? '; path=' + (options.path) : '';
79 - var domain = options.domain ? '; domain=' + (options.domain) : '';
80 - var secure = options.secure ? '; secure' : '';
81 - document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
82 - } else { // only name given, get cookie
83 - var cookieValue = null;
84 - if (document.cookie && document.cookie != '') {
85 - var cookies = document.cookie.split(';');
86 - for (var i = 0; i < cookies.length; i++) {
87 - var cookie = jQuery.trim(cookies[i]);
88 - // Does this cookie string begin with the name we want?
89 - if (cookie.substring(0, name.length + 1) == (name + '=')) {
90 - cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
91 - break;
92 - }
93 - }
94 - }
95 - return cookieValue;
96 - }
 58+ if (typeof value != 'undefined') { // name and value given, set cookie
 59+ options = options || {};
 60+ if (value === null) {
 61+ value = '';
 62+ options.expires = -1;
 63+ }
 64+ var expires = '';
 65+ if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
 66+ var date;
 67+ if (typeof options.expires == 'number') {
 68+ date = new Date();
 69+ date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
 70+ } else {
 71+ date = options.expires;
 72+ }
 73+ expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
 74+ }
 75+ // CAUTION: Needed to parenthesize options.path and options.domain
 76+ // in the following expressions, otherwise they evaluate to undefined
 77+ // in the packed version for some reason...
 78+ var path = options.path ? '; path=' + (options.path) : '';
 79+ var domain = options.domain ? '; domain=' + (options.domain) : '';
 80+ var secure = options.secure ? '; secure' : '';
 81+ document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
 82+ } else { // only name given, get cookie
 83+ var cookieValue = null;
 84+ if (document.cookie && document.cookie != '') {
 85+ var cookies = document.cookie.split(';');
 86+ for (var i = 0; i < cookies.length; i++) {
 87+ var cookie = jQuery.trim(cookies[i]);
 88+ // Does this cookie string begin with the name we want?
 89+ if (cookie.substring(0, name.length + 1) == (name + '=')) {
 90+ cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
 91+ break;
 92+ }
 93+ }
 94+ }
 95+ return cookieValue;
 96+ }
9797 };
9898
Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js
@@ -2,7 +2,7 @@
33 $.ArticleAssessment = {
44 'config': {
55 'authtoken': '',
6 - 'userID': '',
 6+ 'userID': wgUserName,
77 'pageID': wgArticleId,
88 'revID': wgCurRevisionId
99 },
@@ -16,13 +16,13 @@
1717 ],
1818 'fieldHintSuffix': '-tooltip',
1919 'fieldPrefix': 'articleassessment-rating-',
20 - 'fieldHTML': '<div class="field-wrapper"> \
 20+ 'fieldHTML': '<div class="field-wrapper" id="articleassessment-rate-{FIELD}"> \
2121 <label for="rating_{FIELD}" original-title="{HINT}" class="rating-field-label">{LABEL}</label> \
22 - <select id="rating_{FIELD}" name="rating{FIELD}" class="rating-field"> \
 22+ <select id="rating_{FIELD}" name="rating[{FIELD}]" class="rating-field"> \
2323 <option value="1">1</option> \
2424 <option value="2">2</option> \
2525 <option value="3">3</option> \
26 - <option value="4" selected>4</option> \
 26+ <option value="4">4</option> \
2727 <option value="5">5</option> \
2828 </select> \
2929 </div>',
@@ -62,18 +62,33 @@
6363 'init': function( $$options ) {
6464 // merge options with the config
6565 var settings = $.extend( {}, $.ArticleAssessment.settings, $$options );
 66+ var config = $.ArticleAssessment.config;
 67+ // if this is an anon user, get a unique identifier for them
6668 // load up the stored ratings and update the markup if the cookie exists
6769 var cookieSettings = $.cookie( 'mwArticleAssessment' );
68 - if ( cookieSettings == null ) {
 70+ if ( true || typeof cookieSettings == 'undefined' ) {
 71+ function randomString( string_length ) {
 72+ var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
 73+ var randomstring = '';
 74+ for (var i=0; i<string_length; i++) {
 75+ var rnum = Math.floor(Math.random() * chars.length);
 76+ randomstring += chars.substring(rnum,rnum+1);
 77+ }
 78+ return randomstring;
 79+ }
6980 cookieSettings = {
70 - 'ratings': { }
 81+ uid: randomString( 32 )
7182 };
7283 $.cookie( 'mwArticleAssessment', cookieSettings );
7384 }
 85+ if ( ! wgUserName ) {
 86+ config.userID = cookieSettings.uid;
 87+ }
7488 // setup our markup
7589 var $output = $( settings.structureHTML
7690 .replace( /\{INSTRUCTIONS\}/g, mw.usability.getMsg('articleassessment-pleaserate') )
77 - .replace( /\{FEEDBACK\}/g, mw.usability.getMsg('articleassessment-featurefeedback') )
 91+ .replace( /\{FEEDBACK\}/g, mw.usability.getMsg('articleassessment-featurefeedback')
 92+ .replace( /\[\[([^\|\]]*)\|([^\|\]]*)\]\]/, '<a href="' + wgArticlePath + '">$2</a>' ) )
7893 .replace( /\{YOURFEEDBACK\}/g, mw.usability.getMsg('articleassessment-yourfeedback') )
7994 .replace( /\{ARTICLERATING\}/g, mw.usability.getMsg('articleassessment-articlerating' ) )
8095 .replace( /\{RESULTSHIDE\}/g, mw.usability.getMsg('articleassessment-results-hide' )
@@ -84,17 +99,17 @@
85100 $output.find( '.article-assessment-rating-fields' )
86101 .append( $( settings.fieldHTML
87102 .replace( /\{LABEL\}/g, mw.usability.getMsg( settings.fieldPrefix + settings.fieldMessages[field] ) )
88 - .replace( /\{FIELD\}/g, "[" + settings.fieldMessages[field] + "]" )
 103+ .replace( /\{FIELD\}/g, settings.fieldMessages[field] )
89104 .replace( /\{HINT\}/g, mw.usability.getMsg( settings.fieldPrefix + settings.fieldMessages[field] + settings.fieldHintSuffix ) ) ) );
90105 $output.find( '#article-assessment-ratings' )
91106 .append( $( settings.ratingHTML
92107 .replace( /\{LABEL\}/g, mw.usability.getMsg(settings.fieldPrefix + settings.fieldMessages[field]) )
93108 .replace( /\{FIELD\}/g, settings.fieldMessages[field] )
94109 .replace( /\{VALUE\}/g, '0%' )
95 - .replace( /\{COUNT\}/g, mw.usability.getMsg( 'field-count' ) ) )
 110+ .replace( /\{COUNT\}/g, mw.usability.getMsg( 'articleassessment-noratings', [0, 0] ) ) )
96111 );
97112 }
98 - $output.find( '#article-assessment' ).data( 'articleAssessment-context', { 'settings': settings });
 113+ $output.find( '#article-assessment' ).data( 'articleAssessment-context', { 'settings': settings, 'config': config } );
99114 // hook up the ratings show/hide
100115 $output
101116 .find( '.article-assessment-show-ratings a' )
@@ -136,9 +151,6 @@
137152 // attempt to fetch the ratings
138153 $.ArticleAssessment.fn.getRatingData();
139154
140 - // attempt to fetch the user's past ratings if it looks like they may have rated this article before
141 - $.ArticleAssessment.fn.getUserRatingData();
142 -
143155 // initialize the star plugin
144156 $( '.rating-field' ).each( function() {
145157 $( this )
@@ -174,6 +186,7 @@
175187 'list': 'articleassessment',
176188 'aarevid': wgCurRevisionId,
177189 'aapageid': wgArticleId,
 190+ 'aauserrating': 1,
178191 'format': 'json'
179192 },
180193 dataType: 'json',
@@ -188,26 +201,35 @@
189202 'afterGetRatingData' : function( data ) {
190203 var settings = $( '#article-assessment' ).data( 'articleAssessment-context' ).settings;
191204 // add the correct data to the markup
192 - for( rating in data.query.articleassessment[0].ratings) {
193 - var rating = data.query.articleassessment[0].ratings[rating],
194 - $rating = $( '#' + rating.ratingdesc ),
195 - label = mw.usability.getMsg( 'articleassessment-noratings', [rating.total, rating.count] );
196 - $rating
197 - .find( '.article-assessment-rating-field-value' )
198 - .text( rating.total )
199 - .end()
200 - .find( '.article-assessment-rating-count' )
201 - .text( label );
 205+ if( data.query.articleassessment.length > 0 ) {
 206+ for( rating in data.query.articleassessment[0].ratings) {
 207+ var rating = data.query.articleassessment[0].ratings[rating],
 208+ $rating = $( '#' + rating.ratingdesc ),
 209+ label = mw.usability.getMsg( 'articleassessment-noratings', [rating.total, rating.count] );
 210+ $rating
 211+ .find( '.article-assessment-rating-field-value' )
 212+ .text( rating.total )
 213+ .end()
 214+ .find( '.article-assessment-rating-count' )
 215+ .text( label );
 216+ if( rating.userrating ) {
 217+ var $rateControl = $( '#' + rating.ratingdesc.replace( 'rating', 'rate' ) + ' .rating-field' );
 218+ $rateControl.children( '.ui-stars-star' ).eq( rating.userrating - 1 ).click();
 219+ }
 220+ }
 221+ // if the rating is stale, add the stale class
 222+ if( true /* replace with conditional based on returned results of past user ratings */ ) {
 223+ // add the stale star class to each on star
 224+ $( '.ui-stars-star-on' )
 225+ .addClass( 'ui-stars-star-stale' );
 226+ // add the stale message
 227+ $( '.article-assessment-submit' )
 228+ .append( settings.staleMSG.replace( /\{MSG\}/g, mw.usability.getMsg( 'articleassessment-stalemessage-revisioncount' )
 229+ .replace( /'''([^']*)'''/g, '<strong>$1</strong >' )
 230+ .replace( /''([^']*)''/, '<em>$1</em>' ) ) );
 231+ }
202232 }
203 - // if the rating is stale, add the stale class
204 - if( true /* replace with conditional based on returned results of past user ratings */ ) {
205 - // add the stale star class to each on star
206 - $( '.ui-stars-star-on' )
207 - .addClass( 'ui-stars-star-stale' );
208 - // add the stale message
209 - $( '.article-assessment-submit' )
210 - .append( settings.staleMSG.replace( /\{MSG\}/g, mw.usability.getMsg( 'articleassessment-stalemessage-revisioncount' ) ) );
211 - }
 233+
212234 // initialize the ratings
213235 $( '.article-assessment-rating-field-value' ).each( function() {
214236 $( this )
@@ -216,26 +238,8 @@
217239 } )
218240 } );
219241 },
220 - 'getUserRatingData': function() {
221 - var request = $.ajax( {
222 - url: wgScriptPath + '/api.php',
223 - data: {
224 - 'action': 'articleassessment',
225 - 'getUserResults': 1,
226 - 'userId': wgUserName || "",
227 - 'pageId': wgArticleId,
228 - 'revId': wgCurRevisionId
229 - },
230 - dataType: 'json',
231 - success: function( data ) {
232 - console.log(data);
233 - },
234 - error: function(XMLHttpRequest, textStatus, errorThrown) {
235 - // console.log( XMLHttpRequest, textStatus, errorThrown );
236 - }
237 - } );
238 - },
239242 'submitRating': function() {
 243+ var config = $( '#article-assessment' ).data( 'articleAssessment-context' ).config;
240244 // clear out the stale message
241245 var results = {};
242246 $( '.rating-field input' ).each( function() {
@@ -248,12 +252,13 @@
249253 url: wgScriptPath + '/api.php',
250254 data: {
251255 'action': 'articleassessment',
252 - 'aarevid': wgCurRevisionId,
253 - 'aapageid': wgArticleId,
 256+ 'aarevid': config.revID,
 257+ 'aapageid': config.pageID,
254258 'aar1' : results['wellsourced'],
255259 'aar2' : results['neutrality'],
256260 'aar3' : results['completeness'],
257261 'aar4' : results['readability'],
 262+ 'aauserid': config.userID,
258263 'format': 'json'
259264 },
260265 dataType: 'json',
@@ -261,7 +266,10 @@
262267 console.log(data);
263268 }
264269 } );
265 - }
 270+ },
 271+ 'flashNotice': function( text, options ) {
 272+
 273+ }
266274 }
267275 };
268276 // FIXME - this should be moved out of here
Index: trunk/extensions/ArticleAssessmentPilot/js/jquery.stars.js
@@ -6,7 +6,7 @@
77 * Marek "Orkan" Zajac (orkans@gmail.com)
88 * http://plugins.jquery.com/project/Star_Rating_widget
99 *
10 - *
 10+ * TODO: Non of the API functions are working right now. Need to rewrite more of this so they will
1111 */
1212 (function($) {
1313 $.stars = {
@@ -235,7 +235,7 @@
236236 value: function() {
237237 return this.options.value;
238238 },
239 - select: function(val) {
 239+ select: function( val ) {
240240 var o = this.options, e = (val == o.cancelValue) ? this.$cancel : this.$stars.eq(o.val2id[val]);
241241 o.forceSelect = true;
242242 e.triggerHandler('click.stars');
@@ -269,9 +269,37 @@
270270 o.oneVoteOnly && !o.disabled && this.disable();
271271 }
272272 }
273 -$.fn.stars = function ( $$options ) {
 273+$.fn.stars = function ( ) {
 274+ var args = arguments;
 275+
 276+ // var context = $( this ).data( 'stars-context' );
 277+ // if ( typeof context == 'undefined' || context == null ) {
 278+ // context = {
 279+ // options: {
 280+ // }
 281+ // };
 282+ // }
 283+ // // // Handle various calling styles
 284+ // if ( args.length > 0 ) {
 285+ // if ( typeof args[0] == 'object' ) {
 286+ // // Apply set of properties
 287+ // // for ( var key in args[0] ) {
 288+ // // $.suggestions.configure( context, key, args[0][key] );
 289+ // // }
 290+ // return $( this ).each( function() {
 291+ // $.stars.init( this, args[0] );
 292+ // } );
 293+ // } else if ( typeof args[0] == 'string' ) {
 294+ // // call the function
 295+ // var funcName = args[0];
 296+ // delete args[0];
 297+ // return $( this ).each( function() {
 298+ // $.stars[funcName]( args );
 299+ // } );
 300+ // }
 301+ // }
274302 return $( this ).each( function() {
275 - $.stars.init( this, $$options );
 303+ $.stars.init( this, args[0] );
276304 } );
277305 };
278306 } )( jQuery );

Status & tagging log