{"action":"created","issue":{"url":"https://api.github.com/repos/resrcit/resrc.js/issues/3","labels_url":"https://api.github.com/repos/resrcit/resrc.js/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/resrcit/resrc.js/issues/3/comments","events_url":"https://api.github.com/repos/resrcit/resrc.js/issues/3/events","html_url":"https://github.com/resrcit/resrc.js/pull/3","id":49065052,"number":3,"title":"Always update image source when calling resrc.run()","user":{"login":"peyerluk","id":47606,"avatar_url":"https://avatars.githubusercontent.com/u/47606?v=3","gravatar_id":"","url":"https://api.github.com/users/peyerluk","html_url":"https://github.com/peyerluk","followers_url":"https://api.github.com/users/peyerluk/followers","following_url":"https://api.github.com/users/peyerluk/following{/other_user}","gists_url":"https://api.github.com/users/peyerluk/gists{/gist_id}","starred_url":"https://api.github.com/users/peyerluk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peyerluk/subscriptions","organizations_url":"https://api.github.com/users/peyerluk/orgs","repos_url":"https://api.github.com/users/peyerluk/repos","events_url":"https://api.github.com/users/peyerluk/events{/privacy}","received_events_url":"https://api.github.com/users/peyerluk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2014-11-17T09:31:24Z","updated_at":"2016-01-25T08:45:24Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/resrcit/resrc.js/pulls/3","html_url":"https://github.com/resrcit/resrc.js/pull/3","diff_url":"https://github.com/resrcit/resrc.js/pull/3.diff","patch_url":"https://github.com/resrcit/resrc.js/pull/3.patch"},"body":"This pull-request fixes a problem where calling `resrc.run(elem)` would not reset the src attribute of the elem even though the `data-src` attribute of that element was changed.\r\n\r\nThis is because of an internal logic that will abort setting the source under the following conditions:\r\n```javascript\r\nif (options.resrcOnResizeDown === false) {\r\n  // Return if the last width of the element is >= to the current width.\r\n  if (elem.lastWidth >= currentElemWidth) {\r\n    return;\r\n  }\r\n}\r\n``` \r\ncode: https://github.com/resrcit/resrc.js/blob/31a398ad083a8dbf68460f35e9a05ecae06f7274/src/resrc.js#L731\r\n\r\nIn our use case of a WYSIWYG editor where users can change image urls or image crops and we reset the `data-src` attribute to update the image this behaviour makes using the resrc.it script as it is unusable unless we set `resrcOnResizeDown` to true. Which is counter-intuitive and very error prone to changes.\r\n\r\nSo we refactored the `run` command and split up the logic to conditionally update an element into its own method  which is currently only called after pinching an element. Calls to `resrc.run` will now always update the src if the `data-src` attribute was changed.\r\n\r\nAdditionally we added a convenience method `setImageUrl()` which allows to update source of an image with a new url.\r\n\r\nHere's a quick example:\r\n```javascript\r\n// new\r\nresrc.setImageUrl(elem, 'http://image.com/1.jpg');\r\n\r\n// currently\r\nelem.setAttribute('data-src', 'http://image.com/1.jpg');\r\nresrc.run(elem);\r\n```\r\n\r\nFinally we added a few tests and had to include karma for it. To run the tests execute `grunt karma`."},"comment":{"url":"https://api.github.com/repos/resrcit/resrc.js/issues/comments/174438904","html_url":"https://github.com/resrcit/resrc.js/pull/3#issuecomment-174438904","issue_url":"https://api.github.com/repos/resrcit/resrc.js/issues/3","id":174438904,"user":{"login":"masone","id":2797,"avatar_url":"https://avatars.githubusercontent.com/u/2797?v=3","gravatar_id":"","url":"https://api.github.com/users/masone","html_url":"https://github.com/masone","followers_url":"https://api.github.com/users/masone/followers","following_url":"https://api.github.com/users/masone/following{/other_user}","gists_url":"https://api.github.com/users/masone/gists{/gist_id}","starred_url":"https://api.github.com/users/masone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/masone/subscriptions","organizations_url":"https://api.github.com/users/masone/orgs","repos_url":"https://api.github.com/users/masone/repos","events_url":"https://api.github.com/users/masone/events{/privacy}","received_events_url":"https://api.github.com/users/masone/received_events","type":"User","site_admin":false},"created_at":"2016-01-25T08:45:24Z","updated_at":"2016-01-25T08:45:24Z","body":"Hey @domfee - It has been a while we opened this PR. I'm happy to update it if you are willing to merge this :)"}}