diff --git a/src/Umbraco.Web.UI.Client/docs/tutorials/CreatingAPropertyEditor.ngdoc b/src/Umbraco.Web.UI.Client/docs/tutorials/CreatingAPropertyEditor.ngdoc index 01dee13075..1a5a414653 100644 --- a/src/Umbraco.Web.UI.Client/docs/tutorials/CreatingAPropertyEditor.ngdoc +++ b/src/Umbraco.Web.UI.Client/docs/tutorials/CreatingAPropertyEditor.ngdoc @@ -104,12 +104,12 @@ Then open the `markdowneditor.controller.js` file and edit it so it looks like t angular.module("umbraco") .controller("My.MarkdownEditorController", - //inject umbracos scriptLoader - function ($scope,scriptLoader) { + //inject umbracos assetsService + function ($scope,assetsService) { - //tell the scriptloader to load the markdown.editor libs from the markdown editors + //tell the assetsService to load the markdown.editor libs from the markdown editors //plugin folder - scriptLoader + assetsService .load([ "/app_plugins/markdowneditor/lib/markdown.converter.js", "/app_plugins/markdowneditor/lib/markdown.sanitizer.js", @@ -121,7 +121,7 @@ Then open the `markdowneditor.controller.js` file and edit it so it looks like t }); //load the seperat css for the editor to avoid it blocking our js loading - scriptLoader.load(["/app_plugins/markdowneditor/lib/markdown.css"]); + assetsService.loadCss("/app_plugins/markdowneditor/lib/markdown.css"); }); This loads in our external dependency, but only when its needed by the editor. diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/umbtree.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/umbtree.directive.js index 88e57a8939..82b47c749c 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/umbtree.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/umbtree.directive.js @@ -15,7 +15,8 @@ angular.module("umbraco.directives") section: '@', showoptions: '@', showheader: '@', - cachekey: '@' + cachekey: '@', + eventhandler: '=' }, compile: function (element, attrs) { @@ -33,7 +34,7 @@ angular.module("umbraco.directives") ''; } template += '
+ * angular.module("umbraco").controller("my.controller". function(assetsService){
+ * assetsService.load(["script.js", "styles.css"], $scope).then(function(){
+ * //this code executes when the dependencies are done loading
+ * });
+ * });
+ *
+ *
+ * You can also load individual files, which gives you greater control over what attibutes are passed to the file, as well as timeout
+ *
+ *
+ * angular.module("umbraco").controller("my.controller". function(assetsService){
+ * assetsService.loadJs("script.js", $scope, {charset: 'utf-8'}, 10000 }).then(function(){
+ * //this code executes when the script is done loading
+ * });
+ * });
+ *
+ *
+ * For these cases, there are 2 individual methods, one for javascript, and one for stylesheets:
+ *
+ *
+ * angular.module("umbraco").controller("my.controller". function(assetsService){
+ * assetsService.loadCss("stye.css", $scope, {media: 'print'}, 10000 }).then(function(){
+ * //loadcss cannot determine when the css is done loading, so this will trigger instantly
+ * });
+ * });
+ *
+ */
+angular.module('umbraco.services')
+.factory('assetsService', function ($q, $log, angularHelper) {
+
+ return {
+ /**
+ * @ngdoc method
+ * @name umbraco.services.assetsService#loadCss
+ * @methodOf umbraco.services.assetsService
+ *
+ * @description
+ * Injects a file as a stylesheet into the document head
+ *
+ * @param {String} path path to the css file to load
+ * @param {Scope} scope optional scope to pass into the loader
+ * @param {Object} keyvalue collection of attributes to pass to the stylesheet element
+ * @param {Number} timeout in milliseconds
+ * @returns {Promise} Promise object which resolves when the file has loaded
+ */
+ loadCss : function(path, scope, attributes, timeout){
+ var deferred = $q.defer();
+ var t = timeout || 5000;
+ var a = attributes || undefined;
+
+ yepnope.injectCss(path, function () {
+
+ if (!scope) {
+ deferred.resolve(true);
+ }else{
+ angularHelper.safeApply(scope, function () {
+ deferred.resolve(true);
+ });
+ }
+
+ },a,t);
+
+ return deferred.promise;
+ },
+
+ /**
+ * @ngdoc method
+ * @name umbraco.services.assetsService#loadJs
+ * @methodOf umbraco.services.assetsService
+ *
+ * @description
+ * Injects a file as a javascript into the document
+ *
+ * @param {String} path path to the js file to load
+ * @param {Scope} scope optional scope to pass into the loader
+ * @param {Object} keyvalue collection of attributes to pass to the script element
+ * @param {Number} timeout in milliseconds
+ * @returns {Promise} Promise object which resolves when the file has loaded
+ */
+ loadJs : function(path, scope, attributes, timeout){
+ var deferred = $q.defer();
+ var t = timeout || 5000;
+ var a = attributes || undefined;
+
+ yepnope.injectJs(path, function () {
+
+ if (!scope) {
+ deferred.resolve(true);
+ }else{
+ angularHelper.safeApply(scope, function () {
+ deferred.resolve(true);
+ });
+ }
+
+ },a,t);
+
+ return deferred.promise;
+ },
+
+ /**
+ * @ngdoc method
+ * @name umbraco.services.assetsService#load
+ * @methodOf umbraco.services.assetsService
+ *
+ * @description
+ * Injects a collection of files, this can be a mixed collection of css and js files, the loader will determine how to load them
+ *
+ * **Warning:** if the collection of files contains a .css file, you will in some cases not receive a resolved promise, it is therefore prefered to use the individual loadCss and loadJs methods
+ *
+ * @param {Array} pathArray string array of paths to the files to load
+ * @param {Scope} scope optional scope to pass into the loader
+ * @returns {Promise} Promise object which resolves when all the files has loaded
+ */
+ load: function (pathArray, scope) {
+ var deferred = $q.defer();
+
+ var nonEmpty = _.reject(pathArray, function(item) {
+ return item === undefined || item === "";
+ });
+
+ //don't load anything if there's nothing to load
+ if (nonEmpty.length > 0) {
+
+ yepnope({
+ load: pathArray,
+ complete: function() {
+
+ //if a scope is supplied then we need to make a digest here because
+ // deferred only executes in a digest. This might be required if we
+ // are doing a load script after an http request or some other async call.
+ if (!scope) {
+ deferred.resolve(true);
+ }
+ else {
+ angularHelper.safeApply(scope, function () {
+ deferred.resolve(true);
+ });
+ }
+ }
+ });
+ }
+ else {
+ if (!scope) {
+ deferred.resolve(true);
+ }
+ else {
+ angularHelper.safeApply(scope, function () {
+ deferred.resolve(true);
+ });
+ }
+ }
+
+ return deferred.promise;
+ }
+ };
+});
\ No newline at end of file
diff --git a/src/Umbraco.Web.UI.Client/src/common/services/util.service.js b/src/Umbraco.Web.UI.Client/src/common/services/util.service.js
index 0569c15c00..e2bdd5c668 100644
--- a/src/Umbraco.Web.UI.Client/src/common/services/util.service.js
+++ b/src/Umbraco.Web.UI.Client/src/common/services/util.service.js
@@ -8,13 +8,13 @@
* @description
* Used to lazy load in any JS dependencies that need to be manually loaded in
*/
-function legacyJsLoader(scriptLoader, umbRequestHelper) {
+function legacyJsLoader(assetsService, umbRequestHelper) {
return {
/** Called to load in the legacy tree js which is required on startup if a user is logged in or
after login, but cannot be called until they are authenticated which is why it needs to be lazy loaded. */
loadLegacyTreeJs: function(scope) {
- return scriptLoader.load([umbRequestHelper.getApiUrl("legacyTreeJs", "", "")], scope);
+ return assetsService.loadJs(umbRequestHelper.getApiUrl("legacyTreeJs", "", ""), scope);
}
};
}
diff --git a/src/Umbraco.Web.UI.Client/src/packages/MarkdownEditor/markdowneditor.controller.js b/src/Umbraco.Web.UI.Client/src/packages/MarkdownEditor/markdowneditor.controller.js
index 385f6e3bd5..445955fefc 100644
--- a/src/Umbraco.Web.UI.Client/src/packages/MarkdownEditor/markdowneditor.controller.js
+++ b/src/Umbraco.Web.UI.Client/src/packages/MarkdownEditor/markdowneditor.controller.js
@@ -1,23 +1,23 @@
angular.module("umbraco")
.controller("My.MarkdownEditorController",
-//inject umbracos scriptLoader
-function ($scope,scriptLoader) {
+//inject umbracos assetsServce
+function ($scope,assetsService) {
- //tell the scriptloader to load the markdown.editor libs from the markdown editors
+ //tell the assets service to load the markdown.editor libs from the markdown editors
//plugin folder
- scriptLoader
+ assetsService
.load([
"/app_plugins/markdowneditor/lib/markdown.converter.js",
"/app_plugins/markdowneditor/lib/markdown.sanitizer.js",
"/app_plugins/markdowneditor/lib/markdown.editor.js"
])
.then(function () {
- //this function will execute when all dependencies have loaded
- var converter2 = new Markdown.Converter();
- var editor2 = new Markdown.Editor(converter2, "-" + $scope.model.alias);
+ //this function will execute when all dependencies have loaded
+ var converter2 = new Markdown.Converter();
+ var editor2 = new Markdown.Editor(converter2, "-" + $scope.model.alias);
editor2.run();
});
//load the seperat css for the editor to avoid it blocking our js loading TEMP HACK
- scriptLoader.load(["/app_plugins/markdowneditor/lib/markdown.css"]);
+ assetsService.loadCss("/app_plugins/markdowneditor/lib/markdown.css");
});
\ No newline at end of file
diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/contentpicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/contentpicker.controller.js
index 522daaec8f..95f99b87d8 100644
--- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/contentpicker.controller.js
+++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/contentpicker.controller.js
@@ -1,10 +1,9 @@
//used for the media picker dialog
angular.module("umbraco").controller("Umbraco.Dialogs.ContentPickerController",
function ($scope) {
- $scope.treeCallback = $({});
+ $scope.dialogTreeEventHandler = $({});
- //$scope.treeCallback.bind("treeNodeSelect", function(event, args){
- $scope.$on("treeNodeSelect", function (ev, args) {
+ $scope.dialogTreeEventHandler.bind("treeNodeSelect", function(ev, args){
args.event.preventDefault();
args.event.stopPropagation();
diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/contentpicker.html b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/contentpicker.html
index 0425f7f14d..cef3668740 100644
--- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/contentpicker.html
+++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/contentpicker.html
@@ -11,10 +11,10 @@