Index: trunk/extensions/UsabilityInitiative/OptIn/OptIn.php |
— | — | @@ -63,7 +63,7 @@ |
64 | 64 | 'type' => 'resolution' ), |
65 | 65 | array( 'question' => 'optin-survey-question-feedback', |
66 | 66 | 'type' => 'textarea' ) |
67 | | -); |
| 67 | +); |
68 | 68 | |
69 | 69 | /* Setup */ |
70 | 70 | |
Index: trunk/extensions/UsabilityInitiative/OptIn/SpecialOptIn.php |
— | — | @@ -11,19 +11,19 @@ |
12 | 12 | parent::__construct( 'OptIn' ); |
13 | 13 | wfLoadExtensionMessages( 'OptIn' ); |
14 | 14 | } |
15 | | - |
| 15 | + |
16 | 16 | function execute( $par ) { |
17 | 17 | global $wgRequest, $wgOut, $wgUser; |
18 | 18 | $this->setHeaders(); |
19 | 19 | $wgOut->setPageTitle( wfMsg( 'optin-title' ) ); |
20 | | - |
| 20 | + |
21 | 21 | if ( $wgUser->isAnon() ) { |
22 | 22 | $url = SpecialPage::getTitleFor( 'Userlogin' )->getFullURL( |
23 | 23 | array( 'returnto' => $this->getTitle()->getPrefixedUrl() ) ); |
24 | 24 | $wgOut->wrapWikiMsg( "<div class='plainlinks'>\n$1\n</div>", array( 'optin-needlogin', $url ) ); |
25 | 25 | return; |
26 | 26 | } |
27 | | - |
| 27 | + |
28 | 28 | if ( $wgRequest->wasPosted() ) { |
29 | 29 | if ( $wgRequest->getVal( 'opt' ) === 'in' ) { |
30 | 30 | $this->optIn( $wgUser ); |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | } |
38 | 38 | $this->showForm(); |
39 | 39 | } |
40 | | - |
| 40 | + |
41 | 41 | function showForm() { |
42 | 42 | global $wgUser, $wgOut; |
43 | 43 | $wgOut->addHTML( Xml::openElement( 'form', array( |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | $wgOut->addHTML( Xml::submitButton( wfMsg( "optin-submit-$opt" ) ) ); |
57 | 57 | $wgOut->addHTML( Xml::closeElement( 'form' ) ); |
58 | 58 | } |
59 | | - |
| 59 | + |
60 | 60 | function isOptedIn( $user ) { |
61 | 61 | global $wgOptInPrefs; |
62 | 62 | foreach ( $wgOptInPrefs as $pref => $value ) { |
— | — | @@ -65,28 +65,28 @@ |
66 | 66 | } |
67 | 67 | return true; |
68 | 68 | } |
69 | | - |
| 69 | + |
70 | 70 | function optIn( $user ) { |
71 | 71 | global $wgOptInPrefs; |
72 | | - foreach( $wgOptInPrefs as $pref => $value ) { |
| 72 | + foreach ( $wgOptInPrefs as $pref => $value ) { |
73 | 73 | $user->setOption( $pref, $value ); |
74 | 74 | } |
75 | 75 | $user->saveSettings(); |
76 | 76 | } |
77 | | - |
| 77 | + |
78 | 78 | function optOut( $user ) { |
79 | 79 | global $wgOptInPrefs; |
80 | | - foreach( $wgOptInPrefs as $pref => $value ) { |
| 80 | + foreach ( $wgOptInPrefs as $pref => $value ) { |
81 | 81 | $user->setOption( $pref, null ); |
82 | 82 | } |
83 | 83 | $user->saveSettings(); |
84 | 84 | } |
85 | | - |
| 85 | + |
86 | 86 | function showSurvey() { |
87 | 87 | global $wgOptInSurvey, $wgOut, $wgOptInStyleVersion; |
88 | 88 | UsabilityInitiativeHooks::addScript( 'OptIn/OptIn.js', |
89 | 89 | $wgOptInStyleVersion ); |
90 | | - |
| 90 | + |
91 | 91 | $retval = Xml::openElement( 'table' ); |
92 | 92 | foreach ( $wgOptInSurvey as $id => $question ) { |
93 | 93 | switch ( $question['type'] ) { |
— | — | @@ -183,12 +183,12 @@ |
184 | 184 | $retval .= Xml::closeElement( 'table' ); |
185 | 185 | $wgOut->addHTML( $retval ); |
186 | 186 | } |
187 | | - |
| 187 | + |
188 | 188 | function saveSurvey() { |
189 | 189 | global $wgRequest, $wgUser, $wgOptInSurvey; |
190 | 190 | $dbw = wfGetDb( DB_MASTER ); |
191 | 191 | $now = $dbw->timestamp( wfTimestamp() ); |
192 | | - //var_dump($wgRequest->data); die(); |
| 192 | + // var_dump($wgRequest->data); die(); |
193 | 193 | foreach ( $wgOptInSurvey as $id => $question ) { |
194 | 194 | $insert = array( |
195 | 195 | 'ois_user' => $wgUser->getId(), |
— | — | @@ -201,7 +201,7 @@ |
202 | 202 | if ( $answer === 'other' ) { |
203 | 203 | $insert['ois_answer'] = null; |
204 | 204 | $insert['ois_answer_data'] = $wgRequest->getVal( "survey-$id-other" ); |
205 | | - } else if ($answer === '' ) { |
| 205 | + } else if ( $answer === '' ) { |
206 | 206 | $insert['ois_answer'] = null; |
207 | 207 | $insert['ois_answer_data'] = null; |
208 | 208 | } else { |
— | — | @@ -222,7 +222,7 @@ |
223 | 223 | break; |
224 | 224 | case 'textarea': |
225 | 225 | $answer = $wgRequest->getVal( "survey-$id" ); |
226 | | - if ($answer === '' ) { |
| 226 | + if ( $answer === '' ) { |
227 | 227 | $insert['ois_answer'] = null; |
228 | 228 | $insert['ois_answer_data'] = null; |
229 | 229 | } else { |
Index: trunk/extensions/UsabilityInitiative/OptIn/OptIn.js |
— | — | @@ -43,8 +43,8 @@ |
44 | 44 | browserIndex = 14; |
45 | 45 | break; |
46 | 46 | } |
47 | | - |
48 | | - var osIndex = -1; |
| 47 | + |
| 48 | + var osIndex = -1; |
49 | 49 | switch ( $.os.name ) { |
50 | 50 | case 'win': |
51 | 51 | osIndex = 0; |
— | — | @@ -56,7 +56,7 @@ |
57 | 57 | osIndex = 2; |
58 | 58 | break; |
59 | 59 | } |
60 | | - |
| 60 | + |
61 | 61 | if ( browserIndex == -1 ) |
62 | 62 | $( '#survey-1' ).val( 'other' ); |
63 | 63 | else |
— | — | @@ -65,5 +65,5 @@ |
66 | 66 | $( '#survey-2' ).val( 'other' ); |
67 | 67 | else |
68 | 68 | $( '#survey-2' ).val( osIndex ); |
69 | | - |
70 | | -}); |
\ No newline at end of file |
| 69 | + |
| 70 | +}); |
Index: trunk/extensions/UsabilityInitiative/OptIn/OptIn.sql |
— | — | @@ -5,18 +5,18 @@ |
6 | 6 | CREATE TABLE IF NOT EXISTS /*_*/optin_survey ( |
7 | 7 | -- User ID |
8 | 8 | ois_user int NOT NULL, |
9 | | - |
| 9 | + |
10 | 10 | -- Timestamp |
11 | 11 | ois_timestamp binary(14) NOT NULL, |
12 | | - |
| 12 | + |
13 | 13 | -- Question ID (key in $wgOptInSurvey) |
14 | 14 | ois_question int unsigned NOT NULL, |
15 | | - |
| 15 | + |
16 | 16 | -- Answer ID (key in $wgOptInSurvey[ois_question]['answers']) |
17 | 17 | ois_answer int unsigned NULL, |
18 | | - |
| 18 | + |
19 | 19 | -- Optional text associated with the answer |
20 | 20 | ois_answer_data text NULL |
21 | 21 | ) /*$wgDBTableOptions*/; |
22 | 22 | |
23 | | -CREATE UNIQUE INDEX /*i*/ois_user_timestamp_question ON /*_*/optin_survey (ois_user, ois_timestamp, ois_question); |
| 23 | +CREATE UNIQUE INDEX /*i*/ois_user_timestamp_question ON /*_*/optin_survey (ois_user, ois_timestamp, ois_question); |
Index: trunk/extensions/UsabilityInitiative/OptIn/OptIn.i18n.php |
— | — | @@ -17,11 +17,14 @@ |
18 | 18 | 'optin-title' => 'Usability Intitiative enhancements', |
19 | 19 | 'optin-needlogin' => 'You need to [$1 log in] to opt-in to the Usability Initiative\'s usability enhancements.', |
20 | 20 | 'optin-intro' => 'The Wikipedia Usability Initiative has developed a new skin and a new edit toolbar intended to enhance the usability of Wikipedia. These enhancements have not been enabled for all users yet, but you can opt-in to them by clicking the button below.', |
21 | | - 'optin-success-in' => 'You have successfully opted in to the Usability Initiative\'s usability enhancements. You can opt back out at any time by clicking the button below.', |
22 | | - 'optin-success-out' => 'You have successfully opted out of the Usability Initiative\'s usability enhancements. You can opt back in at any time by clicking the button below.', |
| 21 | + 'optin-success-in' => 'You have successfully opted in to the Usability Initiative\'s usability enhancements. |
| 22 | +You can opt back out at any time by clicking the button below.', |
| 23 | + 'optin-success-out' => 'You have successfully opted out of the Usability Initiative\'s usability enhancements. |
| 24 | +You can opt back in at any time by clicking the button below.', |
23 | 25 | 'optin-submit-in' => 'Opt in', |
24 | 26 | 'optin-submit-out' => 'Opt out', |
25 | | - 'optin-survey-intro' => "Thank you for trying the Usability Initiative's usability enhancements. You can opt out by clicking the button at the bottom of this page.\n\nWe'd like to know what you think about our new interface, so we'd appreciate it if you filled out the optional survey below before clicking the Opt out button.", |
| 27 | + 'optin-survey-intro' => "Thank you for trying the Usability Initiative's usability enhancements. |
| 28 | +You can opt out by clicking the button at the bottom of this page.\n\nWe'd like to know what you think about our new interface, so we'd appreciate it if you filled out the optional survey below before clicking the Opt out button.", |
26 | 29 | 'optin-survey-question-whyoptout' => 'Why are you opting out of this interface?', |
27 | 30 | 'optin-survey-answer-whyoptout-didntlike' => 'I do not like the design.', |
28 | 31 | 'optin-survey-answer-whyoptout-hard' => 'It was too hard to edit an article or a discussion page.', |
Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.i18n.php |
— | — | @@ -15,7 +15,8 @@ |
16 | 16 | 'prefstats' => 'Preference statistics', |
17 | 17 | 'prefstats-desc' => 'Track statistics about how many users have certain preferences enabled', |
18 | 18 | 'prefstats-title' => 'Preference statistics', |
19 | | - 'prefstats-list-intro' => 'Currently, the following preferences are being tracked. Click on one to view statistics about it.', |
| 19 | + 'prefstats-list-intro' => 'Currently, the following preferences are being tracked. |
| 20 | +Click on one to view statistics about it.', |
20 | 21 | 'prefstats-list-elem' => '$1 = $2', |
21 | 22 | ); |
22 | 23 | |
Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.php |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | $wgPrefStatsChartDimensions = '1000x300'; |
31 | 31 | |
32 | 32 | // Time unit to use for the graph on Special:PrefStats |
33 | | -$wgPrefStatsTimeUnit = 60*60*24; // one day |
| 33 | +$wgPrefStatsTimeUnit = 60 * 60 * 24; // one day |
34 | 34 | |
35 | 35 | /* Setup */ |
36 | 36 | |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | $wgAutoloadClasses['PrefStatsHooks'] = |
49 | 49 | dirname( __FILE__ ) . '/PrefStats.hooks.php'; |
50 | 50 | $wgAutoloadClasses['SpecialPrefStats'] = |
51 | | - dirname( __FILE__ ). '/SpecialPrefStats.php'; |
| 51 | + dirname( __FILE__ ) . '/SpecialPrefStats.php'; |
52 | 52 | |
53 | 53 | $wgSpecialPages['PrefStats'] = 'SpecialPrefStats'; |
54 | 54 | |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | $wgExtensionMessagesFiles['PrefStats'] = |
57 | 57 | dirname( __FILE__ ) . '/PrefStats.i18n.php'; |
58 | 58 | $wgExtensionAliasesFiles['PrefStats'] = |
59 | | - dirname( __FILE__ ). '/PrefStats.alias.php'; |
| 59 | + dirname( __FILE__ ) . '/PrefStats.alias.php'; |
60 | 60 | |
61 | 61 | // Registers Hooks |
62 | 62 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'PrefStatsHooks::schema'; |
Index: trunk/extensions/UsabilityInitiative/PrefStats/SpecialPrefStats.php |
— | — | @@ -11,27 +11,27 @@ |
12 | 12 | parent::__construct( 'PrefStats', 'prefstats' ); |
13 | 13 | wfLoadExtensionMessages( 'PrefStats' ); |
14 | 14 | } |
15 | | - |
| 15 | + |
16 | 16 | function execute( $par ) { |
17 | 17 | global $wgRequest, $wgOut, $wgUser, $wgPrefStatsTrackPrefs; |
18 | 18 | $this->setHeaders(); |
19 | | - |
| 19 | + |
20 | 20 | // Check permissions |
21 | 21 | if ( !$this->userCanExecute( $wgUser ) ) { |
22 | 22 | $this->displayRestrictionError(); |
23 | 23 | return; |
24 | 24 | } |
25 | | - |
| 25 | + |
26 | 26 | $wgOut->setPageTitle( wfMsg( 'prefstats-title' ) ); |
27 | | - |
28 | | - if( !isset( $wgPrefStatsTrackPrefs[$par] ) ) { |
| 27 | + |
| 28 | + if ( !isset( $wgPrefStatsTrackPrefs[$par] ) ) { |
29 | 29 | $this->displayTrackedPrefs(); |
30 | 30 | return; |
31 | 31 | } |
32 | | - |
| 32 | + |
33 | 33 | $this->displayPrefStats( $par ); |
34 | 34 | } |
35 | | - |
| 35 | + |
36 | 36 | function displayTrackedPrefs() { |
37 | 37 | global $wgOut, $wgUser, $wgPrefStatsTrackPrefs; |
38 | 38 | $wgOut->addWikiMsg( 'prefstats-list-intro' ); |
— | — | @@ -45,7 +45,7 @@ |
46 | 46 | } |
47 | 47 | $wgOut->addHTML( Xml::closeElement( 'ul' ) ); |
48 | 48 | } |
49 | | - |
| 49 | + |
50 | 50 | function displayPrefStats( $pref ) { |
51 | 51 | global $wgOut, $wgRequest, $wgPrefStatsTrackPrefs; |
52 | 52 | $max = $this->getMaxDuration( $pref ); |
— | — | @@ -54,10 +54,10 @@ |
55 | 55 | $wgOut->addHTML( Xml::element( 'img', array( 'src' => |
56 | 56 | $this->getGoogleChartParams( $stats ) ) ) ); |
57 | 57 | } |
58 | | - |
| 58 | + |
59 | 59 | function getGoogleChartParams( $stats ) { |
60 | 60 | global $wgPrefStatsChartDimensions; |
61 | | - return "http://chart.apis.google.com/chart?" . wfArrayToCGI( |
| 61 | + return "http://chart.apis.google.com/chart?" . wfArrayToCGI( |
62 | 62 | array( |
63 | 63 | 'chs' => $wgPrefStatsChartDimensions, |
64 | 64 | 'cht' => 'bvs', |
— | — | @@ -65,18 +65,18 @@ |
66 | 66 | 'chd' => 't:' . implode( ',', $stats ), |
67 | 67 | 'chxt' => 'x,y', |
68 | 68 | 'chxr' => '1,' . min( $stats ) . ',' . max( $stats ), |
69 | | - 'chxl' => '0:|'. implode( '|', array_keys( $stats ) ), |
70 | | - 'chm' => 'N*f0zy*,000000,0,-1,11' |
| 69 | + 'chxl' => '0:|' . implode( '|', array_keys( $stats ) ), |
| 70 | + 'chm' => 'N*f0zy*,000000,0,-1,11' |
71 | 71 | ) ); |
72 | 72 | } |
73 | | - |
| 73 | + |
74 | 74 | function getPrefStats( $pref, $inc = null ) { |
75 | 75 | global $wgPrefStatsTimeUnit; |
76 | 76 | $max = ceil( $this->getMaxDuration( $pref ) / |
77 | 77 | $wgPrefStatsTimeUnit ); |
78 | 78 | $inc = max( 1, ( is_null( $inc ) ? ceil( $max / 10 ) : $inc ) ); |
79 | 79 | $retval = array(); |
80 | | - for( $i = 0; $i <= $max; $i += $inc ) { |
| 80 | + for ( $i = 0; $i <= $max; $i += $inc ) { |
81 | 81 | $end = min( $max, $i + $inc ); |
82 | 82 | $key = $i . '-' . $end; |
83 | 83 | $retval[$key] = $this->countBetween( $pref, |
— | — | @@ -85,7 +85,7 @@ |
86 | 86 | } |
87 | 87 | return $retval; |
88 | 88 | } |
89 | | - |
| 89 | + |
90 | 90 | /** |
91 | 91 | * Get the highest duration in the database |
92 | 92 | */ |
— | — | @@ -99,7 +99,7 @@ |
100 | 100 | $max2 = wfTimestamp( TS_UNIX ) - wfTimestamp( TS_UNIX, $minTS ); |
101 | 101 | return max( $max1, $max2 ); |
102 | 102 | } |
103 | | - |
| 103 | + |
104 | 104 | /** |
105 | 105 | * Count the number of users having $pref enabled between |
106 | 106 | * $min and $max seconds |
Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.hooks.php |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | 'ps_pref' => $pref, |
31 | 31 | 'ps_end IS NULL' |
32 | 32 | ), __METHOD__ ); |
33 | | - if ( isset( $options[$pref] ) && $options[$pref] == $value && !$start) |
| 33 | + if ( isset( $options[$pref] ) && $options[$pref] == $value && !$start ) |
34 | 34 | $dbw->insert( 'prefstats', array( |
35 | 35 | 'ps_user' => $user->getId(), |
36 | 36 | 'ps_pref' => $pref, |
— | — | @@ -55,5 +55,4 @@ |
56 | 56 | } |
57 | 57 | return true; |
58 | 58 | } |
59 | | - |
60 | 59 | } |
Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.alias.php |
— | — | @@ -5,9 +5,9 @@ |
6 | 6 | * @file |
7 | 7 | * @ingroup Extensions |
8 | 8 | */ |
9 | | - |
| 9 | + |
10 | 10 | $aliases = array(); |
11 | | - |
| 11 | + |
12 | 12 | $aliases['en'] = array( |
13 | 13 | 'PrefStats' => array( 'PrefStats' ), |
14 | 14 | ); |
Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.sql |
— | — | @@ -5,19 +5,19 @@ |
6 | 6 | CREATE TABLE IF NOT EXISTS /*_*/prefstats ( |
7 | 7 | -- User ID |
8 | 8 | ps_user int NOT NULL, |
9 | | - |
| 9 | + |
10 | 10 | -- Preference name |
11 | 11 | ps_pref varbinary(32) NOT NULL, |
12 | | - |
| 12 | + |
13 | 13 | -- Preference value |
14 | 14 | ps_value blob NOT NULL, |
15 | | - |
| 15 | + |
16 | 16 | -- Timestamp the user enabled the preference |
17 | 17 | ps_start binary(14) NOT NULL, |
18 | | - |
| 18 | + |
19 | 19 | -- Timestamp the user disabled the preference, or NULL if still enabled |
20 | 20 | ps_end binary(14) NULL, |
21 | | - |
| 21 | + |
22 | 22 | -- Number of seconds the user had the preference enabled, |
23 | 23 | -- or 0 if still enabled |
24 | 24 | ps_duration int unsigned |
Index: trunk/extensions/UsabilityInitiative/NavigableTOC/NavigableTOC.i18n.php |
— | — | @@ -14,4 +14,4 @@ |
15 | 15 | $messages['en'] = array( |
16 | 16 | 'navigabletoc' => 'Navigable table of contents', |
17 | 17 | 'navigabletoc-desc' => 'Adds a table of contents to the edit form that scrolls the text box when a section is clicked.', |
18 | | -); |
\ No newline at end of file |
| 18 | +); |
Index: trunk/extensions/UsabilityInitiative/NavigableTOC/NavigableTOC.hooks.php |
— | — | @@ -9,12 +9,12 @@ |
10 | 10 | class NavigableTOCHooks { |
11 | 11 | |
12 | 12 | /* Static Functions */ |
13 | | - |
| 13 | + |
14 | 14 | /** |
15 | 15 | * EditPage::showEditForm::initial hook |
16 | 16 | * Adds the TOC to the edit form |
17 | 17 | */ |
18 | | - public static function addTOC(&$ep) { |
| 18 | + public static function addTOC( &$ep ) { |
19 | 19 | global $wgNavigableTOCStyleVersion, $wgParser, $wgUser; |
20 | 20 | global $wgUseParserCache; |
21 | 21 | |
— | — | @@ -22,34 +22,34 @@ |
23 | 23 | UsabilityInitiativeHooks::addScript( |
24 | 24 | 'NavigableTOC/NavigableTOC.js', $wgNavigableTOCStyleVersion |
25 | 25 | ); |
26 | | - |
| 26 | + |
27 | 27 | // Try the parser cache first |
28 | 28 | $pcache = ParserCache::singleton(); |
29 | 29 | $articleObj = new Article( $ep->mTitle ); |
30 | 30 | $p_result = $pcache->get( $articleObj, $wgUser ); |
31 | 31 | if ( !$p_result ) |
32 | 32 | { |
33 | | - $p_result = $wgParser->parse( $articleObj->getContent(), $ep->mTitle, new ParserOptions()); |
34 | | - if( $wgUseParserCache ) |
| 33 | + $p_result = $wgParser->parse( $articleObj->getContent(), $ep->mTitle, new ParserOptions() ); |
| 34 | + if ( $wgUseParserCache ) |
35 | 35 | $pcache->save( $p_result, $articleObj, $popts ); |
36 | 36 | } else { |
37 | 37 | // The ParserOutput in cache could be too old to have |
38 | 38 | // byte offsets. In that case, reparse |
39 | 39 | $sections = $p_result->getSections(); |
40 | 40 | if ( isset( $sections[0] ) && !isset( $sections[0]['byteoffset'] ) ) { |
41 | | - $p_result = $wgParser->parse( $articleObj->getContent(), $ep->mTitle, new ParserOptions()); |
42 | | - if( $wgUseParserCache ) |
| 41 | + $p_result = $wgParser->parse( $articleObj->getContent(), $ep->mTitle, new ParserOptions() ); |
| 42 | + if ( $wgUseParserCache ) |
43 | 43 | $pcache->save( $p_result, $articleObj, $popts ); |
44 | 44 | } |
45 | 45 | } |
46 | | - |
| 46 | + |
47 | 47 | $js = "\$.sectionOffsets = ["; |
48 | 48 | foreach ( $p_result->getSections() as $section ) |
49 | 49 | if ( !is_null( $section['byteoffset'] ) ) |
50 | 50 | $js .= intval( $section['byteoffset'] ) . ','; |
51 | 51 | $js .= '];'; |
52 | 52 | $jsTag = Xml::element( 'script', array(), $js ); |
53 | | - |
| 53 | + |
54 | 54 | $ep->editFormTextTop .= $p_result->getTOCHTML() . $jsTag; |
55 | 55 | return true; |
56 | 56 | } |
Index: trunk/extensions/UsabilityInitiative/NavigableTOC/NavigableTOC.js |
— | — | @@ -18,7 +18,7 @@ |
19 | 19 | var width = control.scrollWidth; |
20 | 20 | return Math.floor(width/8); |
21 | 21 | } |
22 | | - |
| 22 | + |
23 | 23 | function getCaret(control) { |
24 | 24 | var caretPos = 0; |
25 | 25 | // IE Support |
— | — | @@ -38,16 +38,16 @@ |
39 | 39 | } |
40 | 40 | return caretPos; |
41 | 41 | } |
42 | | - |
| 42 | + |
43 | 43 | function getCaretPosition(control) { |
44 | 44 | var text = control.value.replace(/\r/g, ""); |
45 | 45 | var caret = getCaret(control); |
46 | 46 | var lineLength = getLineLength(control); |
47 | | - |
| 47 | + |
48 | 48 | var row = 0; |
49 | 49 | var charInLine = 0; |
50 | 50 | var lastSpaceInLine = 0; |
51 | | - |
| 51 | + |
52 | 52 | for(i = 0; i < caret; i++) { |
53 | 53 | charInLine++; |
54 | 54 | if(text.charAt(i) == " ") { |
— | — | @@ -60,13 +60,13 @@ |
61 | 61 | if(charInLine > lineLength) { |
62 | 62 | if(lastSpaceInLine > 0) { |
63 | 63 | charInLine = charInLine - lastSpaceInLine; |
64 | | - |
| 64 | + |
65 | 65 | lastSpaceInLine = 0; |
66 | 66 | row++; |
67 | 67 | } |
68 | 68 | } |
69 | 69 | } |
70 | | - |
| 70 | + |
71 | 71 | var nextSpace = 0; |
72 | 72 | for(j = caret; j < caret + lineLength; j++) { |
73 | 73 | if(text.charAt(j) == " " || text.charAt(j) == "\n" || caret == text.length) { |
— | — | @@ -74,16 +74,16 @@ |
75 | 75 | break; |
76 | 76 | } |
77 | 77 | } |
78 | | - |
| 78 | + |
79 | 79 | if(nextSpace > lineLength && caret <= lineLength) { |
80 | 80 | charInLine = caret - lastSpaceInLine; |
81 | 81 | row++; |
82 | 82 | } |
83 | | - |
84 | | - |
| 83 | + |
| 84 | + |
85 | 85 | return ($.os.name == 'mac' ? 13 : 16)*row; |
86 | 86 | } |
87 | | - |
| 87 | + |
88 | 88 | // Put the cursor at the desired position |
89 | 89 | this.focus(); |
90 | 90 | if ( this.selectionStart || this.selectionStart == '0' ) { // Mozilla |
— | — | @@ -111,6 +111,5 @@ |
112 | 112 | $( '#wpTextbox1' ).scrollToPosition( $(this).data( 'offset' ) ); |
113 | 113 | e.preventDefault(); |
114 | 114 | }); |
115 | | - |
116 | | -}); |
117 | 115 | |
| 116 | +}); |