Updates from August, 2011 Toggle Comment Threads | Keyboard Shortcuts

  • Mihai Chereji 6:22 pm on August 20, 2011 Permalink | Reply

    This is just a short post to explain… 

    This is just a short post to explain theme and plugin developers how to use my plugin (LocalStorage Plugin), which, btw, made it’s way into the official wp plugin repo – feedback and impressions always welcome. 🙂

    Thanks to the awesomeness of amplify.js, it’s easy to have something akin to WP PHP hooks in JavaScript – beyond events and callbacks.

    You see, the core of the amplify library offers two methods –  publish and subscribe, which are equivalent to do_action and add_action.For more info, check out amplify.js documentation

    The cool thing about it is that you can send parameters, and they’re sent by reference, so it works both as actions and as filters.

    In the hooks I’ve added so far, you can modify the post_data which will be saved, or submitted, before the actions take place

    a.publish('aboutToSave', action, post_data);

    The “plugin” example I’ve chosen to implement backs up the post format and modifies the value when showing the backup (on request).

    amplify.subscribe("aboutToSave", function (action, post_data) {
    	post_data.post_format = $('input.post-format:checked').val();
    amplify.subscribe("showBackup", function (action, post_data) {
    	$("input.post-format").filter("[value=" + post_data.post_format + "]").prop("checked", true);

    And this is basically it! I’ll add some more examples later, but this is what it’s mostly about.

    • Andrew Ozz 8:57 pm on August 21, 2011 Permalink | Reply

      Tried to get it to work a few times by disconnecting the network cable. It seems to save to the local storage but later fails to show the notice to publish/restore the last saved content. Not sure what’s the cause, will look more into it.

      Also made a small patch to the plugin, http://plugins.trac.wordpress.org/ticket/1373

      • Mihai Chereji 9:45 pm on August 21, 2011 Permalink | Reply

        Hey, what browser version are you using?

        • Andrew Ozz 9:47 pm on August 21, 2011 Permalink

          FF 5 and Chrome 12 on win, can test in other too.

        • Mihai Chereji 9:51 pm on August 21, 2011 Permalink

          Are you using the version from the plug-in repo?

        • Andrew Ozz 9:52 pm on August 21, 2011 Permalink

          Yes, that’s the latest “official” one, right? It shows the “Publish/Delete” notice only if I put FF in offline mode before quitting. Will try to trace it later.

        • Mihai Chereji 9:54 pm on August 21, 2011 Permalink

          Yeah, will look into it. Tested it on both Chrome and FF myself, would love to know what other plugins you have installed.

        • Andrew Ozz 9:56 pm on August 21, 2011 Permalink

          No other plugins but was testing on trunk (WP 3.3-alpha). Not many JS changes there from 3.2.

        • Mihai Chereji 9:59 pm on August 21, 2011 Permalink

          Tested on that too (that’s what running on my blog too). The thing is, if you leave the page on the editor, when the connection comes back online, you should not notice anything, it will sync in the background.

          If you navigate to another page (or reload the page before it syncs) you should indeed get a notification.

        • Andrew Ozz 10:02 pm on August 21, 2011 Permalink

          I was quitting the browser, connecting the network cable and starting the browser again 🙂

        • Mihai Chereji 10:11 pm on August 21, 2011 Permalink

          Then indeed, you should have seen a notification 😀

          This is quite weird, as I’ve tried the same on both FF and Chrome.

        • Mihai Chereji 11:52 pm on August 21, 2011 Permalink

          After some more debugging, we found out that this was due to @azaozz ‘s browsers acting up (somehow deleting localStorage on closing, thus rendering it useless).

  • Mihai Chereji 6:43 pm on July 4, 2011 Permalink | Reply
    Tags: , UX,   

    Last week was pretty good.

    The plugin now has a component that loads on all admin pages and checks if you have backed up pages and syncs if it needs to.

    It also checks when an autosave request fails in the post editor, and also sends a dummy request when you press the “Publish” button.

    (this part was also posted here but I might as well copy-paste it, as this blog gets a lot more visitors)

    @mitchoyoshitaka believes that when the server is not reachable, the “Publish/Update” buttons should be greyed out. I think a notification that the post will be submitted later suffices, and greying out the buttons detters the user from clicking, and (part of) what I’m trying to do is to make it ok to push that button even when offline.

    We’d both love some more input from more UX-savvy people.

    This week I’ll work on some user notifications and some bugs to bring it to a really usable version before midterm 🙂

    • Simon Wheatley 7:54 am on July 6, 2011 Permalink | Reply

      My 2 cents: I agree that greying out will discourage users from clicking; perhaps there could be some subtle indication somewhere that the system is operating “offline”?

      • Mihai Chereji 4:30 pm on July 6, 2011 Permalink | Reply

        Right now, there’s a message that appears below the editor, where “Draft successfully saved” usually appears, that says something along the lines of “Connection seems to be down, but that’s ok”. @azaozz suggested to move this below the main publishing box so it’s clear as day when the user clicks the button.

  • Mihai Chereji 8:33 am on June 13, 2011 Permalink | Reply
    Tags: ,   

    Local Storage weekly update & various stuff 

    Well, this was a productive week, if I say so myself.

    What’s done:

    • Backing up is mostly done, I believe. In it’s current form, the plugin differentiates between autosaves, drafts and intentions to publish. It puts the IDs  in different lists in storage, and each entry is of the format ID-autosave, ID-draft, ID-publish. This is easily extendable, as the lsBackup function, which does the backup, takes the ‘action’ parameter, and simply concatenates the paramter to the ID of the post. Don’t know the specific case for which this should be extensible, but, hey, power to the people, right?
    • Syncing to the server works for autosaves. I took the ‘action’ case from admin-ajax.php and modified it a little bit (disabled nonces temporarily,etc). I’ll have to do something similar for drafts and published posts.

    What will I do this week:

    • Finish the server-side code. This entails treating published and draft posts, adding back nonces, detailing error messages (like ‘the post has been edited by someone else since you started working’, credentials, etc).
    • Start working on a reliable way to determine when the connection is down. My very shallow tests have shown that navigator.onLine, which I had planned to use isn’t really useful. In Firefox, it doesn’t detect whether there’s an established connection, but rather if the ‘Work offline’ switch from the File menu is enabled. Chrome doesn’t even have that switch (or I couldn’t find it), so it always returns true. Will keep checking other browsers’ behavior. @azaozz (Andrew Ozz) also made the very good point that while you might have a working connection, the server itself may go down, so the best way to check is with a dummy request.
    • Polish client-side code. Right now it doesn’t have anything in the way of error handling, or stuff like that, but that will quickly change. Also, I need to remove posts from the list once they were successfully synchronized.

    I think I can safely say that I’m back on schedule, and by mid-week, I should be a bit ahead.

    Questions / opinions needed:

    • Right now, I send a request to the server for each backed up post, be it autosave, draft or published post. Realistically speaking, I don’t expect a server to have all that many posts at a time to send to the server, so I’m not sure if it penalties performance all that bad, but I sense that I should send one request with all the posts at once, but that complicates things a little. So, I’m really at a loss as to what to do.
    • Plugging into the Javascript code in WordPress is harder than it needs to be. Other than replacing the entire autosave function with your own, there’s no way to actually plug in. After a discussion with @mitcho and @azaozz, it’s become clear that a pub/sub system, or something similar to the actions model in the PHP code is necessary. I’d like to plug amplify.js again (it hit beta not long ago) as a potential candidate for inclusion. It features a pub/sub module, which, as @mitcho pointed out, is pretty close to the do/add action model in WP PHP. I’ve yet to check on any performance issues.

    That’s about it for now.

    PS – this may be noobish, or may have been discussed to death, or it may simply be an issue of style, but sifting through admin-ajax.php and other parts of the code, I came across a lot of examples of what I heard being called “Yoda expressions” (e.g. “if( 0 == $id)” instead of  “if( $id == 0)”). When translating the code in my head, it just sounds completely un-natural in both Romanian and English (and even in my poor French). Does this bring some performance bonus in PHP that I’m not aware of, or is that code maybe written by someone whose native language finds this particular construct natural, or is this a legitimate coding style I haven’t encountered too often before?

Compose new post
Next post/Next comment
Previous post/Previous comment
Show/Hide comments
Go to top
Go to login
Show/Hide help
shift + esc