Index: trunk/extensions/ArticleAssessmentPilot/test.html |
— | — | @@ -9,7 +9,7 @@ |
10 | 10 | </script> |
11 | 11 | <script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript" charset="utf-8"></script> |
12 | 12 | <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script> |
13 | | - <script src="js/jquery.ui.stars.js" type="text/javascript" charset="utf-8"></script> |
| 13 | + <script src="js/jquery.stars.js" type="text/javascript" charset="utf-8"></script> |
14 | 14 | <script src="js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script> |
15 | 15 | <script src="js/jquery.tipsy.js" type="text/javascript" charset="utf-8"></script> |
16 | 16 | |
Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.i18n.php |
— | — | @@ -10,7 +10,7 @@ |
11 | 11 | 'articleassessment' => 'Article assessment', |
12 | 12 | 'articleassessment-desc' => 'Article assessment pilot version', |
13 | 13 | 'articleassessment-yourfeedback' => 'Your feedback', |
14 | | - 'articleassessment-pleaserate' => "''Please take a moment to rate this page below.''", |
| 14 | + 'articleassessment-pleaserate' => "Please take a moment to rate this page below.", |
15 | 15 | 'articleassessment-submit' => 'Submit', |
16 | 16 | 'articleassessment-rating-wellsourced' => 'Well sourced:', |
17 | 17 | 'articleassessment-rating-neutrality' => 'Neutrality:', |
— | — | @@ -31,6 +31,6 @@ |
32 | 32 | 'articleassessment-stalemessage-norevisioncount' => "This article has been ''revised'' since you last reviewed it. You may wish to re-rate it.", |
33 | 33 | |
34 | 34 | # FIXME: Invalid links |
35 | | - 'articleassessment-results-show' => "''(Results hidden. [[|Show]] them.)''", |
36 | | - 'articleassessment-results-hide' => "''([[|Hide results]])''", |
| 35 | + 'articleassessment-results-show' => "(Results hidden. [[|Show]] them.)", |
| 36 | + 'articleassessment-results-hide' => "([[|Hide Results]])", |
37 | 37 | ); |
Index: trunk/extensions/ArticleAssessmentPilot/css/ArticleAssessment.css |
— | — | @@ -1,6 +1,3 @@ |
2 | | -.aa-rating-field { |
3 | | - |
4 | | -} |
5 | 2 | /*! |
6 | 3 | * jQuery UI Stars v3.0.1 |
7 | 4 | * http://plugins.jquery.com/project/Star_Rating_widget |
— | — | @@ -14,7 +11,7 @@ |
15 | 12 | * $Build: 35 (2010-05-01) |
16 | 13 | * |
17 | 14 | */ |
18 | | -.ui-stars-star { |
| 15 | +.article-assessment-wrapper .ui-stars-star { |
19 | 16 | float: left; |
20 | 17 | display: block; |
21 | 18 | overflow: hidden; |
— | — | @@ -22,39 +19,39 @@ |
23 | 20 | cursor: pointer; |
24 | 21 | padding-right: 4px; |
25 | 22 | } |
26 | | -.ui-stars-star a { |
| 23 | +.article-assessment-wrapper .ui-stars-star a { |
27 | 24 | width: 21px; |
28 | 25 | height: 21px; |
29 | 26 | display: block; |
30 | 27 | background: url(../images/stars.gif) no-repeat 0 0; |
31 | 28 | } |
32 | | -.ui-stars-star a { |
| 29 | +.article-assessment-wrapper .ui-stars-star a { |
33 | 30 | background-position: 0 0px; |
34 | 31 | } |
35 | | -.ui-stars-star-on a { |
| 32 | +.article-assessment-wrapper .ui-stars-star-on a { |
36 | 33 | background-position: 0 -42px; |
37 | 34 | } |
38 | | -.ui-stars-star-rated a { |
| 35 | +.article-assessment-wrapper .ui-stars-star-rated a { |
39 | 36 | background-position: 0 -42px; |
40 | 37 | } |
41 | | -.ui-stars-star-stale a { |
| 38 | +.article-assessment-wrapper .ui-stars-star-stale a { |
42 | 39 | background-position: 0 -63px; |
43 | 40 | } |
44 | | -.ui-stars-star-hover a { |
| 41 | +.article-assessment-wrapper .ui-stars-star-hover a { |
45 | 42 | background-position: 0 -21px; |
46 | 43 | } |
47 | | -.ui-stars-star-disabled, |
48 | | -.ui-stars-star-disabled a { |
| 44 | +.article-assessment-wrapper .ui-stars-star-disabled, |
| 45 | +.article-assessment-wrapper .ui-stars-star-disabled a { |
49 | 46 | cursor: default !important; |
50 | 47 | } |
51 | | -.ui-stars-cancel { |
| 48 | +.article-assessment-wrapper .ui-stars-cancel { |
52 | 49 | display: none; |
53 | 50 | } |
54 | 51 | /* End ui-stars styles */ |
55 | 52 | |
56 | 53 | /* Tipsy Styles */ |
57 | 54 | .tipsy { padding: 5px; font-size: 12px; position: absolute; z-index: 100000; } |
58 | | -.tipsy-inner { padding: 5px 8px 4px 8px; background-color: #d6f3ff; color: black; border: 1px solid #5dc9f4; max-width: 200px; text-align: center; } |
| 55 | +.tipsy-inner { padding: 5px 8px 4px 8px; background-color: #d6f3ff; color: black; border: 1px solid #5dc9f4; max-width: 300px; text-align: left; } |
59 | 56 | /* .tipsy-inner { border-radius: 3px; -moz-border-radius:3px; -webkit-border-radius:3px; } */ |
60 | 57 | .tipsy-arrow { position: absolute; background: url( '../images/arrow.gif' ) no-repeat top left; width: 13px; height: 13px; } |
61 | 58 | .tipsy-n .tipsy-arrow { top: 0; left: 50%; margin-left: -4px; } |
— | — | @@ -67,77 +64,127 @@ |
68 | 65 | .tipsy-w .tipsy-arrow { top: 50%; margin-top: -4px; left: 0; width: 5px; height: 9px; } |
69 | 66 | |
70 | 67 | /* End Tipsy styles */ |
71 | | -#article-assessment-rate, |
72 | | -#article-assessment-ratings { |
| 68 | +.article-assessment-wrapper #article-assessment-rate, |
| 69 | +.article-assessment-wrapper #article-assessment-ratings { |
73 | 70 | background: #f7f7f7; |
74 | 71 | float: left; |
75 | 72 | } |
76 | | -#article-assessment-ratings { |
| 73 | +.article-assessment-wrapper #article-assessment-ratings { |
77 | 74 | width: 320px; |
78 | 75 | } |
79 | | -#article-assessment-rate { |
| 76 | +.article-assessment-wrapper #article-assessment-rate { |
80 | 77 | width: 650px; |
| 78 | + margin-right: 10px; |
81 | 79 | } |
82 | | -.field-wrapper { |
| 80 | +.article-assessment-wrapper legend { |
| 81 | + font-weight: bold; |
| 82 | +} |
| 83 | +.article-assessment-wrapper .field-wrapper { |
83 | 84 | float: left; |
84 | 85 | width: 250px; |
85 | 86 | padding-right: 28px; |
86 | 87 | } |
87 | | -.rating-field { |
| 88 | +.article-assessment-wrapper .rating-field { |
88 | 89 | float: right; |
89 | 90 | line-height: 24px; |
90 | 91 | padding-right: 5px; |
91 | 92 | } |
92 | | -.rating-field-label{ |
| 93 | +.article-assessment-wrapper .rating-field-label{ |
93 | 94 | float: left; |
94 | 95 | line-height: 24px; |
95 | 96 | } |
96 | | -.rating-field-label { |
| 97 | +.article-assessment-wrapper .rating-field-label { |
97 | 98 | margin-right: 10px; |
98 | 99 | } |
99 | | -.rating-field-hint { |
| 100 | +.article-assessment-wrapper .rating-field-hint { |
100 | 101 | width: 11px; |
101 | 102 | height: 24px; |
102 | 103 | display: block; |
103 | 104 | float: right; |
104 | 105 | background: url(../images/question.gif) 0 50% no-repeat; |
105 | 106 | } |
106 | | -.article-assessment-submit { |
| 107 | +.article-assessment-wrapper .article-assessment-submit { |
107 | 108 | text-align: right; |
108 | 109 | } |
109 | | -.article-assessment-stale-msg { |
| 110 | +.article-assessment-wrapper .article-assessment-stale-msg { |
110 | 111 | background: #d6f3ff; |
111 | 112 | border: 1px solid #5dc9f4; |
112 | 113 | float: left; |
113 | | - font-size: 12px; |
| 114 | + font-size: 11px; |
| 115 | + padding: 1px 5px; |
| 116 | +} |
| 117 | +.article-assessment-wrapper .article-assessment-rating-field-name { |
| 118 | + float: left; |
| 119 | + width: 90px; |
| 120 | +} |
| 121 | +.article-assessment-wrapper .article-assessment-rating-field-value-wrapper, |
| 122 | +.article-assessment-wrapper .article-assessment-rating-field-value-disabled { |
| 123 | + background: url( ../images/rating_bg.gif ) 0 0 no-repeat; |
| 124 | + width: 120px; |
| 125 | + height: 13px; |
| 126 | + display: block; |
| 127 | + float: left; |
114 | 128 | padding: 2px; |
| 129 | + text-indent: -9999px; |
115 | 130 | } |
| 131 | +.article-assessment-wrapper .article-assessment-rate-instructions, |
| 132 | +.article-assessment-wrapper .article-assessment-rate-feedback, |
| 133 | +.article-assessment-wrapper .article-assessment-show-ratings, |
| 134 | +.article-assessment-wrapper .article-assessment-hide-ratings { |
| 135 | + font-size: 10px; |
| 136 | + font-style: italic; |
| 137 | +} |
| 138 | +.article-assessment-wrapper .article-assessment-rate-instructions { |
| 139 | + float: left; |
| 140 | +} |
| 141 | +.article-assessment-wrapper .article-assessment-rate-feedback { |
| 142 | + float: right; |
| 143 | +} |
| 144 | +.article-assessment-wrapper .article-assessment-rating-field-value-wrapper .article-assessment-rating-field-value { |
| 145 | + background: url( ../images/rating_bar.gif ) 0 0 no-repeat; |
| 146 | + height: 9px; |
| 147 | + float: right; |
| 148 | + display: block; |
| 149 | +} |
| 150 | +.article-assessment-wrapper .article-assessment-rating-field-value-disabled { |
| 151 | + background: url( ../images/rating_disabled_bg.gif ) 0 0 no-repeat; |
| 152 | +} |
| 153 | +.article-assessment-wrapper .article-assessment-wrapper .article-assessment-rating-fields { |
| 154 | + margin: 8px 0; |
| 155 | +} |
| 156 | +.article-assessment-wrapper .article-assessment-rating-fields .field-wrapper { |
| 157 | + margin-bottom: 5px; |
| 158 | +} |
116 | 159 | /* Self Clearing Floats */ |
117 | | -.field-wrapper:after, |
118 | | -.article-assessment-rating-fields:after, |
119 | | -.article-assessment-submit:after, |
120 | | -.rating-fields:after { |
| 160 | +.article-assessment-wrapper .article-assessment-information:after, |
| 161 | +.article-assessment-wrapper .field-wrapper:after, |
| 162 | +.article-assessment-wrapper .article-assessment-rating-fields:after, |
| 163 | +.article-assessment-wrapper .article-assessment-submit:after, |
| 164 | +.article-assessment-wrapper .rating-fields:after { |
121 | 165 | content: "."; |
122 | 166 | display: block; |
123 | 167 | height: 0; |
124 | 168 | clear: both; |
125 | 169 | visibility: hidden; |
126 | 170 | } |
127 | | -.field-wrapper, |
128 | | -.article-assessment-rating-fields, |
129 | | -.article-assessment-submit, |
130 | | -.rating-fields { |
| 171 | +.article-assessment-wrapper .field-wrapper, |
| 172 | +.article-assessment-wrapper .article-assessment-information, |
| 173 | +.article-assessment-wrapper .article-assessment-rating-fields, |
| 174 | +.article-assessment-wrapper .article-assessment-submit, |
| 175 | +.article-assessment-wrapper .rating-fields { |
131 | 176 | display: inline-block; |
132 | 177 | } |
133 | | -* html .field-wrapper, |
134 | | -* html .article-assessment-rating-fields, |
135 | | -* html .article-assessment-submit, |
136 | | -* html .rating-fields { |
| 178 | +* html .article-assessment-wrapper .field-wrapper, |
| 179 | +* html .article-assessment-wrapper .article-assessment-information, |
| 180 | +* html .article-assessment-wrapper .article-assessment-rating-fields, |
| 181 | +* html .article-assessment-wrapper .article-assessment-submit, |
| 182 | +* html .article-assessment-wrapper .rating-fields { |
137 | 183 | height: 1%; |
138 | 184 | } |
139 | | -.field-wrapper, |
140 | | -.article-assessment-rating-fields, |
141 | | -.article-assessment-submit, |
142 | | -.rating-fields { |
| 185 | +.article-assessment-wrapper .field-wrapper, |
| 186 | +.article-assessment-wrapper .article-assessment-information, |
| 187 | +.article-assessment-wrapper .article-assessment-rating-fields, |
| 188 | +.article-assessment-wrapper .article-assessment-submit, |
| 189 | +.article-assessment-wrapper .rating-fields { |
143 | 190 | display: block; |
144 | 191 | } |
\ No newline at end of file |
Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.hooks.php |
— | — | @@ -15,8 +15,12 @@ |
16 | 16 | array( 'src' => 'js/ArticleAssessment.js', 'version' => 1 ), |
17 | 17 | array( 'src' => 'js/jquery.cookie.js', 'version' => 1 ), |
18 | 18 | array( 'src' => 'js/jquery.tipsy.js', 'version' => 1 ), |
| 19 | + array( 'src' => 'js/jquery.stars.js', 'version' => 1 ), |
19 | 20 | ); |
| 21 | + |
20 | 22 | |
| 23 | + private static $messages = array(); |
| 24 | + |
21 | 25 | /* Static Functions */ |
22 | 26 | public static function schema() { |
23 | 27 | global $wgExtNewTables; |
— | — | @@ -43,7 +47,7 @@ |
44 | 48 | |
45 | 49 | public static function addResources( $out ) { |
46 | 50 | global $wgExtensionAssetsPath; |
47 | | - |
| 51 | + |
48 | 52 | foreach ( self::$scriptFiles as $script ) { |
49 | 53 | $out->addScriptFile( $wgExtensionAssetsPath . |
50 | 54 | "/ArticleAssessmentPilot/{$script['src']}", $script['version'] |
— | — | @@ -55,10 +59,67 @@ |
56 | 60 | "/ArticleAssessmentPilot/{$style['src']}?{$style['version']}" |
57 | 61 | ); |
58 | 62 | } |
| 63 | + |
| 64 | + // Transforms messages into javascript object members |
| 65 | + self::$messages = array( |
| 66 | + 'articleassessment', |
| 67 | + 'articleassessment-desc', |
| 68 | + 'articleassessment-yourfeedback', |
| 69 | + 'articleassessment-pleaserate', |
| 70 | + 'articleassessment-submit', |
| 71 | + 'articleassessment-rating-wellsourced', |
| 72 | + 'articleassessment-rating-neutrality', |
| 73 | + 'articleassessment-rating-completeness', |
| 74 | + 'articleassessment-rating-readability', |
| 75 | + 'articleassessment-rating-wellsourced-tooltip', |
| 76 | + 'articleassessment-rating-neutrality-tooltip', |
| 77 | + 'articleassessment-rating-completeness-tooltip', |
| 78 | + 'articleassessment-rating-readability-tooltip', |
| 79 | + 'articleassessment-articlerating', |
| 80 | + 'articleassessment-featurefeedback', |
| 81 | + 'articleassessment-noratings', |
| 82 | + 'articleassessment-stalemessage-revisioncount', |
| 83 | + 'articleassessment-stalemessage-norevisioncount', |
| 84 | + 'articleassessment-results-show', |
| 85 | + 'articleassessment-results-hide', |
| 86 | + ); |
| 87 | + |
| 88 | + foreach ( self::$messages as $i => $message ) { |
| 89 | + $escapedMessageValue = Xml::escapeJsString( wfMsg( $message ) ); |
| 90 | + $escapedMessageKey = Xml::escapeJsString( $message ); |
| 91 | + self::$messages[$i] = |
| 92 | + "'{$escapedMessageKey}':'{$escapedMessageValue}'"; |
| 93 | + } |
| 94 | + // Add javascript to document |
| 95 | + if ( count( self::$messages ) > 0 ) { |
| 96 | + $out->addScript( Html::inlineScript( |
| 97 | + 'mw.usability.addMessages({' . implode( ',', self::$messages ) . '});' |
| 98 | + ) ); |
| 99 | + } |
59 | 100 | |
60 | 101 | return true; |
61 | 102 | } |
62 | | - |
| 103 | + |
| 104 | + /** |
| 105 | + * Adds a reference to a javascript file to the head of the document |
| 106 | + * @param string $src Path to the file relative to this extension's folder |
| 107 | + * @param object $version Version number of the file |
| 108 | + */ |
| 109 | + public static function addScript( $src, $version = '' ) { |
| 110 | + // The key is Andrew's snarky 20-character way of stopping multiple inclusion of the same file. |
| 111 | + self::$scripts["$src?$version"] = array( 'src' => $src, 'version' => $version ); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Adds internationalized message definitions to the document for access |
| 116 | + * via javascript using the mw.usability.getMsg() function |
| 117 | + * @param array $messages Key names of messages to load |
| 118 | + */ |
| 119 | + public static function addMessages( $messages ) { |
| 120 | + self::$messages = array_merge( self::$messages, $messages ); |
| 121 | + } |
| 122 | + |
| 123 | + |
63 | 124 | public static function addCode( &$data, $skin ) { |
64 | 125 | $title = $skin->getTitle(); |
65 | 126 | |
Index: trunk/extensions/ArticleAssessmentPilot/js/jquery.ui.stars.js |
— | — | @@ -1,316 +0,0 @@ |
2 | | -/*! |
3 | | - * jQuery UI Stars v3.0.1 |
4 | | - * http://plugins.jquery.com/project/Star_Rating_widget |
5 | | - * |
6 | | - * Copyright (c) 2010 Marek "Orkan" Zajac (orkans@gmail.com) |
7 | | - * Dual licensed under the MIT and GPL licenses. |
8 | | - * http://docs.jquery.com/License |
9 | | - * |
10 | | - * $Rev: 164 $ |
11 | | - * $Date:: 2010-05-01 #$ |
12 | | - * $Build: 35 (2010-05-01) |
13 | | - * |
14 | | - * Depends: |
15 | | - * jquery.ui.core.js |
16 | | - * jquery.ui.widget.js |
17 | | - * |
18 | | - */ |
19 | | -(function($) { |
20 | | - |
21 | | -$.widget('ui.stars', { |
22 | | - options: { |
23 | | - inputType: 'radio', // [radio|select] |
24 | | - split: 0, // decrease number of stars by splitting each star into pieces [2|3|4|...] |
25 | | - disabled: false, // set to [true] to make the stars initially disabled |
26 | | - cancelTitle: 'Cancel Rating', |
27 | | - cancelValue: 0, // default value of Cancel btn. |
28 | | - cancelShow: true, |
29 | | - disableValue: true, // set to [false] to not disable the hidden input when Cancel btn is clicked, so the value will present in POST data. |
30 | | - oneVoteOnly: false, |
31 | | - showTitles: false, |
32 | | - captionEl: null, // jQuery object - target for text captions |
33 | | - callback: null, // function(ui, type, value, event) |
34 | | - |
35 | | - /* |
36 | | - * CSS classes |
37 | | - */ |
38 | | - starWidth: 16, // width of the star image |
39 | | - cancelClass: 'ui-stars-cancel', |
40 | | - starClass: 'ui-stars-star', |
41 | | - starOnClass: 'ui-stars-star-on', |
42 | | - starHoverClass: 'ui-stars-star-hover', |
43 | | - starDisabledClass: 'ui-stars-star-disabled', |
44 | | - cancelHoverClass: 'ui-stars-cancel-hover', |
45 | | - cancelDisabledClass: 'ui-stars-cancel-disabled' |
46 | | - }, |
47 | | - |
48 | | - _create: function() { |
49 | | - var self = this, o = this.options, starId = 0; |
50 | | - this.element.data('former.stars', this.element.html()); |
51 | | - |
52 | | - o.isSelect = o.inputType == 'select'; |
53 | | - this.$form = $(this.element).closest('form'); |
54 | | - this.$selec = o.isSelect ? $('select', this.element) : null; |
55 | | - this.$rboxs = o.isSelect ? $('option', this.$selec) : $(':radio', this.element); |
56 | | - |
57 | | - /* |
58 | | - * Map all inputs from $rboxs array to Stars elements |
59 | | - */ |
60 | | - this.$stars = this.$rboxs.map(function(i) |
61 | | - { |
62 | | - var el = { |
63 | | - value: this.value, |
64 | | - title: (o.isSelect ? this.text : this.title) || this.value, |
65 | | - isDefault: (o.isSelect && this.defaultSelected) || this.defaultChecked |
66 | | - }; |
67 | | - |
68 | | - if(i==0) { |
69 | | - o.split = typeof o.split != 'number' ? 0 : o.split; |
70 | | - o.val2id = []; |
71 | | - o.id2val = []; |
72 | | - o.id2title = []; |
73 | | - o.name = o.isSelect ? self.$selec.get(0).name : this.name; |
74 | | - o.disabled = o.disabled || (o.isSelect ? $(self.$selec).attr('disabled') : $(this).attr('disabled')); |
75 | | - } |
76 | | - |
77 | | - /* |
78 | | - * Consider it as a Cancel button? |
79 | | - */ |
80 | | - if(el.value == o.cancelValue) { |
81 | | - o.cancelTitle = el.title; |
82 | | - return null; |
83 | | - } |
84 | | - |
85 | | - o.val2id[el.value] = starId; |
86 | | - o.id2val[starId] = el.value; |
87 | | - o.id2title[starId] = el.title; |
88 | | - |
89 | | - if(el.isDefault) { |
90 | | - o.checked = starId; |
91 | | - o.value = o.defaultValue = el.value; |
92 | | - o.title = el.title; |
93 | | - } |
94 | | - |
95 | | - var $s = $('<div/>').addClass(o.starClass); |
96 | | - var $a = $('<a/>').attr('title', o.showTitles ? el.title : '').text(el.value); |
97 | | - |
98 | | - /* |
99 | | - * Prepare division settings |
100 | | - */ |
101 | | - if(o.split) { |
102 | | - var oddeven = (starId % o.split); |
103 | | - var stwidth = Math.floor(o.starWidth / o.split); |
104 | | - $s.width(stwidth); |
105 | | - $a.css('margin-left', '-' + (oddeven * stwidth) + 'px'); |
106 | | - } |
107 | | - |
108 | | - starId++; |
109 | | - return $s.append($a).get(0); |
110 | | - }); |
111 | | - |
112 | | - /* |
113 | | - * How many Stars? |
114 | | - */ |
115 | | - o.items = starId; |
116 | | - |
117 | | - /* |
118 | | - * Remove old content |
119 | | - */ |
120 | | - o.isSelect ? this.$selec.remove() : this.$rboxs.remove(); |
121 | | - |
122 | | - /* |
123 | | - * Append Stars interface |
124 | | - */ |
125 | | - this.$cancel = $('<div/>').addClass(o.cancelClass).append( $('<a/>').attr('title', o.showTitles ? o.cancelTitle : '').text(o.cancelValue) ); |
126 | | - o.cancelShow &= !o.disabled && !o.oneVoteOnly; |
127 | | - o.cancelShow && this.element.append(this.$cancel); |
128 | | - this.element.append(this.$stars); |
129 | | - |
130 | | - /* |
131 | | - * Initial selection |
132 | | - */ |
133 | | - if(o.checked === undefined) { |
134 | | - o.checked = -1; |
135 | | - o.value = o.defaultValue = o.cancelValue; |
136 | | - o.title = ''; |
137 | | - } |
138 | | - |
139 | | - /* |
140 | | - * The only FORM element, that has been linked to the stars control. The value field is updated on each Star click event |
141 | | - */ |
142 | | - this.$value = $("<input type='hidden' name='"+o.name+"' value='"+o.value+"' />"); |
143 | | - this.element.append(this.$value); |
144 | | - |
145 | | - |
146 | | - /* |
147 | | - * Attach stars event handler |
148 | | - */ |
149 | | - this.$stars.bind('click.stars', function(e) { |
150 | | - if(!o.forceSelect && o.disabled) return false; |
151 | | - |
152 | | - var i = self.$stars.index(this); |
153 | | - o.checked = i; |
154 | | - o.value = o.id2val[i]; |
155 | | - o.title = o.id2title[i]; |
156 | | - self.$value.attr({disabled: o.disabled ? 'disabled' : '', value: o.value}); |
157 | | - |
158 | | - fillTo(i, false); |
159 | | - self._disableCancel(); |
160 | | - |
161 | | - !o.forceSelect && self.callback(e, 'star'); |
162 | | - }) |
163 | | - .bind('mouseover.stars', function() { |
164 | | - if(o.disabled) return false; |
165 | | - var i = self.$stars.index(this); |
166 | | - fillTo(i, true); |
167 | | - }) |
168 | | - .bind('mouseout.stars', function() { |
169 | | - if(o.disabled) return false; |
170 | | - fillTo(self.options.checked, false); |
171 | | - }); |
172 | | - |
173 | | - |
174 | | - /* |
175 | | - * Attach cancel event handler |
176 | | - */ |
177 | | - this.$cancel.bind('click.stars', function(e) { |
178 | | - if(!o.forceSelect && (o.disabled || o.value == o.cancelValue)) return false; |
179 | | - |
180 | | - o.checked = -1; |
181 | | - o.value = o.cancelValue; |
182 | | - o.title = ''; |
183 | | - |
184 | | - self.$value.val(o.value); |
185 | | - o.disableValue && self.$value.attr({disabled: 'disabled'}); |
186 | | - |
187 | | - fillNone(); |
188 | | - self._disableCancel(); |
189 | | - |
190 | | - !o.forceSelect && self.callback(e, 'cancel'); |
191 | | - }) |
192 | | - .bind('mouseover.stars', function() { |
193 | | - if(self._disableCancel()) return false; |
194 | | - self.$cancel.addClass(o.cancelHoverClass); |
195 | | - fillNone(); |
196 | | - self._showCap(o.cancelTitle); |
197 | | - }) |
198 | | - .bind('mouseout.stars', function() { |
199 | | - if(self._disableCancel()) return false; |
200 | | - self.$cancel.removeClass(o.cancelHoverClass); |
201 | | - self.$stars.triggerHandler('mouseout.stars'); |
202 | | - }); |
203 | | - |
204 | | - |
205 | | - /* |
206 | | - * Attach onReset event handler to the parent FORM |
207 | | - */ |
208 | | - this.$form.bind('reset.stars', function(){ |
209 | | - !o.disabled && self.select(o.defaultValue); |
210 | | - }); |
211 | | - |
212 | | - |
213 | | - /* |
214 | | - * Clean up to avoid memory leaks in certain versions of IE 6 |
215 | | - */ |
216 | | - $(window).unload(function(){ |
217 | | - self.$cancel.unbind('.stars'); |
218 | | - self.$stars.unbind('.stars'); |
219 | | - self.$form.unbind('.stars'); |
220 | | - self.$selec = self.$rboxs = self.$stars = self.$value = self.$cancel = self.$form = null; |
221 | | - }); |
222 | | - |
223 | | - |
224 | | - /* |
225 | | - * Star selection helpers |
226 | | - */ |
227 | | - function fillTo(index, hover) { |
228 | | - if(index != -1) { |
229 | | - var addClass = hover ? o.starHoverClass : o.starOnClass; |
230 | | - var remClass = hover ? o.starOnClass : o.starHoverClass; |
231 | | - self.$stars.eq(index).prevAll('.' + o.starClass).andSelf().removeClass(remClass).addClass(addClass); |
232 | | - self.$stars.eq(index).nextAll('.' + o.starClass).removeClass(o.starHoverClass + ' ' + o.starOnClass); |
233 | | - self._showCap(o.id2title[index]); |
234 | | - } |
235 | | - else fillNone(); |
236 | | - }; |
237 | | - function fillNone() { |
238 | | - self.$stars.removeClass(o.starOnClass + ' ' + o.starHoverClass); |
239 | | - self._showCap(''); |
240 | | - }; |
241 | | - |
242 | | - |
243 | | - /* |
244 | | - * Finally, set up the Stars |
245 | | - */ |
246 | | - this.select(o.value); |
247 | | - o.disabled && this.disable(); |
248 | | - |
249 | | - }, |
250 | | - |
251 | | - /* |
252 | | - * Private functions |
253 | | - */ |
254 | | - _disableCancel: function() { |
255 | | - var o = this.options, disabled = o.disabled || o.oneVoteOnly || (o.value == o.cancelValue); |
256 | | - if(disabled) this.$cancel.removeClass(o.cancelHoverClass).addClass(o.cancelDisabledClass); |
257 | | - else this.$cancel.removeClass(o.cancelDisabledClass); |
258 | | - this.$cancel.css('opacity', disabled ? 0.5 : 1); |
259 | | - return disabled; |
260 | | - }, |
261 | | - _disableAll: function() { |
262 | | - var o = this.options; |
263 | | - this._disableCancel(); |
264 | | - if(o.disabled) this.$stars.filter('div').addClass(o.starDisabledClass); |
265 | | - else this.$stars.filter('div').removeClass(o.starDisabledClass); |
266 | | - }, |
267 | | - _showCap: function(s) { |
268 | | - var o = this.options; |
269 | | - if(o.captionEl) o.captionEl.text(s); |
270 | | - }, |
271 | | - |
272 | | - /* |
273 | | - * Public functions |
274 | | - */ |
275 | | - value: function() { |
276 | | - return this.options.value; |
277 | | - }, |
278 | | - select: function(val) { |
279 | | - var o = this.options, e = (val == o.cancelValue) ? this.$cancel : this.$stars.eq(o.val2id[val]); |
280 | | - o.forceSelect = true; |
281 | | - e.triggerHandler('click.stars'); |
282 | | - o.forceSelect = false; |
283 | | - }, |
284 | | - selectID: function(id) { |
285 | | - var o = this.options, e = (id == -1) ? this.$cancel : this.$stars.eq(id); |
286 | | - o.forceSelect = true; |
287 | | - e.triggerHandler('click.stars'); |
288 | | - o.forceSelect = false; |
289 | | - }, |
290 | | - enable: function() { |
291 | | - this.options.disabled = false; |
292 | | - this._disableAll(); |
293 | | - }, |
294 | | - disable: function() { |
295 | | - this.options.disabled = true; |
296 | | - this._disableAll(); |
297 | | - }, |
298 | | - destroy: function() { |
299 | | - this.$form.unbind('.stars'); |
300 | | - this.$cancel.unbind('.stars').remove(); |
301 | | - this.$stars.unbind('.stars').remove(); |
302 | | - this.$value.remove(); |
303 | | - this.element.unbind('.stars').html(this.element.data('former.stars')).removeData('stars'); |
304 | | - return this; |
305 | | - }, |
306 | | - callback: function(e, type) { |
307 | | - var o = this.options; |
308 | | - o.callback && o.callback(this, type, o.value, e); |
309 | | - o.oneVoteOnly && !o.disabled && this.disable(); |
310 | | - } |
311 | | -}); |
312 | | - |
313 | | -$.extend($.ui.stars, { |
314 | | - version: '3.0.1' |
315 | | -}); |
316 | | - |
317 | | -})(jQuery); |
Index: trunk/extensions/ArticleAssessmentPilot/js/jquery.ui.stars.min.js |
— | — | @@ -1,18 +0,0 @@ |
2 | | -/* |
3 | | - * jQuery UI Stars v3.0.1 |
4 | | - * http://plugins.jquery.com/project/Star_Rating_widget |
5 | | - * |
6 | | - * Copyright (c) 2010 Marek "Orkan" Zajac (orkans@gmail.com) |
7 | | - * Dual licensed under the MIT and GPL licenses. |
8 | | - * http://docs.jquery.com/License |
9 | | - * |
10 | | - * $Rev: 164 $ |
11 | | - * $Date:: 2010-05-01 #$ |
12 | | - * $Build: 35 (2010-05-01) |
13 | | - * |
14 | | - * Depends: |
15 | | - * jquery.ui.core.js |
16 | | - * jquery.ui.widget.js |
17 | | - * |
18 | | - */ |
19 | | -(function(A){A.widget("ui.stars",{options:{inputType:"radio",split:0,disabled:false,cancelTitle:"Cancel Rating",cancelValue:0,cancelShow:true,disableValue:true,oneVoteOnly:false,showTitles:false,captionEl:null,callback:null,starWidth:16,cancelClass:"ui-stars-cancel",starClass:"ui-stars-star",starOnClass:"ui-stars-star-on",starHoverClass:"ui-stars-star-hover",starDisabledClass:"ui-stars-star-disabled",cancelHoverClass:"ui-stars-cancel-hover",cancelDisabledClass:"ui-stars-cancel-disabled"},_create:function(){var C=this,F=this.options,B=0;this.element.data("former.stars",this.element.html());F.isSelect=F.inputType=="select";this.$form=A(this.element).closest("form");this.$selec=F.isSelect?A("select",this.element):null;this.$rboxs=F.isSelect?A("option",this.$selec):A(":radio",this.element);this.$stars=this.$rboxs.map(function(I){var J={value:this.value,title:(F.isSelect?this.text:this.title)||this.value,isDefault:(F.isSelect&&this.defaultSelected)||this.defaultChecked};if(I==0){F.split=typeof F.split!="number"?0:F.split;F.val2id=[];F.id2val=[];F.id2title=[];F.name=F.isSelect?C.$selec.get(0).name:this.name;F.disabled=F.disabled||(F.isSelect?A(C.$selec).attr("disabled"):A(this).attr("disabled"))}if(J.value==F.cancelValue){F.cancelTitle=J.title;return null}F.val2id[J.value]=B;F.id2val[B]=J.value;F.id2title[B]=J.title;if(J.isDefault){F.checked=B;F.value=F.defaultValue=J.value;F.title=J.title}var H=A("<div/>").addClass(F.starClass);var K=A("<a/>").attr("title",F.showTitles?J.title:"").text(J.value);if(F.split){var G=(B%F.split);var L=Math.floor(F.starWidth/F.split);H.width(L);K.css("margin-left","-"+(G*L)+"px")}B++;return H.append(K).get(0)});F.items=B;F.isSelect?this.$selec.remove():this.$rboxs.remove();this.$cancel=A("<div/>").addClass(F.cancelClass).append(A("<a/>").attr("title",F.showTitles?F.cancelTitle:"").text(F.cancelValue));F.cancelShow&=!F.disabled&&!F.oneVoteOnly;F.cancelShow&&this.element.append(this.$cancel);this.element.append(this.$stars);if(F.checked===undefined){F.checked=-1;F.value=F.defaultValue=F.cancelValue;F.title=""}this.$value=A("<input type='hidden' name='"+F.name+"' value='"+F.value+"' />");this.element.append(this.$value);this.$stars.bind("click.stars",function(H){if(!F.forceSelect&&F.disabled){return false}var G=C.$stars.index(this);F.checked=G;F.value=F.id2val[G];F.title=F.id2title[G];C.$value.attr({disabled:F.disabled?"disabled":"",value:F.value});D(G,false);C._disableCancel();!F.forceSelect&&C.callback(H,"star")}).bind("mouseover.stars",function(){if(F.disabled){return false}var G=C.$stars.index(this);D(G,true)}).bind("mouseout.stars",function(){if(F.disabled){return false}D(C.options.checked,false)});this.$cancel.bind("click.stars",function(G){if(!F.forceSelect&&(F.disabled||F.value==F.cancelValue)){return false}F.checked=-1;F.value=F.cancelValue;F.title="";C.$value.val(F.value);F.disableValue&&C.$value.attr({disabled:"disabled"});E();C._disableCancel();!F.forceSelect&&C.callback(G,"cancel")}).bind("mouseover.stars",function(){if(C._disableCancel()){return false}C.$cancel.addClass(F.cancelHoverClass);E();C._showCap(F.cancelTitle)}).bind("mouseout.stars",function(){if(C._disableCancel()){return false}C.$cancel.removeClass(F.cancelHoverClass);C.$stars.triggerHandler("mouseout.stars")});this.$form.bind("reset.stars",function(){!F.disabled&&C.select(F.defaultValue)});A(window).unload(function(){C.$cancel.unbind(".stars");C.$stars.unbind(".stars");C.$form.unbind(".stars");C.$selec=C.$rboxs=C.$stars=C.$value=C.$cancel=C.$form=null});function D(G,I){if(G!=-1){var J=I?F.starHoverClass:F.starOnClass;var H=I?F.starOnClass:F.starHoverClass;C.$stars.eq(G).prevAll("."+F.starClass).andSelf().removeClass(H).addClass(J);C.$stars.eq(G).nextAll("."+F.starClass).removeClass(F.starHoverClass+" "+F.starOnClass);C._showCap(F.id2title[G])}else{E()}}function E(){C.$stars.removeClass(F.starOnClass+" "+F.starHoverClass);C._showCap("")}this.select(F.value);F.disabled&&this.disable()},_disableCancel:function(){var C=this.options,B=C.disabled||C.oneVoteOnly||(C.value==C.cancelValue);if(B){this.$cancel.removeClass(C.cancelHoverClass).addClass(C.cancelDisabledClass)}else{this.$cancel.removeClass(C.cancelDisabledClass)}this.$cancel.css("opacity",B?0.5:1);return B},_disableAll:function(){var B=this.options;this._disableCancel();if(B.disabled){this.$stars.filter("div").addClass(B.starDisabledClass)}else{this.$stars.filter("div").removeClass(B.starDisabledClass)}},_showCap:function(B){var C=this.options;if(C.captionEl){C.captionEl.text(B)}},value:function(){return this.options.value},select:function(D){var C=this.options,B=(D==C.cancelValue)?this.$cancel:this.$stars.eq(C.val2id[D]);C.forceSelect=true;B.triggerHandler("click.stars");C.forceSelect=false},selectID:function(D){var C=this.options,B=(D==-1)?this.$cancel:this.$stars.eq(D);C.forceSelect=true;B.triggerHandler("click.stars");C.forceSelect=false},enable:function(){this.options.disabled=false;this._disableAll()},disable:function(){this.options.disabled=true;this._disableAll()},destroy:function(){this.$form.unbind(".stars");this.$cancel.unbind(".stars").remove();this.$stars.unbind(".stars").remove();this.$value.remove();this.element.unbind(".stars").html(this.element.data("former.stars")).removeData("stars");return this},callback:function(C,B){var D=this.options;D.callback&&D.callback(this,B,D.value,C);D.oneVoteOnly&&!D.disabled&&this.disable()}});A.extend(A.ui.stars,{version:"3.0.1"})})(jQuery); |
\ No newline at end of file |
Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js |
— | — | @@ -3,14 +3,14 @@ |
4 | 4 | 'config': { |
5 | 5 | 'authtoken': '', |
6 | 6 | 'userID': '', |
7 | | - 'pageID': '', |
8 | | - 'revID': '' |
| 7 | + 'pageID': wgArticleId, |
| 8 | + 'revID': wgCurRevisionId |
9 | 9 | }, |
10 | 10 | 'settings': { |
11 | 11 | 'endpoint': wgScriptPath + '/api.php?', |
12 | 12 | 'fieldMessages' : [ |
13 | 13 | 'wellsourced', |
14 | | - 'aneutrality', |
| 14 | + 'neutrality', |
15 | 15 | 'completeness', |
16 | 16 | 'readability' |
17 | 17 | ], |
— | — | @@ -30,8 +30,10 @@ |
31 | 31 | <form action="rate" method="post" id="article-assessment"> \ |
32 | 32 | <fieldset id="article-assessment-rate"> \ |
33 | 33 | <legend>{YOURFEEDBACK}</legend> \ |
34 | | - <span class="article-assessment-rate-instructions">{INSTRUCTIONS}</span> \ |
35 | | - <span class="article-assessment-rate-feedback">{FEEDBACK}</span> \ |
| 34 | + <div class="article-assessment-information"> \ |
| 35 | + <span class="article-assessment-rate-instructions">{INSTRUCTIONS}</span> \ |
| 36 | + <span class="article-assessment-rate-feedback">{FEEDBACK}</span> \ |
| 37 | + </div> \ |
36 | 38 | <div class="article-assessment-rating-fields"></div> \ |
37 | 39 | <div class="article-assessment-submit"> \ |
38 | 40 | <input type="submit" value="Submit" /> \ |
— | — | @@ -39,12 +41,18 @@ |
40 | 42 | </fieldset> \ |
41 | 43 | <fieldset id="article-assessment-ratings"> \ |
42 | 44 | <legend>{ARTICLERATING}</legend> \ |
| 45 | + <div class="article-assessment-information"> \ |
| 46 | + <span class="article-assessment-show-ratings">{RESULTSSHOW}</span> \ |
| 47 | + <span class="article-assessment-hide-ratings">{RESULTSHIDE}</span> \ |
| 48 | + </div> \ |
43 | 49 | </fieldset> \ |
44 | 50 | </form> \ |
45 | 51 | </div>', |
46 | 52 | 'ratingHTML': '<div class="article-assessment-rating"> \ |
47 | 53 | <span class="article-assessment-rating-field-name">{LABEL}</span> \ |
48 | | - <span class="article-assessment-rating-field-value">{VALUE}</span> \ |
| 54 | + <span class="article-assessment-rating-field-value-wrapper"> \ |
| 55 | + <span class="article-assessment-rating-field-value">{VALUE}</span> \ |
| 56 | + </span> \ |
49 | 57 | <span class="article-assessment-rating-count">{COUNT}</span> \ |
50 | 58 | </div>', |
51 | 59 | 'staleMSG': '<span class="article-assessment-stale-msg">{MSG}</span>' |
— | — | @@ -64,29 +72,36 @@ |
65 | 73 | } |
66 | 74 | // setup our markup |
67 | 75 | var $output = $( settings.structureHTML |
68 | | - .replace( /\{INSTRUCTIONS\}/g, 'articleassessment-pleaserate' ) |
69 | | - .replace( /\{FEEDBACK\}/g, 'articleassessment-yourfeedback' ) |
70 | | - .replace( /\{YOURFEEDBACK\}/g, 'articleassessment-featurefeedback' ) |
71 | | - .replace( /\{ARTICLERATING\}/g, 'articleassessment-articlerating' ) ); |
| 76 | + .replace( /\{INSTRUCTIONS\}/g, mw.usability.getMsg('articleassessment-pleaserate') ) |
| 77 | + .replace( /\{FEEDBACK\}/g, mw.usability.getMsg('articleassessment-featurefeedback') ) |
| 78 | + .replace( /\{YOURFEEDBACK\}/g, mw.usability.getMsg('articleassessment-yourfeedback') ) |
| 79 | + .replace( /\{ARTICLERATING\}/g, mw.usability.getMsg('articleassessment-articlerating' ) ) |
| 80 | + .replace( /\{RESULTSHIDE\}/g, mw.usability.getMsg('articleassessment-results-hide' ) ) |
| 81 | + .replace( /\{RESULTSSHOW\}/g, mw.usability.getMsg('articleassessment-results-show' ) ) ); |
72 | 82 | for( var field in settings.fieldMessages ) { |
73 | 83 | $output.find( '.article-assessment-rating-fields' ) |
74 | 84 | .append( $( settings.fieldHTML |
75 | | - .replace( /\{LABEL\}/g, settings.fieldPrefix + settings.fieldMessages[field] ) |
76 | | - .replace( /\{FIELD\}/g, settings.fieldMessages[field] ) |
77 | | - .replace( /\{HINT\}/g, settings.fieldPrefix + settings.fieldMessages[field] + settings.fieldHintSuffix ) ) ); |
| 85 | + .replace( /\{LABEL\}/g, mw.usability.getMsg( settings.fieldPrefix + settings.fieldMessages[field] ) ) |
| 86 | + .replace( /\{FIELD\}/g, mw.usability.getMsg( settings.fieldMessages[field] ) ) |
| 87 | + .replace( /\{HINT\}/g, mw.usability.getMsg( settings.fieldPrefix + settings.fieldMessages[field] + settings.fieldHintSuffix ) ) ) ); |
78 | 88 | $output.find( '#article-assessment-ratings' ) |
79 | 89 | .append( $( settings.ratingHTML |
80 | | - .replace( /\{LABEL\}/g, settings.fieldPrefix + settings.fieldMessages[field] ) |
| 90 | + .replace( /\{LABEL\}/g, mw.usability.getMsg(settings.fieldPrefix + settings.fieldMessages[field]) ) |
81 | 91 | .replace( /\{VALUE\}/g, '0%' ) |
82 | | - .replace( /\{COUNT\}/g, 'field-count' ) ) |
| 92 | + .replace( /\{COUNT\}/g, mw.usability.getMsg( 'field-count' ) ) ) |
83 | 93 | ); |
84 | 94 | } |
85 | 95 | |
86 | 96 | $( '#catlinks' ).before( $output ); |
87 | 97 | |
| 98 | + // attempt to fetch the ratings |
| 99 | + $.ArticleAssessment.fn.getRatingData(); |
| 100 | + |
| 101 | + // attempt to fetch the user's past ratings if it looks like they may have rated this article before |
| 102 | + $.ArticleAssessment.fn.getUserRatingData(); |
| 103 | + |
88 | 104 | // initialize the star plugin |
89 | 105 | $( '.rating-field' ).each( function() { |
90 | | - console.log(this); |
91 | 106 | $( this ) |
92 | 107 | .wrapAll( '<div class="rating-field"></div>' ) |
93 | 108 | .parent() |
— | — | @@ -101,29 +116,72 @@ |
102 | 117 | } ); |
103 | 118 | }); |
104 | 119 | // if the rating is stale, add the stale class |
105 | | - if( true /* replace with conditional */ ) { |
| 120 | + if( true /* replace with conditional based on returned results of past user ratings */ ) { |
106 | 121 | // add the stale star class to each on star |
107 | 122 | $( '.ui-stars-star-on' ) |
108 | 123 | .addClass( 'ui-stars-star-stale' ); |
109 | 124 | // add the stale message |
110 | 125 | $( '.article-assessment-submit' ) |
111 | | - .append( settings.staleMSG.replace( /\{MSG\}/g, 'articleassessment-stalemessage-revisioncount' ) ); |
| 126 | + .append( settings.staleMSG.replace( /\{MSG\}/g, mw.usability.getMsg( 'articleassessment-stalemessage-revisioncount' ) ) ); |
112 | 127 | } |
113 | 128 | // intialize the tooltips |
114 | 129 | $( '.field-wrapper label[original-title]' ).each(function() { |
115 | 130 | $( this ) |
116 | 131 | .after( $( '<span class="rating-field-hint" />' ) |
117 | 132 | .attr( 'original-title', $( this ).attr( 'original-title' ) ) |
118 | | - .tipsy( { gravity : 'se', opacity: '0.9' } ) ); |
| 133 | + .tipsy( { gravity : 'se', opacity: '0.9', } ) ); |
119 | 134 | } ); |
120 | 135 | // initialize the ratings |
121 | | - |
| 136 | + $( '.article-assessment-rating-field-value' ).each( function() { |
| 137 | + $( this ) |
| 138 | + .css( { |
| 139 | + 'width': 120 - ( 120 * ( parseInt( $( this ).text() ) / 100 ) ) + "px" |
| 140 | + } ) |
| 141 | + } ); |
122 | 142 | // bind submit event to the form |
123 | 143 | |
124 | 144 | // prevent the submit button for being active until all ratings are filled out |
125 | 145 | |
126 | 146 | }, |
| 147 | + 'getRatingData': function() { |
| 148 | + var request = $j.ajax( { |
| 149 | + url: wgScriptPath + '/api.php', |
| 150 | + data: { |
| 151 | + 'action': 'articleassessment', |
| 152 | + 'getCumulativeResults': 1, |
| 153 | + 'pageId': wgArticleId, |
| 154 | + 'revId': wgCurRevisionId |
| 155 | + }, |
| 156 | + dataType: 'json', |
| 157 | + success: function( data ) { |
| 158 | + console.log(data); |
| 159 | + }, |
| 160 | + error: function(XMLHttpRequest, textStatus, errorThrown) { |
| 161 | + console.log(XMLHttpRequest, textStatus, errorThrown); |
| 162 | + } |
| 163 | + } ); |
| 164 | + }, |
| 165 | + 'getUserRatingData': function() { |
| 166 | + var request = $j.ajax( { |
| 167 | + url: wgScriptPath + '/api.php', |
| 168 | + data: { |
| 169 | + 'action': 'articleassessment', |
| 170 | + 'getUserResults': 1, |
| 171 | + 'userId': wgUserName || "", |
| 172 | + 'pageId': wgArticleId, |
| 173 | + 'revId': wgCurRevisionId |
| 174 | + }, |
| 175 | + dataType: 'json', |
| 176 | + success: function( data ) { |
| 177 | + console.log(data); |
| 178 | + }, |
| 179 | + error: function(XMLHttpRequest, textStatus, errorThrown) { |
| 180 | + console.log(XMLHttpRequest, textStatus, errorThrown); |
| 181 | + } |
| 182 | + } ); |
| 183 | + }, |
127 | 184 | 'submit': function() { |
| 185 | + // clear out the stale message |
128 | 186 | var request = $j.ajax( { |
129 | 187 | url: wgScriptPath + '/api.php', |
130 | 188 | data: { |
— | — | @@ -140,10 +198,7 @@ |
141 | 199 | }; |
142 | 200 | // FIXME - this should be moved out of here |
143 | 201 | $( document ).ready( function () { |
144 | | - mw.usability.load( [ '$j.ui' ], function() { |
145 | | - $.getScript( wgScriptPath + '/extensions/ArticleAssessmentPilot/js/jquery.ui.stars.js', function() { |
146 | | - $.ArticleAssessment.fn.init( { 'endpoint': wgScriptPath + "/api.php" } ); |
147 | | - } ); |
148 | | - } ); |
| 202 | + console.log(this); |
| 203 | + $.ArticleAssessment.fn.init( { 'endpoint': wgScriptPath + "/api.php" } ); |
149 | 204 | } ); //document ready |
150 | 205 | } )( jQuery ); |
\ No newline at end of file |
Index: trunk/extensions/ArticleAssessmentPilot/js/jquery.stars.js |
— | — | @@ -0,0 +1,277 @@ |
| 2 | +/*! |
| 3 | + * jQuery Stars v1 |
| 4 | + * adapted by Adam Miller (acm6603@gmail.com) 2010 |
| 5 | + * |
| 6 | + * Adapted from jQuery UI Stars v3.0.1 |
| 7 | + * Marek "Orkan" Zajac (orkans@gmail.com) |
| 8 | + * http://plugins.jquery.com/project/Star_Rating_widget |
| 9 | + * |
| 10 | + * |
| 11 | + */ |
| 12 | +(function($) { |
| 13 | +$.stars = { |
| 14 | + defaults : { |
| 15 | + inputType: 'radio', // [radio|select] |
| 16 | + split: 0, // decrease number of stars by splitting each star into pieces [2|3|4|...] |
| 17 | + disabled: false, // set to [true] to make the stars initially disabled |
| 18 | + cancelTitle: 'Cancel Rating', |
| 19 | + cancelValue: 0, // default value of Cancel btn. |
| 20 | + cancelShow: true, |
| 21 | + disableValue: true, // set to [false] to not disable the hidden input when Cancel btn is clicked, so the value will present in POST data. |
| 22 | + oneVoteOnly: false, |
| 23 | + showTitles: false, |
| 24 | + captionEl: null, // jQuery object - target for text captions |
| 25 | + callback: null, // function(ui, type, value, event) |
| 26 | + /* |
| 27 | + * CSS classes |
| 28 | + */ |
| 29 | + starWidth: 16, // width of the star image |
| 30 | + cancelClass: 'ui-stars-cancel', |
| 31 | + starClass: 'ui-stars-star', |
| 32 | + starOnClass: 'ui-stars-star-on', |
| 33 | + starHoverClass: 'ui-stars-star-hover', |
| 34 | + starDisabledClass: 'ui-stars-star-disabled', |
| 35 | + cancelHoverClass: 'ui-stars-cancel-hover', |
| 36 | + cancelDisabledClass: 'ui-stars-cancel-disabled' |
| 37 | + }, |
| 38 | + init: function( element, options ) { |
| 39 | + var context = $.extend( {}, { |
| 40 | + element: $( element ), |
| 41 | + options: $.extend( {}, this.defaults, options ) |
| 42 | + }, this ); |
| 43 | + this.create.call( context ); |
| 44 | + }, |
| 45 | + create: function( ) { |
| 46 | + var self = this, o = this.options, starId = 0; |
| 47 | + this.element.data('former.stars', this.element.html()); |
| 48 | + o.isSelect = o.inputType == 'select'; |
| 49 | + this.$form = $(this.element).closest('form'); |
| 50 | + this.$selec = o.isSelect ? $('select', this.element) : null; |
| 51 | + this.$rboxs = o.isSelect ? $('option', this.$selec) : $(':radio', this.element); |
| 52 | + /* |
| 53 | + * Map all inputs from $rboxs array to Stars elements |
| 54 | + */ |
| 55 | + this.$stars = this.$rboxs.map(function(i) |
| 56 | + { |
| 57 | + var el = { |
| 58 | + value: this.value, |
| 59 | + title: (o.isSelect ? this.text : this.title) || this.value, |
| 60 | + isDefault: (o.isSelect && this.defaultSelected) || this.defaultChecked |
| 61 | + }; |
| 62 | + if(i==0) { |
| 63 | + o.split = typeof o.split != 'number' ? 0 : o.split; |
| 64 | + o.val2id = []; |
| 65 | + o.id2val = []; |
| 66 | + o.id2title = []; |
| 67 | + o.name = o.isSelect ? self.$selec.get(0).name : this.name; |
| 68 | + o.disabled = o.disabled || (o.isSelect ? $(self.$selec).attr('disabled') : $(this).attr('disabled')); |
| 69 | + } |
| 70 | + /* |
| 71 | + * Consider it as a Cancel button? |
| 72 | + */ |
| 73 | + if(el.value == o.cancelValue) { |
| 74 | + o.cancelTitle = el.title; |
| 75 | + return null; |
| 76 | + } |
| 77 | + o.val2id[el.value] = starId; |
| 78 | + o.id2val[starId] = el.value; |
| 79 | + o.id2title[starId] = el.title; |
| 80 | + if(el.isDefault) { |
| 81 | + o.checked = starId; |
| 82 | + o.value = o.defaultValue = el.value; |
| 83 | + o.title = el.title; |
| 84 | + } |
| 85 | + var $s = $('<div/>').addClass(o.starClass); |
| 86 | + var $a = $('<a/>').attr('title', o.showTitles ? el.title : '').text(el.value); |
| 87 | + /* |
| 88 | + * Prepare division settings |
| 89 | + */ |
| 90 | + if(o.split) { |
| 91 | + var oddeven = (starId % o.split); |
| 92 | + var stwidth = Math.floor(o.starWidth / o.split); |
| 93 | + $s.width(stwidth); |
| 94 | + $a.css('margin-left', '-' + (oddeven * stwidth) + 'px'); |
| 95 | + } |
| 96 | + starId++; |
| 97 | + return $s.append($a).get(0); |
| 98 | + }); |
| 99 | + /* |
| 100 | + * How many Stars? |
| 101 | + */ |
| 102 | + o.items = starId; |
| 103 | + /* |
| 104 | + * Remove old content |
| 105 | + */ |
| 106 | + o.isSelect ? this.$selec.remove() : this.$rboxs.remove(); |
| 107 | + /* |
| 108 | + * Append Stars interface |
| 109 | + */ |
| 110 | + this.$cancel = $('<div/>').addClass(o.cancelClass).append( $('<a/>').attr('title', o.showTitles ? o.cancelTitle : '').text(o.cancelValue) ); |
| 111 | + o.cancelShow &= !o.disabled && !o.oneVoteOnly; |
| 112 | + o.cancelShow && this.element.append(this.$cancel); |
| 113 | + this.element.append(this.$stars); |
| 114 | + /* |
| 115 | + * Initial selection |
| 116 | + */ |
| 117 | + if(o.checked === undefined) { |
| 118 | + o.checked = -1; |
| 119 | + o.value = o.defaultValue = o.cancelValue; |
| 120 | + o.title = ''; |
| 121 | + } |
| 122 | + /* |
| 123 | + * The only FORM element, that has been linked to the stars control. The value field is updated on each Star click event |
| 124 | + */ |
| 125 | + this.$value = $("<input type='hidden' name='"+o.name+"' value='"+o.value+"' />"); |
| 126 | + this.element.append(this.$value); |
| 127 | + /* |
| 128 | + * Attach stars event handler |
| 129 | + */ |
| 130 | + this.$stars.bind('click.stars', function(e) { |
| 131 | + if(!o.forceSelect && o.disabled) return false; |
| 132 | + var i = self.$stars.index(this); |
| 133 | + o.checked = i; |
| 134 | + o.value = o.id2val[i]; |
| 135 | + o.title = o.id2title[i]; |
| 136 | + self.$value.attr({disabled: o.disabled ? 'disabled' : '', value: o.value}); |
| 137 | + fillTo(i, false); |
| 138 | + self.disableCancel(); |
| 139 | + !o.forceSelect && self.callback(e, 'star'); |
| 140 | + }) |
| 141 | + .bind('mouseover.stars', function() { |
| 142 | + if(o.disabled) return false; |
| 143 | + var i = self.$stars.index(this); |
| 144 | + fillTo(i, true); |
| 145 | + }) |
| 146 | + .bind('mouseout.stars', function() { |
| 147 | + if(o.disabled) return false; |
| 148 | + fillTo(self.options.checked, false); |
| 149 | + }); |
| 150 | + /* |
| 151 | + * Attach cancel event handler |
| 152 | + */ |
| 153 | + this.$cancel.bind('click.stars', function(e) { |
| 154 | + if(!o.forceSelect && (o.disabled || o.value == o.cancelValue)) return false; |
| 155 | + o.checked = -1; |
| 156 | + o.value = o.cancelValue; |
| 157 | + o.title = ''; |
| 158 | + self.$value.val(o.value); |
| 159 | + o.disableValue && self.$value.attr({disabled: 'disabled'}); |
| 160 | + fillNone(); |
| 161 | + self.disableCancel(); |
| 162 | + !o.forceSelect && self.callback(e, 'cancel'); |
| 163 | + }) |
| 164 | + .bind('mouseover.stars', function() { |
| 165 | + if(self.disableCancel()) return false; |
| 166 | + self.$cancel.addClass(o.cancelHoverClass); |
| 167 | + fillNone(); |
| 168 | + self.showCap(o.cancelTitle); |
| 169 | + }) |
| 170 | + .bind('mouseout.stars', function() { |
| 171 | + if(self.disableCancel()) return false; |
| 172 | + self.$cancel.removeClass(o.cancelHoverClass); |
| 173 | + self.$stars.triggerHandler('mouseout.stars'); |
| 174 | + }); |
| 175 | + /* |
| 176 | + * Attach onReset event handler to the parent FORM |
| 177 | + */ |
| 178 | + this.$form.bind('reset.stars', function(){ |
| 179 | + !o.disabled && self.select(o.defaultValue); |
| 180 | + }); |
| 181 | + /* |
| 182 | + * Clean up to avoid memory leaks in certain versions of IE 6 |
| 183 | + */ |
| 184 | + $(window).unload(function(){ |
| 185 | + self.$cancel.unbind('.stars'); |
| 186 | + self.$stars.unbind('.stars'); |
| 187 | + self.$form.unbind('.stars'); |
| 188 | + self.$selec = self.$rboxs = self.$stars = self.$value = self.$cancel = self.$form = null; |
| 189 | + }); |
| 190 | + /* |
| 191 | + * Star selection helpers |
| 192 | + */ |
| 193 | + function fillTo(index, hover) { |
| 194 | + if(index != -1) { |
| 195 | + var addClass = hover ? o.starHoverClass : o.starOnClass; |
| 196 | + var remClass = hover ? o.starOnClass : o.starHoverClass; |
| 197 | + self.$stars.eq(index).prevAll('.' + o.starClass).andSelf().removeClass(remClass).addClass(addClass); |
| 198 | + self.$stars.eq(index).nextAll('.' + o.starClass).removeClass(o.starHoverClass + ' ' + o.starOnClass); |
| 199 | + self.showCap(o.id2title[index]); |
| 200 | + } |
| 201 | + else fillNone(); |
| 202 | + }; |
| 203 | + function fillNone() { |
| 204 | + self.$stars.removeClass(o.starOnClass + ' ' + o.starHoverClass); |
| 205 | + self.showCap(''); |
| 206 | + }; |
| 207 | + /* |
| 208 | + * Finally, set up the Stars |
| 209 | + */ |
| 210 | + this.select( o.value ); |
| 211 | + o.disabled && this.disable(); |
| 212 | + }, |
| 213 | + /* |
| 214 | + * Private functions |
| 215 | + */ |
| 216 | + disableCancel: function() { |
| 217 | + var o = this.options, disabled = o.disabled || o.oneVoteOnly || (o.value == o.cancelValue); |
| 218 | + if(disabled) this.$cancel.removeClass(o.cancelHoverClass).addClass(o.cancelDisabledClass); |
| 219 | + else this.$cancel.removeClass(o.cancelDisabledClass); |
| 220 | + this.$cancel.css('opacity', disabled ? 0.5 : 1); |
| 221 | + return disabled; |
| 222 | + }, |
| 223 | + disableAll: function() { |
| 224 | + var o = this.options; |
| 225 | + this.disableCancel(); |
| 226 | + if(o.disabled) this.$stars.filter('div').addClass(o.starDisabledClass); |
| 227 | + else this.$stars.filter('div').removeClass(o.starDisabledClass); |
| 228 | + }, |
| 229 | + showCap: function(s) { |
| 230 | + var o = this.options; |
| 231 | + if(o.captionEl) o.captionEl.text(s); |
| 232 | + }, |
| 233 | + /* |
| 234 | + * Public functions |
| 235 | + */ |
| 236 | + value: function() { |
| 237 | + return this.options.value; |
| 238 | + }, |
| 239 | + select: function(val) { |
| 240 | + var o = this.options, e = (val == o.cancelValue) ? this.$cancel : this.$stars.eq(o.val2id[val]); |
| 241 | + o.forceSelect = true; |
| 242 | + e.triggerHandler('click.stars'); |
| 243 | + o.forceSelect = false; |
| 244 | + }, |
| 245 | + selectID: function(id) { |
| 246 | + var o = this.options, e = (id == -1) ? this.$cancel : this.$stars.eq(id); |
| 247 | + o.forceSelect = true; |
| 248 | + e.triggerHandler('click.stars'); |
| 249 | + o.forceSelect = false; |
| 250 | + }, |
| 251 | + enable: function() { |
| 252 | + this.options.disabled = false; |
| 253 | + this.disableAll(); |
| 254 | + }, |
| 255 | + disable: function() { |
| 256 | + this.options.disabled = true; |
| 257 | + this.disableAll(); |
| 258 | + }, |
| 259 | + destroy: function() { |
| 260 | + this.$form.unbind('.stars'); |
| 261 | + this.$cancel.unbind('.stars').remove(); |
| 262 | + this.$stars.unbind('.stars').remove(); |
| 263 | + this.$value.remove(); |
| 264 | + this.element.unbind('.stars').html(this.element.data('former.stars')).removeData('stars'); |
| 265 | + return this; |
| 266 | + }, |
| 267 | + callback: function(e, type) { |
| 268 | + var o = this.options; |
| 269 | + o.callback && o.callback(this, type, o.value, e); |
| 270 | + o.oneVoteOnly && !o.disabled && this.disable(); |
| 271 | + } |
| 272 | +} |
| 273 | +$.fn.stars = function ( $$options ) { |
| 274 | + return $( this ).each( function() { |
| 275 | + $.stars.init( this, $$options ); |
| 276 | + } ); |
| 277 | +}; |
| 278 | +} )( jQuery ); |
Property changes on: trunk/extensions/ArticleAssessmentPilot/js/jquery.stars.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 279 | + native |