[03:56:11] hi. [03:56:23] What would you recommend me to do with AJAX calls? Is there a way to stop branching out? Look for "Clean up article page" at https://test.wikipedia.org/wiki/User:Gryllida/common.js and the next 5 lines. (Nested AJAX .dones, which is ugly) [03:59:53] svetlana: $.ajax() returns jquery Deferred objects (which are used elsewhere in the script) [04:00:14] okay, that's one more term. how do I use them to do what I'm after? [04:00:14] see [04:00:26] svetlana: give me a sec, helping someone on another channel [04:00:39] have a look at the docs meanwhile and i'll try to devise an example in a few minutes [04:01:02] if you could describe how it's different from 'promise' term it'd be useful too. [04:01:48] ah it had some mention, different terms. [04:02:00] goal is to do 4 ajax calls in succession without nesting the code. [04:02:22] instead of chaining the .done() to the ajax call, you can do something like: [04:02:58] var editReq = $.ajax('...'); [04:03:10] editReq.done( function () { /* do stuff */ } ) [04:03:23] or for greater clarity, use named rather than anonymous functions [04:03:29] that's first call. where do i place the second one? [04:03:38] so function doSomethingWhenFinishedEditing() { .... } [04:03:39] and then: [04:03:46] editReq.done( doSomethingWhenFinishedEditing ); [04:04:45] ajax1.done(foo1); function foo1(){ajax2.done(foo2)}; function foo2(){ajax3.done(foo3)}; [04:04:49] it seems a bit unreadable [04:07:20] svetlana: better than inlining imho [04:07:39] svetlana: sorry, I'm debugging another issue. But this is an issue people run into often, and there are lots of guides that illustrate it well.. some links: [04:08:07] I try not to respond to a thoughtful question with a barrage of hyperlinks but I am not able to walk through it at the moment, sorry [04:09:42] pyramid of doom is a nice term for it :) [04:09:48] thanks for the links [05:27:59] ori, I appear to be using that, with pain catching the errors. When you're about and have bit more time to look at it, please look at the current revision and suggest, if you like; JS isn't a language I'm very proficient with. [09:11:40] ori: (I'm the one who asked about afch2 js. I'm still here.) [09:11:58] afch2 js? [09:12:10] ori: as svetlana [09:12:21] ah, right [09:12:25] ok, let me look again [09:13:03] ori: now I'm trying to make afch2.dom.create() more readable. Also I am not catching errors from the ajax properly (I started using .when .then, which is a bit more readable.) [09:13:21] ori: it's at github now also. https://github.com/Gryllida/Afch2/blob/master/script.js [09:14:13] .fail() lets you bind error handlers [09:14:41] * ori reads the code [09:15:10] ori: the request succeeds, but it spews something like {error => { name => invalid}}, like you can see I can somehow try to process it in the .then, but it's a bit weird (I don't get to stop the other ongoing calls while I do that) [09:15:30] I just want to not branch out, there is no need to do them in parallel :) [09:18:11] gry (or svetlana?): manipulating the DOM is very expensive (=slow) [09:18:29] so when you have a lot of HTML to insert, it's generally better to build it up as a string [09:18:33] and then insert it all at once [09:18:55] oh my. that would be rather unreadable (I couldn't find a way to have multiline strings in JS) [09:19:59] when you say that, I start thinking of 'var html = "yadda yadda"; html+="foobars at line 2"; html+= "baz at line 3";', is that what you mean? [09:20:23] that is one way of doing it, though i concede it is not especially pretty [09:20:38] what better way(s) is(are) there? [09:20:58] you can also have a detached DOM (so you create a DOM node and append elements to it, etc.). It's still cheaper than DOM manipulation because the browser doesn't have to shuffle everything around on the screen after each element [09:21:14] but usually the way to go for anything nontrivial is to adopt some javascript templating library [09:22:28] the family tree of modern javascript templating libraries begins with this little snippet by jon resig: http://ejohn.org/blog/javascript-micro-templating/ [09:22:45] which also doubles as one of the best overall explanations of how to do templating well [09:23:32] (just to go back for a moment and to clarify what I meant by a detached DOM: you just build up a tree of elements but you postpone actually adding it to the page until it's fully assembled) [09:24:38] ori: I didn't understand the detached DOM idea. where and how do I create a dom node? is that not what I'm doing? [09:25:01] ah. I read last line. I see. [09:25:28] I'll do it this way then but templating looks too complex at this size. [09:25:44] any advice about ajax things? the .when .then thing catches errors poorly. [09:26:11] what do you mean? [09:26:51] which calls specifically are you trying to improve? [09:27:06] .create doesn't have any, which is why i ask [09:27:09] https://github.com/Gryllida/Afch2/blob/master/script.js#L278 [09:27:26] s/populare/populate :) [09:28:52] ah, yes. yeah, the error-handling for multiple deferreds in a $.when sucks, that is true [09:29:41] I just want to avoid branch-outs, almost etmpted to use labels (ajax1.done(goto 2;); 2: ajax2.done(goto 3;); 3: ajax3.done (...)) [09:29:57] there is no real need to do the ajax things in parallel / async [09:30:33] let me clone the repo and spend 5-10 minutes hacking at the code [09:30:36] however if i do it with labels like that i fear it'll go to 2 before completing ajax1 [09:30:38] it's a lot to read at a glance [09:30:49] ok thanks :) [09:36:40] heh, neat. i don't often encounter Infinity in JS [09:41:16] gry: can i make some generic remarks about code organization? [09:41:29] more than welcome to [09:43:04] ok, so first point, your functions are very long. treat anything longer than 7 lines or so as probably worthy of refactoring into separate functions [09:43:46] second (related) point is that writing sophisticated javascript webapps is basically a battle to keep DOM manipulation and application logic as separate as possible [09:45:05] MV* frameworks are very useful but they can be very confusing at first. but jquery gives you several powerful tools, one of which is the ability to trigger arbitrary events on arbitrary objects and to bind handlers to those events [09:45:59] right [09:46:08] I tried to isolate dom events in afch2.dom.* [09:46:29] I'll think about isolating things into functions a bit more. [09:47:28] i'll try to whip up a simple example based on a snippet of code you have in that file [09:49:11] perfect [09:57:26] gry: another small code organization / performance tip -- [09:57:52] if you know you're going to be referencing some element multiple times in a function, it's both more performant and more readable to cache (save) it in a variable name [09:58:13] if you're saving the result of a jquery selector, the convention is to use variable names that start with '$' [09:58:16] so: [09:58:24] var $el = $( '#afch2TargetPageName' ); [09:58:39] then $el.attr('readonly', 'readonly'); [09:58:48] var name = $el.val(); [09:58:49] etc [09:59:03] 'el' is not very descriptive; it's even better to come up with nice functional names [09:59:05] point taken [09:59:24] the reason it's more performant is that you're not searching the DOM multiple times [09:59:28] yup [10:06:22] gry: not tested or anything, but here's an example: https://dpaste.de/KDMt [10:07:03] basically: var p = new Page('footitle'); p.check() [10:07:41] the check() gives you a deferred object that is resolved if the check succeeded and returned a positive result and rejected otherwise [10:08:21] notice how all of that is completely agnostic of the UI [10:09:14] it encapsulates application logic [10:09:30] but then you can take it and actually wire it up to the UI, which is what the latter half is doing [10:10:56] er, line 27 should be deleted, obviously [10:18:47] ori, 'new Page'? [10:19:09] Page is a constructor [10:22:09] ok thanks [10:26:13] gry: also forgot to recommend this: http://addyosmani.com/resources/essentialjsdesignpatterns/book/ [10:28:38] yup excellent read, you rock [10:29:48] you use $variableName, what does that do? define a jquery variable? [10:30:34] it's just a convention to help you and other readers of your code remember that the variable name contains the result of a jquery selection [10:32:27] now I should figure out where to start changing the things that I have. I think I'll try to incorporate your 'Page' thing and the check function, first [10:33:03] gry: what you had was pretty much complete, right? [10:34:03] it was except the errors handling in the .when thing, and except the extractComment bit was broken (the regex is not matching). the former is a large problem and the latter is just a matter of debugging, it's something I can manage [10:35:45] yeah, i'd do the latter problem first before refactoring, so that you have a checkpoint to return to [10:39:38] ori, I couldn't manage it too well. the more broad regexp appears to have fewer matches and I don't see why. It's already simple [10:40:49] L164 is the simple one, L178 is the more specific one, it works, the former has no matches [10:42:38] I think it's reasonable to accept that the declining works, and return to completing the approve functionality (which this broken thing is a part of) later - approving properly implies learning to catch the error messages, which I didn't do. [10:55:38] gry: sorry, got distracted by something else. i am past being able to absorb new code for the night, but happy to look at this again tomorrow or some other time [10:55:52] what timezone are you in? [10:56:01] utc+11 here, I'm about to sleep too [10:57:04] utc-8 [10:57:13] * gry scratches head [10:57:46] we're 19 hours apart, so it's 3AM there isn't it? [10:58:00] three minutes to [10:58:26] ok, see you later. I'll try to figure out how to catch you in the mornings or evenings, depending [10:58:46] sleep well :-) [10:59:55] thanks, you to [10:59:57] o [17:54:45] Hello. I currently have my web browser's start up page to display a random page from Wikipedia using the Special:Random URL, but I was wondering if there was some way of having a URL which chose a random page out of a given category, instead of the entire wiki. [17:59:12] Hi QuiteBoringName. [17:59:12] QuiteBoringName: https://en.wikipedia.org/wiki/Special:RandomInCategory/History_of_Scotland [17:59:28] Hi twkozlowski. [17:59:35] I forgot that was in core now. [17:59:41] I was going to suggest Erwin's tool. [17:59:52] That directs me to random categories, twkozlowski. [18:00:08] No. [18:00:12] QuiteBoringName: Did you click the link? [18:00:14] Yes, somebody just directed me to erwin's tool on a different channel. I'm going to try that out now. [18:00:24] twkozlowski's link sent me to https://en.wikipedia.org/wiki/Sigurd_Magnusson [18:00:28] Oh okay, that time it didnt. [18:00:34] https://en.wikipedia.org/wiki/Duke_of_Rothesay here [18:00:49] Subcategories might be considered a random item to be selected. [18:00:50] Dunnnnnnno. [18:00:53] Thing is, when you paste the link it does do that I think. [18:01:09] And when it's set as a startup page, it acts as though the URL has been pasted, I believe. [18:01:39] Oh nevermind, it was just coincidence. [18:01:40] Twice. [18:04:56] With that URL format, is it possible to have multiple categories or just the one [18:04:57] ? [18:05:17] Probably just one. [19:19:23] Hello? [19:19:29] Any life here? [19:20:16] I was over on wikipedia-en-help, and they suggested that I ask my question here. It was more technical than edit related. [19:21:43] go ahead [19:21:45] !ask [19:21:45] Please feel free to ask your question: if anybody who knows the answer is around, they will surely reply. Don't ask for help or for attention before actually asking your question, that's just a waste of time – both yours and everybody else's. :) [19:22:42] Yes, but I wasn't certain if I was in an empty room. The other place was so active, that I knew I'd get a response. [19:22:56] My issue is with editing. It seems I can't. [19:23:26] When I go to edit a page, make a few changes, then hit Save Page, I'm returned to the editor with no changes visible. [19:23:52] It first started when I tried adding a section to a talk page, but it seems that it happens all the time, even in the Sandbox. [19:24:55] When I tried adding a section, I hit the + at the top, was presented with Subject and Content boxes, then after filling in both, I hit Save Page. I was returned to the editor with the entire page available for edit, but none of my changes were there. [19:25:16] huh. [19:25:50] In the Sandbox, I can see that others have been able to make changes, but none of mine show up. [19:25:53] when you return to the editor, are your changes preserved? or do they disappear? [19:26:53] The changes aren't there. Almost as if I had just clicked Edit on the entire page. If I do a browser Back, I can get to where all my edits were entered (so I was able to save all my work into a text file for when it does start working). [19:27:12] what browser are you using and have you tried using another one? [19:28:11] I use Chrome, and last night I did a few edits that worked just fine. It just seems that this morn there are issues. [19:28:31] I could swap over to another browser just for a test... [19:29:03] please do [19:31:45] Wow. What a suggestion. IE seems to work just fine. I'm going to swap back to Chrome and see what happens. [19:32:05] IE >.> [19:32:27] This may be the only moment in recorded history that IE did something that Chrome couldn't [19:32:54] No difference on Chrome...I'm going to log out of WP and then come back in... [19:32:56] Newyorkadam: Chrome can't display ActiveX controls! :P [19:33:26] Westley: that looks like you somehow managed to bizarrely misconfigure your chrome (or it somehow misconfigured itself) [19:33:49] Westley: It brings you back to the edit screen right? Does it save what you edited and just not submit it, or does it just not save your changes at all? [19:33:59] Westley: let's try the obvious stuff, clear your cookies, etc. :) [19:34:48] In Chrome, I logged out of WP, then went to the Sandbox to edit. No change. No edits. [19:35:05] Westley: Try using private browsing [19:35:09] shift-command-n [19:35:23] You'll need to log in again [19:35:49] Newyorkadam: When I was doing real edits, my changes were not shown at all, but I was able to recover them by doing a Back in the browser. [19:36:07] Westley: Does it work if you aren't logged in (i.e. an IP user)? [19:36:54] I just tried that. I was warned that my IP would be visible, but still no edits took. I'm going to try the Private browsing thing... [19:38:15] In the private session, not logged in, same problem. I'm going to go back to IE, log out and try it... [19:39:34] IE works again. :-( My edits both show in history, one as me, one as an IP address. [19:42:02] Ah! New symptom: In the private session, I can't log in. I enter my username and password, check the 30-day box, then hit enter or click on the Log In button, and am returned to the login screen with no data in the boxes. Could be a cookie problem. [19:42:18] Try it again without checking the 30 day box [19:42:24] pease [19:42:29] MatmaRex ^ [19:42:31] *please [19:44:45] In the private session, not checking the box made no difference. I even tried an invalid password, just to see if I could get an error message: nothing. [19:45:12] Invalid name also makes no difference. [19:45:50] weird :/ [19:46:07] Thinking about it, my computer did do its weekly reboot last night. There might have been some upgrades that were installed. I wonder where I should go look for changes..... [19:46:12] you could try the nuclear option and reset all browser settings [19:46:12] https://support.google.com/chrome/answer/3296214 [19:46:24] or try disabling things that might have changed [19:46:30] extensions, etc. [19:47:17] The problem is that I don't know what all they decided to change. :-) It could have any of a bunch of 'security' changes that were done. [19:48:09] i suppose someone else would notice if it was broken for everyone [19:49:24] Thanks for the link. The list of changes to Chrome are rather extensive. I think I'll see if I can go the other direction: remove one item at a time until it works. [19:49:43] Westley: First try clearing cache and cookies [19:49:46] and history [19:49:57] MatmaRex: Good point. In fact that's what I thought I'd find when I came here. [19:53:24] Cache from the last day...no change [19:54:12] Cookies from the last day...no change. [19:54:31] have you installed any chrome extensions? [19:54:56] Download and browsing history from the last day...no change. [19:55:19] I haven't intentionally installed any extensions, certainly not since last night. [19:56:27] Westley: What operating system are you using? [19:57:06] Cookies, cache, and history for the last week...no change. [19:57:30] Windows 7. [20:00:14] The extensions tab show that I have none. [20:08:27] I may have to be AFK for a few. Any new ideas, just throw them out there, thanks! [20:39:31] what is the ♙ symbol for and how come it pops up a lot in VisualEditor? [20:40:37] It's a chess symbol. [20:40:43] A pawn, specifically. [20:40:53] It appears because it's a very stupid placeholder. [20:41:13] It indicates when something goes wrong with VisualEditor. [20:41:26] Rather than disallowing the edit, the VE team decided to litter articles with Unicode pawns. [20:41:30] Why, I do not know. [20:41:33] lol [20:41:52] it's used internally i think during copy-and-pasting [20:42:09] The "pile of poo" icon is also used, I believe. [20:42:16] idk I caused it to pop up once last month messing around on test wiki [20:42:17] actually, no, something else [20:42:19] Because pawns weren't offensive enough vandalism. [20:42:20] internally, anyway [20:42:24] if you see it, that's a bug [20:42:26] :) [20:43:46] Gloria: there's also an umbrella, a sun and a cloud, i think [20:44:04] Blergh. [20:44:59] it showed up here: https://www.mediawiki.org/w/index.php?oldid=803786 and I believe in my deleted contributions at testwiki [20:45:07] but I cant find out for sure [20:46:41] if it's used to indicate something wrong with VE [20:46:58] why not also include some sort of debug tool next to it [20:57:02] Withoutaname: what sort of a debug tool? [20:57:34] I was thinking about pointing out specifically what went wrong with VE in the code [20:57:52] or how we caused the character to show up [20:58:03] if that was known, VE would prevent it from showing up ;)