Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
node-slate
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nguyễn Hải Sơn
node-slate
Commits
68807cd4
Commit
68807cd4
authored
Apr 09, 2014
by
Christopher Rogers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes some leakage in the language selector
Signed-off-by:
Christopher Rogers
<
chrissrogers@gmail.com
>
parent
53db9d4a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
34 deletions
+40
-34
lang_selector.js
source/javascripts/lang_selector.js
+40
-34
No files found.
source/javascripts/lang_selector.js
View file @
68807cd4
...
...
@@ -13,40 +13,46 @@ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
*/
languages
=
[]
function
activateLanguage
(
language
)
{
$
(
"#lang-selector a"
).
removeClass
(
'active'
);
$
(
"#lang-selector a[data-language-name='"
+
language
+
"']"
).
addClass
(
'active'
);
for
(
var
i
=
0
;
i
<
languages
.
length
;
i
++
)
{
$
(
".highlight."
+
languages
[
i
]).
hide
();
}
$
(
".highlight."
+
language
).
show
();
}
function
setupLanguages
(
l
)
{
languages
=
l
;
currentLanguage
=
languages
[
0
];
defaultLanguage
=
localStorage
.
getItem
(
"language"
);
if
((
location
.
search
.
substr
(
1
)
!=
""
)
&&
(
jQuery
.
inArray
(
location
.
search
.
substr
(
1
),
languages
))
!=
-
1
)
{
// the language is in the URL, so use that language!
activateLanguage
(
location
.
search
.
substr
(
1
));
// set this language as the default for next time, if the URL has no language
localStorage
.
setItem
(
"language"
,
location
.
search
.
substr
(
1
));
}
else
if
((
defaultLanguage
!==
null
)
&&
(
jQuery
.
inArray
(
defaultLanguage
,
languages
)
!=
-
1
))
{
// the language was the last selected one saved in localstorage, so use that language!
activateLanguage
(
defaultLanguage
);
}
else
{
// no language selected, so use the default
activateLanguage
(
languages
[
0
]);
(
function
(
global
)
{
var
languages
=
[];
global
.
setupLanguages
=
setupLanguages
;
global
.
activateLanguage
=
activateLanguage
;
function
activateLanguage
(
language
)
{
$
(
"#lang-selector a"
).
removeClass
(
'active'
);
$
(
"#lang-selector a[data-language-name='"
+
language
+
"']"
).
addClass
(
'active'
);
for
(
var
i
=
0
;
i
<
languages
.
length
;
i
++
)
{
$
(
".highlight."
+
languages
[
i
]).
hide
();
}
$
(
".highlight."
+
language
).
show
();
}
// if we click on a language tab, reload the page with that language in the URL
$
(
"#lang-selector a"
).
bind
(
"click"
,
function
()
{
window
.
location
.
replace
(
"?"
+
$
(
this
).
data
(
"language-name"
)
+
window
.
location
.
hash
);
return
false
;
});
function
setupLanguages
(
l
)
{
var
currentLanguage
=
l
[
0
];
var
defaultLanguage
=
localStorage
.
getItem
(
"language"
);
languages
=
l
;
if
((
location
.
search
.
substr
(
1
)
!=
""
)
&&
(
jQuery
.
inArray
(
location
.
search
.
substr
(
1
),
languages
))
!=
-
1
)
{
// the language is in the URL, so use that language!
activateLanguage
(
location
.
search
.
substr
(
1
));
// set this language as the default for next time, if the URL has no language
localStorage
.
setItem
(
"language"
,
location
.
search
.
substr
(
1
));
}
else
if
((
defaultLanguage
!==
null
)
&&
(
jQuery
.
inArray
(
defaultLanguage
,
languages
)
!=
-
1
))
{
// the language was the last selected one saved in localstorage, so use that language!
activateLanguage
(
defaultLanguage
);
}
else
{
// no language selected, so use the default
activateLanguage
(
languages
[
0
]);
}
// if we click on a language tab, reload the page with that language in the URL
$
(
"#lang-selector a"
).
bind
(
"click"
,
function
()
{
window
.
location
.
replace
(
"?"
+
$
(
this
).
data
(
"language-name"
)
+
window
.
location
.
hash
);
return
false
;
});
}
}
})(
window
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment