Skip to content

Commit 01d10aa

Browse files
committed
fix pjax issue
1 parent de142f1 commit 01d10aa

File tree

2 files changed

+30
-34
lines changed

2 files changed

+30
-34
lines changed

translator/public/js/translator.js

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,32 @@ $(document).ready(function() {
88
});
99
});
1010

11-
function getNextRow($row) {
11+
function get_next_row($row) {
1212
$row = $row.next()
1313
if ($row.find("button.btn-verify[data-verified=0]").size() > 0) {
1414
console.log($row.find("button.btn-verify[data-verified=0]").size())
1515
return $row
1616
}
17-
return getNextRow($row)
17+
return get_next_row($row)
1818
}
1919

20-
function getNextTranslation($currentElement) {
21-
$row = getNextRow($currentElement.closest('.row'))
20+
function get_next_translation($currentElement) {
21+
$row = get_next_row($currentElement.closest('.row'))
2222
return $row.find('.translated')
2323
}
2424

25-
function getParameterByName(name) {
25+
function get_parameter_by_name(name) {
2626
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
2727
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
2828
results = regex.exec(location.search);
2929
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
3030
}
3131

32-
frappe.ready(function() {
33-
if(location.pathname=="/translator/view") {
34-
$(".page-header h2").html("Translate " + window.language_name);
35-
document.title = "Translate " + window.language_name;
36-
$("[data-char='"+(get_url_arg("c") || "*")+"']").addClass("active");
37-
}
38-
39-
$(".message-ts").each(function() {
40-
var ts = $(this).attr("data-timestamp");
41-
$(this).html("Last Updated: "
42-
+ (comment_when(ts) || ts));
43-
});
44-
45-
$("input#search-box").keyup(function(event){
46-
if(event.keyCode == 13){
47-
search_param = $(this).val()
48-
lang = getParameterByName('lang')
49-
if (search_param && lang) {
50-
window.location = "/translator/view?lang="+lang+"&search="+search_param
51-
}
52-
}
53-
});
54-
55-
});
56-
57-
5832
var translator = {
5933
next: function($next) {
6034
var $txt = $(".edit-value")
6135
if (!$next) {
62-
$next = getNextTranslation($txt)
36+
$next = get_next_translation($txt)
6337
}
6438
$next.trigger('click')
6539
},
@@ -94,7 +68,7 @@ var translator = {
9468
},
9569
callback: function(data) {
9670
if(!data.exc) {
97-
$next = getNextTranslation($txt)
71+
$next = get_next_translation($txt)
9872
$txt.parent().removeClass("active").html(val);
9973
translator.next($next)
10074
}
@@ -128,7 +102,7 @@ var translator = {
128102
$cancel = $('<button class="btn btn-default btn-small">Next</button>')
129103
.appendTo($p)
130104
.on("click", function(e) {
131-
$next = getNextTranslation($txt)
105+
$next = get_next_translation($txt)
132106
translator.next()
133107
translator.next($next)
134108
});

translator/www/translator/view.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@
77
window.language_name = "{{ lang.language_name }}";
88
window.user_karma = {{ karma }};
99
window.lang = "{{ frappe.form_dict.lang }}";
10+
11+
frappe.ready(function() {
12+
$(".page-header h2").html("Translate " + window.language_name);
13+
document.title = "Translate " + window.language_name;
14+
$("[data-char='"+(get_url_arg("c") || "*")+"']").addClass("active");
15+
16+
$(".message-ts").each(function() {
17+
var ts = $(this).attr("data-timestamp");
18+
$(this).html("Last Updated: "
19+
+ (comment_when(ts) || ts));
20+
});
21+
22+
$("input#search-box").keyup(function(event){
23+
if(event.keyCode == 13){
24+
search_param = $(this).val()
25+
lang = get_parameter_by_name('lang')
26+
if (search_param && lang) {
27+
window.location = "/translator/view?lang="+lang+"&search="+search_param
28+
}
29+
}
30+
});
31+
})
1032
</script>
1133

1234
<div class="reset">

0 commit comments

Comments
 (0)