{"action":"created","issue":{"url":"https://api.github.com/repos/fraywing/textAngular/issues/892","labels_url":"https://api.github.com/repos/fraywing/textAngular/issues/892/labels{/name}","comments_url":"https://api.github.com/repos/fraywing/textAngular/issues/892/comments","events_url":"https://api.github.com/repos/fraywing/textAngular/issues/892/events","html_url":"https://github.com/fraywing/textAngular/issues/892","id":107052016,"number":892,"title":"Module breaks if rangy is not defined in requirejs","user":{"login":"afreeland","id":3135030,"avatar_url":"https://avatars.githubusercontent.com/u/3135030?v=3","gravatar_id":"","url":"https://api.github.com/users/afreeland","html_url":"https://github.com/afreeland","followers_url":"https://api.github.com/users/afreeland/followers","following_url":"https://api.github.com/users/afreeland/following{/other_user}","gists_url":"https://api.github.com/users/afreeland/gists{/gist_id}","starred_url":"https://api.github.com/users/afreeland/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/afreeland/subscriptions","organizations_url":"https://api.github.com/users/afreeland/orgs","repos_url":"https://api.github.com/users/afreeland/repos","events_url":"https://api.github.com/users/afreeland/events{/privacy}","received_events_url":"https://api.github.com/users/afreeland/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/fraywing/textAngular/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-17T19:05:58Z","updated_at":"2015-09-17T19:54:22Z","closed_at":null,"body":"Was previously using 1.2.2 of textAngular and decided to upgrade to a more stable version, 1.4.5.  Loaded in each necessary file `textAngular.css`, `textAngular-sanitize.min.js`, `textAngular-rangy.min.js`, and `textAngular.js`....which caused all some grief for over an hour.\r\n\r\nDecided to take a deep dive through textAngular and came across what I believe is the issue:\r\n```\r\ntextAngular.run([function(){\r\n\t/* istanbul ignore next: not sure how to test this */\r\n\t// Require Rangy and rangy savedSelection module.\r\n\tif (typeof define === 'function' && define.amd) {\r\n\t\t// AMD. Register as an anonymous module.\r\n\t\tdefine(function(require) {\r\n\t\t\twindow.rangy = require('rangy');\r\n\t\t\twindow.rangy.saveSelection = require('rangy/lib/rangy-selectionsaverestore');\r\n\t\t});\r\n\t} else if (typeof require ==='function' && typeof module !== 'undefined' && typeof exports === 'object') {\r\n\t\t// Node/CommonJS style\r\n\t\twindow.rangy = require('rangy');\r\n\t\twindow.rangy.saveSelection = require('rangy/lib/rangy-selectionsaverestore');\r\n\t} else {\r\n\t\t// Ensure that rangy and rangy.saveSelection exists on the window (global scope).\r\n\t\t// TODO: Refactor so that the global scope is no longer used.\r\n\t\tif(!window.rangy){\r\n\t\t\tthrow(\"rangy-core.js and rangy-selectionsaverestore.js are required for textAngular to work correctly, rangy-core is not yet loaded.\");\r\n\t\t}else{\r\n\t\t\twindow.rangy.init();\r\n\t\t\tif(!window.rangy.saveSelection){\r\n\t\t\t\tthrow(\"rangy-selectionsaverestore.js is required for textAngular to work correctly.\");\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}]);\r\n```\r\n\r\nThis method assumes that if `require` is available that `rangy` can be **required**...however, we have not implemented all files through require, rangy is among those not implemented. The really crummy part is that even though require fails to load, no errors are thrown and the app appears to just break.\r\n\r\nChanging the above code to the below solved this for us.  I may try to fork later and put in a pull request with a proper fix...but wanted to list this as a concern to others that may run across this issue.\r\n\r\n```\r\ntextAngular.run([function(){\r\n\t// Ensure that rangy and rangy.saveSelection exists on the window (global scope).\r\n\t// TODO: Refactor so that the global scope is no longer used.\r\n\tif(!window.rangy){\r\n\t\tthrow(\"rangy-core.js and rangy-selectionsaverestore.js are required for textAngular to work correctly, rangy-core is not yet loaded.\");\r\n\t}else{\r\n\t\twindow.rangy.init();\r\n\t\tif(!window.rangy.saveSelection){\r\n\t\t\tthrow(\"rangy-selectionsaverestore.js is required for textAngular to work correctly.\");\r\n\t\t}\r\n\t}\r\n\r\n}]);\r\n```"},"comment":{"url":"https://api.github.com/repos/fraywing/textAngular/issues/comments/141207134","html_url":"https://github.com/fraywing/textAngular/issues/892#issuecomment-141207134","issue_url":"https://api.github.com/repos/fraywing/textAngular/issues/892","id":141207134,"user":{"login":"pbassut","id":1500037,"avatar_url":"https://avatars.githubusercontent.com/u/1500037?v=3","gravatar_id":"","url":"https://api.github.com/users/pbassut","html_url":"https://github.com/pbassut","followers_url":"https://api.github.com/users/pbassut/followers","following_url":"https://api.github.com/users/pbassut/following{/other_user}","gists_url":"https://api.github.com/users/pbassut/gists{/gist_id}","starred_url":"https://api.github.com/users/pbassut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pbassut/subscriptions","organizations_url":"https://api.github.com/users/pbassut/orgs","repos_url":"https://api.github.com/users/pbassut/repos","events_url":"https://api.github.com/users/pbassut/events{/privacy}","received_events_url":"https://api.github.com/users/pbassut/received_events","type":"User","site_admin":false},"created_at":"2015-09-17T19:54:22Z","updated_at":"2015-09-17T19:54:22Z","body":"We try our best :)\r\nThanks again for the report."}}