-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(all): remove all direct use of browser globals #10826
Changes from all commits
b71fafc
6767ce7
3335096
59e9f5f
8a27c80
b197cc9
608d4f0
575f995
d88aab9
5cc67ed
c1da2fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
.module('autocompleteDemo', ['ngMaterial']) | ||
.controller('DemoCtrl', DemoCtrl); | ||
|
||
function DemoCtrl ($timeout, $q, $log) { | ||
function DemoCtrl ($timeout, $q, $log, $mdDialog) { | ||
var self = this; | ||
|
||
self.simulateQuery = false; | ||
|
@@ -18,8 +18,14 @@ | |
|
||
self.newState = newState; | ||
|
||
function newState(state) { | ||
alert("Sorry! You'll need to create a Constitution for " + state + " first!"); | ||
function newState(state, $event) { | ||
$mdDialog.show( | ||
$mdDialog | ||
.alert() | ||
.title('state creation failed.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's completely remove the concept of a link or button in the |
||
.textContent("Sorry! You'll need to create a Constitution for " + state + " first!") | ||
.targetEvent($event) | ||
); | ||
} | ||
|
||
// ****************************** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,23 +2,61 @@ | |
'use strict'; | ||
|
||
// If we do not have CryptoJS defined; import it | ||
if (typeof CryptoJS === 'undefined') { | ||
var cryptoSrc = 'https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/md5.js'; | ||
var scriptTag = document.createElement('script'); | ||
scriptTag.setAttribute('src', cryptoSrc); | ||
document.body.appendChild(scriptTag); | ||
function cryptoJsLoader() { | ||
var prom; | ||
var src = '//cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/md5.js'; | ||
function loadCryptoJSInner($document, $q, $window) { | ||
var document = $document[0]; | ||
|
||
function resolveCrypto() { | ||
if (typeof $window.CryptoJS !== 'undefined') { | ||
return $q.resolve($window.CryptoJS); | ||
} | ||
|
||
return $q.reject(new Error("Can't resolve CryptoJS")); | ||
} | ||
|
||
function loadCrypto() { | ||
return $q(function (resolve, reject) { | ||
var s; | ||
s = document.createElement('script'); | ||
s.src = src; | ||
s.onload = resolve; | ||
s.onerror = reject; | ||
document.head.appendChild(s); | ||
}); | ||
} | ||
|
||
return $q.resolve(undefined) | ||
.then(resolveCrypto) | ||
.catch(loadCrypto) | ||
.then(resolveCrypto); | ||
} | ||
|
||
return function($document, $q, $window) { | ||
if (prom) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. promise |
||
return prom; | ||
} | ||
|
||
prom = loadCryptoJSInner($document, $q, $window); | ||
}; | ||
} | ||
|
||
var loader = cryptoJsLoader(); | ||
|
||
angular | ||
.module('contactChipsDemo', ['ngMaterial']) | ||
.controller('ContactChipDemoCtrl', DemoCtrl); | ||
|
||
function DemoCtrl ($q, $timeout, $log, $mdConstant) { | ||
function DemoCtrl ($q, $timeout, $log, $mdConstant, $document, $window) { | ||
var self = this; | ||
var pendingSearch, cancelSearch = angular.noop; | ||
var lastSearch; | ||
|
||
self.allContacts = loadContacts(); | ||
loader($document, $q, $window).then(function (CryptoJS) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This throws:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Urgh, probably a missing return |
||
self.allContacts = loadContacts(CryptoJS); | ||
}); | ||
|
||
self.contacts = [self.allContacts[0]]; | ||
self.asyncContacts = []; | ||
self.keys = [$mdConstant.KEY_CODE.COMMA]; | ||
|
@@ -89,7 +127,7 @@ | |
$log.log('The model has changed to ' + JSON.stringify(newModel) + '.'); | ||
} | ||
|
||
function loadContacts() { | ||
function loadContacts(CryptoJS) { | ||
var contacts = [ | ||
'Marina Augustine', | ||
'Oddr Sarno', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is hard to focus on a PR that seems to be trying to do a lot of changes at once, especially when it includes changes like this line that seems unrelated (changing
<a>
to<md-button>
)I don't think I'll be able to comfortably be able to review a change like this given that it tries to make too many changes at once. I'd prefer to see a PR that works through a predetermined set of steps that brings us to our goal (remove use of globals), e.g.
If the PRs were separated as such, it would be much easier to parse and review. As it is now, it is too risky of a change to confidently LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's just a doc change because they were using window.event.
I just swapped the a for a button because you can't have a
a
without an href, and I was editing that line anyway.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can try running it through presubmits once it is reviewed (@Splaktar - do you want to look at this). If it passes then it's alright with me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'll review before adding the
merge ready
label and asking for it to be run through the presubmits.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new behavior here is quite buggy.

Let's completely remove the concept of a link or button in the
md-not-found
for this demo.