-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/initial module #2
Merged
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
37c54d6
initial SkrollrService and snSkrollr directive
jamesjwarren a73df09
update README
jamesjwarren 014e17d
remove loading from SkrollrService
jamesjwarren ef66bca
refactor skrollr initialisation
jamesjwarren b7712c8
remove initialisation from refresh directive
jamesjwarren 218fb38
update README
jamesjwarren e37e019
replace initialisation directive with provider
jamesjwarren 3a33b90
update README with provider config usage
jamesjwarren 0315a71
rename init object to config
jamesjwarren 75d0a39
remove $q - no longer required
jamesjwarren 69a750e
unit test for snSkrollrProvider
jamesjwarren 58a04b7
combine module into single file
jamesjwarren 703aeb6
unit tests
jamesjwarren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"use strict"; | ||
/** | ||
* Load and initialise skrollrjs, based on: | ||
* {@link http://stackoverflow.com/questions/23715337/integrating-skrollr-w-angularjs-single-page-app} | ||
* @author SOON_ | ||
* @module sn.skrollr | ||
* @class snSkrollrService | ||
*/ | ||
angular.module("sn.skrollr").service("snSkrollrService", [ | ||
"$document", | ||
"$q", | ||
"$rootScope", | ||
"$window", | ||
/** | ||
* @constructor | ||
* @param {Object} $document angular wrapper for document | ||
* @param {Service} $q promise service | ||
* @param {Object} $rootScope data on rootScope | ||
* @param {Object} $window angular wrapper for window object | ||
*/ | ||
function($document, $q, $rootScope, $window){ | ||
|
||
var defer = $q.defer(); | ||
|
||
function onScriptLoad() { | ||
// Load skrollr.js in the browser | ||
$rootScope.$apply(function() { | ||
var s = $window.skrollr.init({ | ||
forceHeight: false, | ||
smoothScrolling: true, | ||
mobileDeceleration: 0.004 | ||
}); | ||
defer.resolve(s); | ||
}); | ||
} | ||
|
||
/** | ||
* Create a script tag with skrollr as the source | ||
* and call our onScriptLoad callback when it | ||
* has been loaded | ||
*/ | ||
var scriptTag = $document[0].createElement("script"); | ||
scriptTag.type = "text/javascript"; | ||
scriptTag.async = true; | ||
scriptTag.src = "components/skrollr/dist/skrollr.min.js"; | ||
|
||
scriptTag.onreadystatechange = function () { | ||
if (this.readyState === "complete") { | ||
onScriptLoad(); | ||
} | ||
}; | ||
|
||
scriptTag.onload = onScriptLoad; | ||
|
||
var s = $document[0].getElementsByTagName("body")[0]; | ||
s.appendChild(scriptTag); | ||
|
||
return { | ||
skrollr: function() { return defer.promise; } | ||
}; | ||
|
||
} | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use strict"; | ||
/** | ||
* Wrap skrollr.js | ||
* @author SOON_ | ||
* @module sn.skrollr | ||
*/ | ||
angular.module("sn.skrollr", []); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"use strict"; | ||
/** | ||
* Refresh skrollrjs on element load | ||
* @author SOON_ | ||
* @module sn.skrollr | ||
* @class snSkrollr | ||
*/ | ||
angular.module("sn.skrollr").directive("snSkrollr", [ | ||
"snSkrollrService", | ||
/** | ||
* @constructor | ||
*/ | ||
function (snSkrollrService){ | ||
return { | ||
restrict: "A", | ||
link: function($scope, $element) { | ||
snSkrollrService.skrollr().then(function(skrollr){ | ||
skrollr.refresh(); | ||
}); | ||
} | ||
}; | ||
} | ||
]); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
{ | ||
"vendor": [ | ||
"app/components/angular/angular.js", | ||
"app/components/angular-route/angular-route.js" | ||
"app/components/angular/angular.js" | ||
], | ||
"application": [ | ||
"app/js/soon-example/app.js", | ||
"app/js/soon-example/config.js", | ||
"app/js/soon-example/controllers/SearchCtrl.js", | ||
"app/js/soon-example/controllers/ResultsCtrl.js" | ||
"app/js/app.js", | ||
"app/js/skrollr.js", | ||
"app/js/SkrollrService.js" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why inject the skrollr library tag using javascript? This presumes the person using this directive has the same directory structure as us e.g. has the skrollr lib in
app/components/
. Also this won't work, even for us, when all the javascript is concatenated and/or minified.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.
Yeh I was concerned about this too. The reason I have used this method is we need to initialise skrollr and directives after it has loaded.
Just including the script in the skrollr is never defined before it is used.
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.
https://github.com/Prinzhorn/skrollr#lets-get-serious
You just need to wait till the document loads before initialising your directives. You can use the
window.onload
event to be sure skrollr is defined. It will only run once all assets e.g. css files, javascript files have been loaded.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.
Ahh for some reason I had assumed angular ran within window.load anyway so neglected to think of it. Does the trick, cheers.