var kla_locale = jQuery.parseJSON('{"chi":{"1":"\u4e2d\u570b\u8a9e\u6587\u6559\u80b2","2":"English Language Education","3":"\u6578\u5b78\u6559\u80b2","4":"\u79d1\u5b78\u6559\u80b2","5":"\u79d1\u6280\u6559\u80b2","6":"\u500b\u4eba\u3001\u793e\u6703\u53ca\u4eba\u6587\u6559\u80b2","7":"\u9ad4\u80b2","8":"\u85dd\u8853\u6559\u80b2","9":"\u5c0f\u5b78\u5e38\u8b58\u79d1","10":"\u9ad8\u4e2d\u901a\u8b58\u6559\u80b2\u79d1","11":"\u7279\u6b8a\u6559\u80b2\u9700\u8981","12":"\u8de8\u5b78\u79d1\/\u5176\u4ed6","13":"\u516c\u6c11\u8207\u793e\u6703\u767c\u5c55\u79d1"},"eng":{"1":"\u4e2d\u570b\u8a9e\u6587\u6559\u80b2","2":"English Language Education","3":"Mathematics Education","4":"Science Education","5":"Technology Education","6":"Personal, Social and Humanities Education","7":"Physical Education","8":"Arts Education","9":"General Studies for Primary Schools","10":"Liberal Studies","11":"Special Education Needs","12":"Cross KLA \/ Others","13":"Citizenship and Social Development"}}');
var project_locale = jQuery.parseJSON('{"chi":{"0":"\u5168\u90e8\u8cc7\u6e90","3":"\u6559\u80b2\u5c40\u8cc7\u6e90","1":"\u6559\u57ce\u8cc7\u6e90","2":"\u793e\u7fa4\u8cc7\u6e90"},"eng":{"0":"All Resources","3":"EDBOSP","1":"EdCity Resources","2":"Community"}}');
rd2015.locale_str = {
chi: {
input_notice: "請輸入關鍵字,或選取學習領域。"
},
eng: {
input_notice: "Please enter keyword, or select key learning area."
}
}
var kla_mapping = {};
for (var lang in kla_locale) {
for (var i in kla_locale[lang]) {
var _key = kla_locale[lang][i];
kla_mapping[_key] = i;
}
}
var project_mapping = {};
for (var lang in project_locale) {
for (var i in project_locale[lang]) {
var _key = project_locale[lang][i];
project_mapping[_key] = i;
}
}
function breadcrumbKlaAction() {
var selected = jQuery.trim(jQuery(this).text());
var kla = [];;
if (typeof kla_mapping[selected] != 'undefined') {
kla.push(kla_mapping[selected]);
} else {
kla.push("0");
}
pageRedirect("", {kla_id: kla});
}
function searchAction() {
var kla = [];
var checked_dom = jQuery("li.subject-listing-item ul.inline-list input:checked");
jQuery.each(checked_dom, function(index1, value1) {
var _html = jQuery("
" + jQuery(value1).parent().html() + "
");
_html.find("input").remove();
_html.find("span").remove();
var selected = jQuery.trim(_html.text());
if (typeof kla_mapping[selected] != 'undefined') {
kla.push(kla_mapping[selected]);
} else {
kla.push("0");
}
});
var resourceType = [];
var checked_dom = jQuery("li.resource-type-listing-item ul.inline-list input:checked");
jQuery.each(checked_dom, function(index1, value1) {
var _html = jQuery("" + jQuery(value1).parent().html() + "
");
_html.find("input").remove();
_html.find("span").remove();
var selected = jQuery.trim(_html.text());
if (typeof project_mapping[selected] != 'undefined') {
resourceType.push(project_mapping[selected]);
}
});
var search_key = jQuery("#cs-input").val();
if ((search_key == "") && (kla.length == 0)) {
// not display error message and do nothing
//if (jQuery("#cs-warming").length <= 0) {
//jQuery("li.search-box").append('' + rd2015.locale_str[rd2015.lang_str].input_notice + '
');
//setTimeout(function(){ jQuery("#cs-warming").remove(); }, 5000);
//}
} else {
var extra_param = {};
if (kla.length > 0) {
extra_param['kla_id'] = kla;
}
if (resourceType.length > 0) {
extra_param['project_id'] = resourceType;
}
if (Object.keys(extra_param).length > 0) {
pageRedirect(search_key, extra_param);
} else {
pageRedirect(search_key);
}
}
}
function pageRedirect(search_key, search_type) {
var req = "";
if ((typeof search_key != 'undefined') && (search_key != "")) {
req = "search_key=" + encodeURIComponent(search_key);
}
if (typeof search_type != 'undefined') {
var _temp = "search_type=" + encodeURIComponent(JSON.stringify(search_type));
if (req.length > 0) {
req = req + "&" + _temp;
} else {
req = _temp;
}
}
window.location.href = rd2015.search_url + "?" + req;
}
function klaAClickAction() {
if (jQuery(this).parent().find("input").is(":checked")) {
var _checkbox = jQuery(this).parent().find("input");
if (typeof _checkbox.prop == 'function') {
_checkbox.prop("checked", false);
} else {
_checkbox.attr("checked", false);
}
jQuery(this).removeClass("selected");
} else {
var _checkbox = jQuery(this).parent().find("input");
if (typeof _checkbox.prop == 'function') {
_checkbox.prop("checked", true);
} else {
_checkbox.attr("checked", true);
}
jQuery(this).addClass("selected");
}
}
function resourceTypeAClickAction() {
if (jQuery(this).parent().find("input").is(":checked")) {
var _checkbox = jQuery(this).parent().find("input");
if (typeof _checkbox.prop == 'function') {
_checkbox.prop("checked", false);
} else {
_checkbox.attr("checked", false);
}
jQuery(this).removeClass("selected");
var resource_type_choice = jQuery(this).parent().find("a").text()
if (typeof project_mapping[resource_type_choice] != 'undefined') {
if (project_mapping[resource_type_choice] == 0) {
jQuery("#promotion-area li.resource-type-listing-item input").each(function(index) {
jQuery(this).prop('checked', false);
})
}
}
} else {
var _checkbox = jQuery(this).parent().find("input");
if (typeof _checkbox.prop == 'function') {
_checkbox.prop("checked", true);
} else {
_checkbox.attr("checked", true);
}
jQuery(this).addClass("selected");
var resource_type_choice = jQuery(this).parent().find("a").text()
if (typeof project_mapping[resource_type_choice] != 'undefined') {
if (project_mapping[resource_type_choice] == 0) {
jQuery("#promotion-area li.resource-type-listing-item input").each(function(index) {
jQuery(this).prop('checked', true);
})
}
}
}
}
function klaInputClickAction() {
if (jQuery(this).is(":checked")) {
jQuery(this).parent().find("a").addClass("selected");
} else {
jQuery(this).parent().find("a").removeClass("selected");
}
}
function resourceTypeInputClickAction() {
if (jQuery(this).is(":checked")) {
jQuery(this).parent().find("a").addClass("selected");
var resource_type_choice = jQuery(this).parent().find("a").text()
if (typeof project_mapping[resource_type_choice] != 'undefined') {
if (project_mapping[resource_type_choice] == 0) {
jQuery("#promotion-area li.resource-type-listing-item input").each(function(index) {
jQuery(this).prop('checked', true);
})
}
}
} else {
jQuery(this).parent().find("a").removeClass("selected");
var resource_type_choice = jQuery(this).parent().find("a").text()
if (typeof project_mapping[resource_type_choice] != 'undefined') {
if (project_mapping[resource_type_choice] == 0) {
jQuery("#promotion-area li.resource-type-listing-item input").each(function(index) {
jQuery(this).prop('checked', false);
})
}
}
}
}
jQuery(document).ready(function() {
var inputBox = jQuery("#cs-input");
if (inputBox.length > 0) {
inputBox.keyup(function(event) {
if (event.keyCode == 13) {
event.preventDefault();
searchAction();
}
});
}
// placeholder for IE8, IE9
if (jQuery("input#cs-input").length > 0) {
jQuery("input#cs-input").placeholder();
}
jQuery("#promotion-area li.subject-listing-item a").click(klaAClickAction);
jQuery("#promotion-area li.subject-listing-item input").click(klaInputClickAction);
// for press back button on browser
setTimeout(function() {
jQuery("#promotion-area li.subject-listing-item input").each(function(index) {
if (jQuery(this).is(":checked")) {
jQuery(this).parent().find("a").addClass("selected");
}
});
}, 1000);
jQuery("#promotion-area li.resource-type-listing-item a").click(resourceTypeAClickAction);
jQuery("#promotion-area li.resource-type-listing-item input").click(resourceTypeInputClickAction);
// for press back button on browser
setTimeout(function() {
jQuery("#promotion-area li.resource-type-listing-listing-item input").each(function(index) {
if (jQuery(this).is(":checked")) {
jQuery(this).parent().find("a").addClass("selected");
}
});
}, 1000);
});