Hello,
The goal is to create a similar to the flag dialog at stackoverflow that shows on clicking the 'flag' button located under a question,but since I'm new to web development I don't understand certain things.
This is what I have:
This is the markup for the button:
<a id="flag-post-2239985" title="flag this post for serious problems">flag</a>
-I don't understand how this executes an event, usually there is an onclick tag.How does it go to the script?
This is the external js containing functions for accepting answers,voting AND flagging posts: http://sstatic.net/so/js/question.js?v=6274
You can unminify it for better view at http://jsbeautifier.org/
Needed functions:
flag: function (F) { var D = F.attr("id").substring("flag-post-".length); var K = "form-flag-" + D; var N = $("#" + D + "-is-owned-by-current-user").length > 0; var L = [ [l.offensive, "Offensive, Abusive, or Hate Speech", !N], [l.spam, "Spam", !N], [l.informModerator, "Requires Moderator attention", true] ]; var I = '<div class="popup flag-menu"><h2>Please flag with care:</h2>'; I += '<div class="flag-reasons"><form id="' + K + '">'; for (var G = 0; G < L.length; G++) { if (L[G][2]) { var M = "flag-radio" + D + "-" + L[G][0]; I += '<input type="radio" id="' + M + '" name="flag-' + D + '" value="' + L[G][0] + '">'; I += '<label for="' + M + '">' + L[G][1] + "</label><br>" } } I += '<div class="flag-comment">Why are you flagging this post?<textarea name="flag-reason" cols="33" rows="4"></textarea>'; I += '<br><span class="text-counter"></span></div>'; I += "</form></div>"; I += '<input type="button" class="flag-cancel" value="Cancel"><input type="button" class="flag-submit" value="Flag Post">'; I += "</div>"; var H = $(I); var E = H.find("#" + K); var J = E.find("textarea"); E.find("input").click(function () { var O = E.find("div.flag-comment"); var P = vote.flagIsInform(E); O.toggle(P); if (P) { J.focus() } vote.flagAllowSubmit(H, J, P) }); J.charCounter({ min: 10, max: 150, setIsValid: function () { vote.flagAllowSubmit(H, J, vote.flagIsInform(E)) } }); H.find(".flag-submit").click(function () { if (vote.flagIsInform(E) && !vote.flagTextValid(J)) { return } vote.flagSubmit(F, D, E, J) }); H.find(".flag-cancel").click(function () { vote.flagClosePopup(F) }); F.parent().append(H); H.fadeIn("fast") }, flagIsInform: function (D) { var E = D.find("input:radio:checked"); if (E.length == 0) { return false } return E.val() == l.informModerator }, flagAllowSubmit: function (E, F, G) { var D = G ? vote.flagTextValid(F) : true; E.find(".flag-submit").toggle(D) }, flagTextValid: function (E) { var D = E.val().length; return (D >= 10 && D <= 150) }, flagClosePopup: function (D) { D.parent().find(".popup").fadeOut("fast", function () { $(this).remove() }) }, flagSubmit: function (G, E, D, H) { vote.flagClosePopup(G); var F = D.find("input:radio:checked").val(); var E = G.attr("id").substring("flag-post-".length); if (F == l.informModerator) { $.ajax({ type: "POST", url: "/messages/inform-moderator-about-post/" + E, dataType: "json", data: { fkey: fkey, msg: H.val() }, success: function (I) { showAjaxError(G.parent(), I.Message) }, error: function (I, K, J) { showAjaxError(G.parent(), (I.responseText && I.responseText.length < 100 ? I.responseText : "An error occurred during submission")) } }) } else { q(G, E, F, vote.flagSubmitCallback, { comment: H.val() }) } }, flagSubmitCallback: function (E, D, G) { if (G && G.Success) { if (G.Message) {} } else { var F = E.parent(); if (G && G.Message) { showAjaxError(F, G.Message) } else { showAjaxError(F, "A problem occurred during flagging") } } }
Problem: When I include the external functions in a new html file,add the tag for the button ,clicking the button does nothing
Questions:
- Where am I doing it wrong?
- What relationship has the button markup with the javascript(I don't understand how it triggers an event if there is no onclick tag)?
- How would you debug this at stackoverflow? I use Firebug,but I cannot set any breakpoints.Please reveal better debuggers and(eventually) editors for javascript.
Please describe in details if possible,I'm new to web development.
Thank you in advance!