var domain = "https://www.feedcowboy.com"; function getOrientation(file, callback) { var reader = new FileReader(); reader.onload = function(e) { var view = new DataView(e.target.result); if (view.getUint16(0, false) != 0xFFD8) return callback(-2); var length = view.byteLength, offset = 2; while (offset < length) { var marker = view.getUint16(offset, false); offset += 2; if (marker == 0xFFE1) { if (view.getUint32(offset += 2, false) != 0x45786966) return callback(-1); var little = view.getUint16(offset += 6, false) == 0x4949; offset += view.getUint32(offset + 4, little); var tags = view.getUint16(offset, little); offset += 2; for (var i = 0; i < tags; i++) if (view.getUint16(offset + (i * 12), little) == 0x0112) return callback(view.getUint16(offset + (i * 12) + 8, little)); } else if ((marker & 0xFF00) != 0xFF00) break; else offset += view.getUint16(offset, false); } return callback(-1); }; reader.readAsArrayBuffer(file.slice(0, 64 * 1024)); } String.prototype.between = function(prefix, suffix) { string = this; var i = string.indexOf(prefix); if (i >= 0) { string = string.substring(i + prefix.length); } else { return ""; } if (suffix) { i = string.indexOf(suffix); if (i >= 0) { string = string.substring(0, i); } else { return ""; } } return string; } function fcNotify(message) { $("#fcNotifier").fadeOut(250, function () { $("#fcNotifier").html("

"+message+"

").fadeIn(250).delay(1500).fadeOut(250); }); } function fcOpenArticle(id) { if ($("#article-"+id+" .article-content").html() == "") { $.ajax({ type:"POST", data: { fcSweetAction : "fcLoadArticleContent", fcArticleID : id }, url:"fc.output.php", success: function(data) { $("#article-"+id+" .article-content").html(data).show(); } }); $("#article-"+id+" .content-button a").html("Sulje edun tiedot »"); } else { $("#article-"+id+" .article-content").html("").hide(); $("#article-"+id+" .content-button a").html("Tutustu etuun »"); } } function fcToggleArticleType(id) { $("#fcArticleType").val(id); $(".fcArticleTypeSelector").removeClass("active").addClass("inactive"); $("#fcArticleTypeSelector_"+id).removeClass("inactive").addClass("active"); if (id == 2) { $(".themes-container").hide(); } else { $(".themes-container").show(); } } function fcSubmitLogin() { if ($("#fcLoginUsername").val() != "") { if ($("#fcLoginPassword").val() != "") { $("#fcLoginForm").submit(); } else {fcNotify("Salasana on tyhjä");} } else {fcNotify("Käyttäjätunnus on tyhjä");} } function fcResetElement(element) { element.parent().find(".dark-button").hide(); element.css("transform", "rotate(0deg)"); element.find("input[type=file]").val(""); element.css("background-image", "url('graphics/button-image.gif')"); element.find("input[type=file]").css({ "width": "100%", "height": "100%" }); } function fcDirectSubmitForm(id) { tinyMCE.triggerSave(); var mandatory_failure = false; $(".highlight").removeClass("highlight"); $(".mandatory").each(function () { if ($(this).val() == "") { $(this).addClass("highlight"); mandatory_failure = true; } }); if (!mandatory_failure) { $("#"+id).submit(); } else { fcNotify("Puuttuvia kenttiä lomakkeessa"); } } function fcGetResponseMessage(string) { return string.between("", ""); } function fcGetResponseStatus(string) { return string.between("", ""); } function fcSubmitForm(id) { var failedFields = 0; $("#fcForm_"+id+" textarea, #fcForm_"+id+" input:text, #fcForm_"+id+" select").each(function(){ if ($(this).hasClass("required") && $(this).val() == "") { failedFields += 1; $(this).addClass("highlight"); } }); if (failedFields < 1) { $("#fcForm_"+id).fadeOut(300, function () { var formData = new FormData($("#fcForm_"+id)[0]); $.ajax({ type : "POST", data : formData, processData: false, contentType: false, error : function (request, status, error) {$("#fcForm_"+id).fadeIn(300); alert("Virhe lomakkeen käsittelyssä");}, url: domain+"/_submitform.php", success: function(data) { if (fcGetResponseStatus(data) == 1) { alert(fcGetResponseMessage(data)); } else { $("#fcForm_"+id).fadeIn(300); alert(fcGetResponseMessage(data)); } } }); }); } else {alert("Puuttuvia kohtia lomakkeessa");} } $(document).ready(function() { tinymce.init({ selector: ".rich-textarea", relative_urls : false, remove_script_host : false, convert_urls : true, plugins: [ "advlist autolink lists link image charmap anchor", "searchreplace visualblocks code", "insertdatetime media table contextmenu paste" ], tools: "inserttable", paste_as_text: true, language: 'fi', menubar: "", style_formats: [ {title: 'Pääotsikko', format: 'h1'}, {title: 'Väliotsikko', format: 'h2'}, {title: 'Leipäteksti', format: 'p'} ], statusbar: false, height: 350, content_css : "css/tinymce.css", toolbar: "bold italic | alignleft aligncenter alignright alignjustify | bullist numlist | link image | code" }); $(".date-input").datepicker({ monthNames: ["Tammikuu", "Helmikuu", "Maaliskuu", "Huhtikuu", "Toukokuu", "Kesäkuu", "Heinäkuu", "Elokuu", "Syyskuu", "Lokakuu", "Marraskuu", "Joulukuu"], dayNamesMin: ["Su","Ma","Ti","Ke","To","Pe","La"], dateFormat: "d.m.yy", firstDay: 1, showOtherMonths: true }); $(".form-image input[type=file]").change(function() { var element = $(this).parent(); var file = this.files[0]; if (file.size < 5000000) { if (file.type == "image/jpeg") { getOrientation(file, function(orientation) { if (orientation == 3) {element.css("transform", "rotate(180deg)");} if (orientation == 6) {element.css("transform", "rotate(90deg)");} if (orientation == 8) {element.css("transform", "rotate(270deg)");} }); function eImageIsLoaded(e) { element.css("background-image", "url('"+e.target.result+"')"); element.find("input[type=file]").css({ "width": "0px", "height": "0px" }); $("#fcRemoveArticleImageButton").show(); } var reader = new FileReader(); reader.onload = eImageIsLoaded; reader.readAsDataURL(file); } else { fcResetElement(element); fcNotify("Tiedostotyyppi on virheellinen (ei JPEG)."); } } else { fcResetElement(element); fcNotify("Tiedostokoko ylittää sallitun rajan (5 megatavua)."); } }); $("#fcRemoveArticleImageButton").hide().on("click", function () { $("#fcArticleForm").append(""); fcResetElement($(".form-image")); }); $("#fcRemoveUserImageButton").hide().on("click", function () { $("#fcUserForm").append(""); fcResetElement($(".form-image")); }); });