From 8db763c9531057b0ff166fce3b924ac5dec3e1c1 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 19 Jun 2013 13:45:41 +1000 Subject: [PATCH] Updated server side stuff to work with new yepnope which makes things much simpler. --- src/Umbraco.Core/Manifest/ManifestParser.cs | 83 +++++---- src/Umbraco.Core/Manifest/PackageManifest.cs | 5 - .../JsInitializationTests.cs | 34 ++++ .../AngularIntegration/RequireJsInitTests.cs | 65 ------- .../Manifest/ManifestParserTests.cs | 12 +- src/Umbraco.Tests/Umbraco.Tests.csproj | 2 +- .../Js/googlemaps.controller.js | 87 --------- .../PropertyEditors/Views/googlemaps.html | 3 - .../App_Plugins/GoogleMaps/package.manifest | 19 -- .../MyPackage/Common/Js/MyPackage.js | 9 +- .../App_Plugins/MyPackage/Package.manifest | 14 +- .../MyPackage/PropertyEditors/Js/CsvEditor.js | 13 +- .../PropertyEditors/Js/FileUploadEditor.js | 29 ++- .../PropertyEditors/Js/PostcodeEditor.js | 13 +- .../PropertyEditors/Js/RegexEditor.js | 11 +- .../PropertyEditors/Views/CsvEditor.html | 2 +- .../PropertyEditors/js/simpleeditor.js | 14 +- .../App_Plugins/SimpleEditor/package.manifest | 9 +- .../umbraco/Views/Default.cshtml | 17 +- .../umbraco/Views/common/dashboard.html | 2 +- src/Umbraco.Web.UI/umbraco/js/app_dev.js | 21 +-- src/Umbraco.Web.UI/umbraco/js/loader.js | 28 +++ .../Editors/BackOfficeController.cs | 4 +- .../{RequireJsInit.cs => JsInitialization.cs} | 172 ++++++++---------- src/Umbraco.Web/UI/JavaScript/JsInitialize.js | 18 ++ src/Umbraco.Web/UI/JavaScript/Main.js | 16 +- .../UI/JavaScript/RequireJsConfig.js | 45 ----- .../UI/JavaScript/RequireJsInitialize.js | 17 -- .../UI/JavaScript/Resources.Designer.cs | 81 ++++----- src/Umbraco.Web/UI/JavaScript/Resources.resx | 9 +- src/Umbraco.Web/Umbraco.Web.csproj | 15 +- 31 files changed, 329 insertions(+), 540 deletions(-) create mode 100644 src/Umbraco.Tests/AngularIntegration/JsInitializationTests.cs delete mode 100644 src/Umbraco.Tests/AngularIntegration/RequireJsInitTests.cs delete mode 100644 src/Umbraco.Web.UI/App_Plugins/GoogleMaps/PropertyEditors/Js/googlemaps.controller.js delete mode 100644 src/Umbraco.Web.UI/App_Plugins/GoogleMaps/PropertyEditors/Views/googlemaps.html delete mode 100644 src/Umbraco.Web.UI/App_Plugins/GoogleMaps/package.manifest create mode 100644 src/Umbraco.Web.UI/umbraco/js/loader.js rename src/Umbraco.Web/UI/JavaScript/{RequireJsInit.cs => JsInitialization.cs} (76%) create mode 100644 src/Umbraco.Web/UI/JavaScript/JsInitialize.js delete mode 100644 src/Umbraco.Web/UI/JavaScript/RequireJsConfig.js delete mode 100644 src/Umbraco.Web/UI/JavaScript/RequireJsInitialize.js diff --git a/src/Umbraco.Core/Manifest/ManifestParser.cs b/src/Umbraco.Core/Manifest/ManifestParser.cs index 5dc4a1aec5..e772cd3df7 100644 --- a/src/Umbraco.Core/Manifest/ManifestParser.cs +++ b/src/Umbraco.Core/Manifest/ManifestParser.cs @@ -71,8 +71,6 @@ namespace Umbraco.Core.Manifest return currDir.GetFiles("Package.manifest") .Select(f => File.ReadAllText(f.FullName)) .ToList(); - - return Enumerable.Empty(); } /// @@ -109,18 +107,11 @@ namespace Umbraco.Core.Manifest var deserialized = JsonConvert.DeserializeObject(m); - //validate the config - var config = deserialized.Properties().Where(x => x.Name == "config").ToArray(); - if (config.Length > 1) - { - throw new FormatException("The manifest is not formatted correctly contains more than one 'config' element"); - } - - //validate the init - var init = deserialized.Properties().Where(x => x.Name == "init").ToArray(); + //validate the javascript + var init = deserialized.Properties().Where(x => x.Name == "javascript").ToArray(); if (init.Length > 1) { - throw new FormatException("The manifest is not formatted correctly contains more than one 'init' element"); + throw new FormatException("The manifest is not formatted correctly contains more than one 'javascript' element"); } //validate the property editors section @@ -130,7 +121,7 @@ namespace Umbraco.Core.Manifest throw new FormatException("The manifest is not formatted correctly contains more than one 'propertyEditors' element"); } - var jConfig = config.Any() ? (JObject) deserialized["config"] : new JObject(); + var jConfig = init.Any() ? (JArray)deserialized["javascript"] : new JArray(); ReplaceVirtualPaths(jConfig); //replace virtual paths for each property editor @@ -152,8 +143,7 @@ namespace Umbraco.Core.Manifest var manifest = new PackageManifest() { - JavaScriptConfig = jConfig, - JavaScriptInitialize = init.Any() ? (JArray)deserialized["init"] : new JArray(), + JavaScriptInitialize = jConfig, PropertyEditors = propEditors.Any() ? (JArray)deserialized["propertyEditors"] : new JArray(), }; result.Add(manifest); @@ -161,6 +151,46 @@ namespace Umbraco.Core.Manifest return result; } + /// + /// Replaces any virtual paths found in properties + /// + /// + private static void ReplaceVirtualPaths(JArray jarr) + { + foreach (var i in jarr) + { + ReplaceVirtualPaths(i); + } + } + + /// + /// Replaces any virtual paths found in properties + /// + /// + private static void ReplaceVirtualPaths(JToken jToken) + { + if (jToken.Type == JTokenType.Object) + { + //recurse + ReplaceVirtualPaths((JObject)jToken); + } + else + { + var value = jToken as JValue; + if (value != null) + { + if (value.Type == JTokenType.String) + { + if (value.Value().StartsWith("~/")) + { + //replace the virtual path + value.Value = IOHelper.ResolveUrl(value.Value()); + } + } + } + } + } + /// /// Replaces any virtual paths found in properties /// @@ -168,27 +198,8 @@ namespace Umbraco.Core.Manifest private static void ReplaceVirtualPaths(JObject jObj) { foreach (var p in jObj.Properties().Select(x => x.Value)) - { - if (p.Type == JTokenType.Object) - { - //recurse - ReplaceVirtualPaths((JObject) p); - } - else - { - var value = p as JValue; - if (value != null) - { - if (value.Type == JTokenType.String) - { - if (value.Value().StartsWith("~/")) - { - //replace the virtual path - value.Value = IOHelper.ResolveUrl(value.Value()); - } - } - } - } + { + ReplaceVirtualPaths(p); } } diff --git a/src/Umbraco.Core/Manifest/PackageManifest.cs b/src/Umbraco.Core/Manifest/PackageManifest.cs index 37835e03bd..f70f51644c 100644 --- a/src/Umbraco.Core/Manifest/PackageManifest.cs +++ b/src/Umbraco.Core/Manifest/PackageManifest.cs @@ -7,11 +7,6 @@ namespace Umbraco.Core.Manifest /// internal class PackageManifest { - /// - /// The json configuration used to configure the JS dependencies - /// - public JObject JavaScriptConfig { get; set; } - /// /// The json array used to initialize the application with the JS dependencies required /// diff --git a/src/Umbraco.Tests/AngularIntegration/JsInitializationTests.cs b/src/Umbraco.Tests/AngularIntegration/JsInitializationTests.cs new file mode 100644 index 0000000000..c7309cdcb4 --- /dev/null +++ b/src/Umbraco.Tests/AngularIntegration/JsInitializationTests.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NUnit.Framework; +using Newtonsoft.Json.Linq; +using Umbraco.Core.Manifest; +using Umbraco.Web.UI.JavaScript; + +namespace Umbraco.Tests.AngularIntegration +{ + [TestFixture] + public class JsInitializationTests + { + + [Test] + public void Get_Default_Init() + { + var init = JsInitialization.GetDefaultInitialization(); + Assert.IsTrue(init.Any()); + } + + [Test] + public void Parse_Main() + { + var result = JsInitialization.ParseMain("[World]"); + + Assert.IsTrue(result.StartsWith(@"yepnope({ + + load: [World],")); + } + } +} diff --git a/src/Umbraco.Tests/AngularIntegration/RequireJsInitTests.cs b/src/Umbraco.Tests/AngularIntegration/RequireJsInitTests.cs deleted file mode 100644 index 32950ce61e..0000000000 --- a/src/Umbraco.Tests/AngularIntegration/RequireJsInitTests.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using NUnit.Framework; -using Newtonsoft.Json.Linq; -using Umbraco.Core.Manifest; -using Umbraco.Web.UI.JavaScript; - -namespace Umbraco.Tests.AngularIntegration -{ - [TestFixture] - public class RequireJsInitTests - { - - - - [Test] - public void Get_Default_Config() - { - var config = RequireJsInit.GetDefaultConfig(); - var paths = config.Properties().SingleOrDefault(x => x.Name == "paths"); - var shim = config.Properties().SingleOrDefault(x => x.Name == "shim"); - Assert.IsNotNull(paths); - Assert.AreEqual(typeof(JProperty), paths.GetType()); - Assert.IsNotNull(shim); - Assert.AreEqual(typeof(JProperty), shim.GetType()); - } - - [Test] - public void Get_Default_Init() - { - var init = RequireJsInit.GetDefaultInitialization(); - Assert.IsTrue(init.Any()); - } - - [Test] - public void Parse_Main() - { - var result = RequireJsInit.ParseMain("{Hello}", "[World]"); - - Assert.IsTrue(result.StartsWith("require.config({Hello});")); - Assert.IsTrue(result.Contains("require([World]")); - } - - [Test] - public void Parse_Main_With_JS_Function() - { - var result = RequireJsInit.ParseMain(@"{ - waitSeconds: 120, - paths: { - jquery: '../lib/jquery/jquery-1.8.2.min' - }, - shim: { - 'tinymce':""@@@@{exports:'tinyMCE',init:function() { this.tinymce.DOM.events.domLoaded = true; return this.tinymce; } }"" - } - }", "[World]"); - - Assert.IsFalse(result.Contains("@@@@")); - Assert.IsTrue(result.Contains("'tinymce':{exports:'tinyMCE',init:function()")); - } - - } -} diff --git a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs index f3ee7b6f4b..f5da535b70 100644 --- a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs +++ b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs @@ -139,16 +139,16 @@ namespace Umbraco.Belle.Tests public void Create_Manifest_From_File_Content() { var content1 = "{}"; - var content2 = "{config: {}, init: []}"; - var content3 = "{config: {paths: {blah: 'mypath.js'}, shim: {'blah' : {'exports': 'blah'}}}, init: []}"; - var content4 = "{propertyEditors: [], config: {paths: {blah: 'mypath.js'}, shim: {'blah' : {'exports': 'blah'}}}, init: []}"; + var content2 = "{javascript: []}"; + var content3 = "{javascript: ['~/test.js', '~/test2.js']}"; + var content4 = "{propertyEditors: [], javascript: ['~/test.js', '~/test2.js']}"; var result = ManifestParser.CreateManifests(null, content1, content2, content3, content4); Assert.AreEqual(4, result.Count()); - Assert.AreEqual(0, result.ElementAt(1).JavaScriptConfig.Properties().Count()); - Assert.AreEqual(2, result.ElementAt(2).JavaScriptConfig.Properties().Count()); - Assert.AreEqual(2, result.ElementAt(3).JavaScriptConfig.Properties().Count()); + Assert.AreEqual(0, result.ElementAt(1).JavaScriptInitialize.Count); + Assert.AreEqual(2, result.ElementAt(2).JavaScriptInitialize.Count); + Assert.AreEqual(2, result.ElementAt(3).JavaScriptInitialize.Count); } diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index bcd3850c72..d9565a9b18 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -146,7 +146,7 @@ - + diff --git a/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/PropertyEditors/Js/googlemaps.controller.js b/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/PropertyEditors/Js/googlemaps.controller.js deleted file mode 100644 index b0ba78a111..0000000000 --- a/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/PropertyEditors/Js/googlemaps.controller.js +++ /dev/null @@ -1,87 +0,0 @@ -define(['app', 'angular'], function (app, angular) { - -angular.module("umbraco") -.controller("Umbraco.Editors.GoogleMapsController", - function ($rootScope, $scope, notificationsService, dialogService) { - - require( - [ - 'async!http://maps.google.com/maps/api/js?sensor=false' - ], - function () { - - - //Google maps is available and all components are ready to use. - var geocoder = new google.maps.Geocoder(); - var latLng = new google.maps.LatLng(-34.397, 150.644); - var mapDiv = document.getElementById($scope.model.alias + '_map'); - var mapOptions = { - zoom: 2, - center: latLng, - mapTypeId: google.maps.MapTypeId.ROADMAP - }; - - //lets load the map - var map = new google.maps.Map(mapDiv, mapOptions); - - - - - //lets add a picture on click - google.maps.event.addListener(map, 'click', function(event) { - - //opens the media dialog - dialogService.mediaPicker({scope: $scope, callback: function(data){ - var image = data.selection[0].thumbnail; - var latLng = event.latLng; - var marker = new google.maps.Marker({ - map: map, - icon: image, - position: latLng, - draggable: true - }); - - google.maps.event.addListener(marker, "dragend", function(e){ - var newLat = marker.getPosition().lat(); - var newLng = marker.getPosition().lng(); - - //find the location - codeLatLng(marker.getPosition()); - - //set the model value - $scope.model.value = newLat + "," + newLng; - }); - - }}); - }); - - - - - function codeLatLng(latLng) { - geocoder.geocode({'latLng': latLng}, - function(results, status) { - if (status == google.maps.GeocoderStatus.OK) { - var location = results[0].formatted_address; - $rootScope.$apply(function () { - - //alert(location); - - notificationsService.success("Pete just went to: ", location); - }); - } - }); - } - - - - $('a[data-toggle="tab"]').on('shown', function (e) { - google.maps.event.trigger(map, 'resize'); - }); - } - ); -}); - -return angular; - -}); \ No newline at end of file diff --git a/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/PropertyEditors/Views/googlemaps.html b/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/PropertyEditors/Views/googlemaps.html deleted file mode 100644 index 6c5f0b74d7..0000000000 --- a/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/PropertyEditors/Views/googlemaps.html +++ /dev/null @@ -1,3 +0,0 @@ -
-
-
\ No newline at end of file diff --git a/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/package.manifest b/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/package.manifest deleted file mode 100644 index de862448fe..0000000000 --- a/src/Umbraco.Web.UI/App_Plugins/GoogleMaps/package.manifest +++ /dev/null @@ -1,19 +0,0 @@ -{ - propertyEditors: [ - { - id: "0BA0F832-D759-4526-9B3E-94BBFC98F82E", - name: "Google Maps", - editor: { - view: "~/App_Plugins/GoogleMaps/PropertyEditors/Views/googlemaps.html" - } - } - ], - config: { - paths: { - 'googleMapsController': '~/App_Plugins/GoogleMaps/PropertyEditors/Js/googlemaps.controller' - } - }, - init: [ - 'googleMapsController' - ] -} \ No newline at end of file diff --git a/src/Umbraco.Web.UI/App_Plugins/MyPackage/Common/Js/MyPackage.js b/src/Umbraco.Web.UI/App_Plugins/MyPackage/Common/Js/MyPackage.js index 4c7a3a4cd3..ef0fb2ee33 100644 --- a/src/Umbraco.Web.UI/App_Plugins/MyPackage/Common/Js/MyPackage.js +++ b/src/Umbraco.Web.UI/App_Plugins/MyPackage/Common/Js/MyPackage.js @@ -1,8 +1,11 @@ 'use strict'; -define(['app'], function (app) { +(function () { + + angular.module("myPackage.directives", []); + angular.module("myPackage.controllers", []); - app.directive('valPostcode', function () { + angular.module("myPackage.directives").directive('valPostcode', function () { /// /// A custom directive to validate for postcodes @@ -51,4 +54,4 @@ define(['app'], function (app) { } }; }); -}); \ No newline at end of file +})(); \ No newline at end of file diff --git a/src/Umbraco.Web.UI/App_Plugins/MyPackage/Package.manifest b/src/Umbraco.Web.UI/App_Plugins/MyPackage/Package.manifest index f8ec9b97ba..f7fbce24d6 100644 --- a/src/Umbraco.Web.UI/App_Plugins/MyPackage/Package.manifest +++ b/src/Umbraco.Web.UI/App_Plugins/MyPackage/Package.manifest @@ -35,16 +35,8 @@ ] } } - ], - config: { - paths: { - myPackageCommon: '~/App_Plugins/MyPackage/Common/Js/MyPackage' - }, - shim: { - 'myPackageCommon': { 'exports': 'myPackageCommon' } - } - }, - init: [ - 'myPackageCommon' + ], + javascript: [ + '~/App_Plugins/MyPackage/Common/Js/MyPackage.js' ] } \ No newline at end of file diff --git a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/CsvEditor.js b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/CsvEditor.js index 607c404eb3..db076f635a 100644 --- a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/CsvEditor.js +++ b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/CsvEditor.js @@ -1,11 +1,8 @@ 'use strict'; -//requires namespaceMgr -define(['namespaceMgr'], function () { +(function() { - Umbraco.Sys.registerNamespace("MyPackage.PropertyEditors"); - - MyPackage.PropertyEditors.CsvEditor = function ($scope, $http, $filter) { + function csvEditorController($scope, $http, $filter) { var values = []; @@ -40,7 +37,7 @@ define(['namespaceMgr'], function () { //write the csv value back to the property $scope.model.value = csv.join(); }, true); - }; - -}); \ No newline at end of file + + angular.module("myPackage.controllers").controller('MyPackage.PropertyEditors.CsvEditorController', csvEditorController); +})(); \ No newline at end of file diff --git a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/FileUploadEditor.js b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/FileUploadEditor.js index cb5eb5c062..3bef4c908f 100644 --- a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/FileUploadEditor.js +++ b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/FileUploadEditor.js @@ -1,12 +1,8 @@ 'use strict'; -//requires namespaceMgr -define(['namespaceMgr'], function () { - - Umbraco.Sys.registerNamespace("MyPackage.PropertyEditors"); +(function() { + function fileUploadEditorController($scope, $element, $compile, umbImageHelper) { - MyPackage.PropertyEditors.FileUploadEditor = function ($scope, $element, $compile, umbImageHelper) { - /** Clears the file collections when content is saving (if we need to clear) or after saved */ function clearFiles() { //TODO: There should be a better way! We don't want to have to know about the parent scope @@ -23,10 +19,10 @@ define(['namespaceMgr'], function () { //for legacy data, this will not be an array, just a string so convert to an array if (!$scope.model.value.startsWith('[')) { - + //check if it ends with a common image extensions - var isImage = umbImageHelper.detectIfImageByExtension($scope.model.value); - $scope.model.value = "[{\"file\": \"" + $scope.model.value + "\",\"isImage\":" + isImage +"}]"; + var isImage = umbImageHelper.detectIfImageByExtension($scope.model.value); + $scope.model.value = "[{\"file\": \"" + $scope.model.value + "\",\"isImage\":" + isImage + "}]"; } $scope.persistedFiles = angular.fromJson($scope.model.value); @@ -35,15 +31,15 @@ define(['namespaceMgr'], function () { $scope.persistedFiles = []; } - _.each($scope.persistedFiles, function(file) { + _.each($scope.persistedFiles, function (file) { file.thumbnail = umbImageHelper.getThumbnailFromPath(file.file); }); - + $scope.clearFiles = false; //listen for clear files changes to set our model to be sent up to the server - $scope.$watch("clearFiles", function(isCleared) { + $scope.$watch("clearFiles", function (isCleared) { if (isCleared == true) { $scope.model.value = "{clearFiles: true}"; clearFiles(); @@ -52,10 +48,10 @@ define(['namespaceMgr'], function () { $scope.model.value = ""; } }); - + //listen for when a file is selected $scope.$on("filesSelected", function (event, args) { - $scope.$apply(function() { + $scope.$apply(function () { //set the parent files collection $scope.$parent.addFiles($scope.model.id, args.files); //clear the current files @@ -67,8 +63,9 @@ define(['namespaceMgr'], function () { //set clear files to false, this will reset the model too $scope.clearFiles = false; }); - }); + }); }; -}); \ No newline at end of file + angular.module("myPackage.controllers").controller('MyPackage.PropertyEditors.FileUploadEditor', fileUploadEditorController); +})(); \ No newline at end of file diff --git a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/PostcodeEditor.js b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/PostcodeEditor.js index 5ad3b3d694..6ef140eaf5 100644 --- a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/PostcodeEditor.js +++ b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/PostcodeEditor.js @@ -1,11 +1,12 @@ 'use strict'; -define(['namespaceMgr'], function () { +(function() { - Umbraco.Sys.registerNamespace("MyPackage.PropertyEditors"); - - MyPackage.PropertyEditors.PostcodeEditor = function ($scope, $http, $filter) { + function postcodeEditor($scope, $http, $filter) { //change the config json model into something usable - $scope.model.config = { country : $scope.model.config[0] }; + $scope.model.config = { country: $scope.model.config[0] }; }; -}); \ No newline at end of file + + angular.module("myPackage.controllers").controller('MyPackage.PropertyEditors.PostcodeEditor', postcodeEditor); + +})(); \ No newline at end of file diff --git a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/RegexEditor.js b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/RegexEditor.js index b76b7840e6..92839313a0 100644 --- a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/RegexEditor.js +++ b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/RegexEditor.js @@ -1,10 +1,11 @@ 'use strict'; -define(['namespaceMgr'], function () { - - Umbraco.Sys.registerNamespace("MyPackage.PropertyEditors"); +(function() { - MyPackage.PropertyEditors.RegexEditor = function ($scope, $http, $filter) { + function regexEditor($scope, $http, $filter) { var asdf = ""; }; -}); \ No newline at end of file + + angular.module("myPackage.controllers").controller('MyPackage.PropertyEditors.RegexEditor', regexEditor); + +})(); \ No newline at end of file diff --git a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Views/CsvEditor.html b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Views/CsvEditor.html index 26cc63e9fa..49ce3a94cf 100644 --- a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Views/CsvEditor.html +++ b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Views/CsvEditor.html @@ -1,4 +1,4 @@ -
+
diff --git a/src/Umbraco.Web.UI/App_Plugins/SimpleEditor/PropertyEditors/js/simpleeditor.js b/src/Umbraco.Web.UI/App_Plugins/SimpleEditor/PropertyEditors/js/simpleeditor.js index e14b592388..bbc0c1147e 100644 --- a/src/Umbraco.Web.UI/App_Plugins/SimpleEditor/PropertyEditors/js/simpleeditor.js +++ b/src/Umbraco.Web.UI/App_Plugins/SimpleEditor/PropertyEditors/js/simpleeditor.js @@ -1,10 +1,8 @@ -define(['app', 'angular'], function (app, angular) { +(function () { -angular.module("umbraco") -.controller("Umbraco.Editors.SimpleEditorController", - function ($rootScope, $scope, notificationsService, dialogService) { - alert("wat"); - }); + angular.module("umbraco").controller("Umbraco.Editors.SimpleEditorController", + function ($rootScope, $scope, notificationsService, dialogService) { + alert("wat"); + }); - return angular; -}); \ No newline at end of file +})(); \ No newline at end of file diff --git a/src/Umbraco.Web.UI/App_Plugins/SimpleEditor/package.manifest b/src/Umbraco.Web.UI/App_Plugins/SimpleEditor/package.manifest index 5e812ab1a4..e1047ffe80 100644 --- a/src/Umbraco.Web.UI/App_Plugins/SimpleEditor/package.manifest +++ b/src/Umbraco.Web.UI/App_Plugins/SimpleEditor/package.manifest @@ -8,12 +8,7 @@ } } ], - config: { - paths: { - 'simpleController': '~/App_Plugins/SimpleEditor/PropertyEditors/Js/SimpleEditor' - } - }, - init: [ - 'simpleController' + javascript: [ + '~/App_Plugins/SimpleEditor/PropertyEditors/Js/SimpleEditor.js' ] } \ No newline at end of file diff --git a/src/Umbraco.Web.UI/umbraco/Views/Default.cshtml b/src/Umbraco.Web.UI/umbraco/Views/Default.cshtml index 24b4234b21..367bed3bda 100644 --- a/src/Umbraco.Web.UI/umbraco/Views/Default.cshtml +++ b/src/Umbraco.Web.UI/umbraco/Views/Default.cshtml @@ -50,29 +50,24 @@ - +
- {{ui | json}}
- - - + + + + + - @*We cannot use the data-main attribute above because we need to load in the application - via a server side JavaScript request, so we just request it after requirejs*@ - - diff --git a/src/Umbraco.Web.UI/umbraco/Views/common/dashboard.html b/src/Umbraco.Web.UI/umbraco/Views/common/dashboard.html index 2ea0896e96..dd2aaa3a5e 100644 --- a/src/Umbraco.Web.UI/umbraco/Views/common/dashboard.html +++ b/src/Umbraco.Web.UI/umbraco/Views/common/dashboard.html @@ -9,7 +9,7 @@
- +
diff --git a/src/Umbraco.Web.UI/umbraco/js/app_dev.js b/src/Umbraco.Web.UI/umbraco/js/app_dev.js index d0a45d9af8..2d13026719 100644 --- a/src/Umbraco.Web.UI/umbraco/js/app_dev.js +++ b/src/Umbraco.Web.UI/umbraco/js/app_dev.js @@ -1,16 +1,7 @@ -/*! umbraco - v0.0.1-SNAPSHOT - 2013-06-18 - * http://umbraco.github.io/Belle - * Copyright (c) 2013 Per Ploug, Anders Stenteberg & Shannon Deminick; - * Licensed MIT - */ -'use strict'; -define(['angular'], function (angular) { var app = angular.module('umbraco', [ - 'umbraco.filters', - 'umbraco.directives', - 'umbraco.mocks.resources', - 'umbraco.services' -]); - -return app; -}); \ No newline at end of file + 'umbraco.filters', + 'umbraco.directives', + 'umbraco.mocks.resources', + 'umbraco.services', + 'umbraco.security' +]); \ No newline at end of file diff --git a/src/Umbraco.Web.UI/umbraco/js/loader.js b/src/Umbraco.Web.UI/umbraco/js/loader.js new file mode 100644 index 0000000000..6875f70a4d --- /dev/null +++ b/src/Umbraco.Web.UI/umbraco/js/loader.js @@ -0,0 +1,28 @@ +yepnope({ + + load: [ + 'lib/jquery/jquery-1.8.2.min.js', + 'lib/jquery/jquery.cookie.js', + 'lib/angular/angular.min.js', + 'lib/bootstrap/js/bootstrap.js', + 'lib/underscore/underscore.js', + 'lib/umbraco/Extensions.js', + + 'js/app_dev.js', + + 'js/umbraco.mocks.js', + 'js/umbraco.directives.js', + 'js/umbraco.filters.js', + 'js/umbraco.services.js', + 'js/umbraco.security.js', + 'js/umbraco.controllers.js', + 'js/routes.js' + ], + + complete: function () { + jQuery(document).ready(function () { + angular.bootstrap(document, ['umbraco']); + }); + + } +}); \ No newline at end of file diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index 2ea7b641b1..1f6c528b0b 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -32,8 +32,8 @@ namespace Umbraco.Web.Editors { var plugins = new DirectoryInfo(Server.MapPath("~/App_Plugins")); var parser = new ManifestParser(plugins); - var requireJs = new RequireJsInit(parser); - var result = requireJs.GetJavascriptInitialization(RequireJsInit.GetDefaultConfig(), RequireJsInit.GetDefaultInitialization()); + var requireJs = new JsInitialization(parser); + var result = requireJs.GetJavascriptInitialization(JsInitialization.GetDefaultInitialization()); return JavaScript(result); } diff --git a/src/Umbraco.Web/UI/JavaScript/RequireJsInit.cs b/src/Umbraco.Web/UI/JavaScript/JsInitialization.cs similarity index 76% rename from src/Umbraco.Web/UI/JavaScript/RequireJsInit.cs rename to src/Umbraco.Web/UI/JavaScript/JsInitialization.cs index 075d4d035c..a05d274474 100644 --- a/src/Umbraco.Web/UI/JavaScript/RequireJsInit.cs +++ b/src/Umbraco.Web/UI/JavaScript/JsInitialization.cs @@ -1,92 +1,80 @@ -using System.IO; -using System.Text.RegularExpressions; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Umbraco.Core.Manifest; - -namespace Umbraco.Web.UI.JavaScript -{ - /// - /// Reads from all defined manifests and ensures that any of their initialization is output with the - /// main Umbraco initialization output. - /// - internal class RequireJsInit - { - private readonly ManifestParser _parser; - - public RequireJsInit(ManifestParser parser) - { - _parser = parser; - } - - //used to strip comments - internal static readonly Regex Comments = new Regex("(/\\*.*\\*/)", RegexOptions.Compiled); - //used for dealing with js functions inside of json (which is not a supported json syntax) - private const string PrefixJavaScriptObject = "@@@@"; - private static readonly Regex JsFunctionParser = new Regex(string.Format("(\"{0}(.*?)\")+", PrefixJavaScriptObject), - RegexOptions.Multiline - | RegexOptions.CultureInvariant - | RegexOptions.Compiled); - //used to replace the tokens in the js main - private static readonly Regex Token = new Regex("(\"##\\w+?##\")", RegexOptions.Compiled); - - /// - /// Processes all found manifest files and outputs the main.js file containing all plugin manifests - /// - public string GetJavascriptInitialization(JObject umbracoConfig, JArray umbracoInit) - { - foreach (var m in _parser.GetManifests()) - { - ManifestParser.MergeJObjects(umbracoConfig, m.JavaScriptConfig, true); - ManifestParser.MergeJArrays(umbracoInit, m.JavaScriptInitialize); - } - - return ParseMain(umbracoConfig.ToString(), umbracoInit.ToString()); - } - - /// - /// Returns the default config as a JObject - /// - /// - internal static JObject GetDefaultConfig() - { - var config = Resources.RequireJsConfig; - var jObj = JsonConvert.DeserializeObject(config); - return jObj; - } - - /// - /// Returns the default config as a JArray - /// - /// - internal static JArray GetDefaultInitialization() - { - var init = Resources.RequireJsInitialize; - var jArr = JsonConvert.DeserializeObject(init); - return jArr; - } - - /// - /// Parses the JsResources.Main and replaces the replacement tokens accordingly. - /// - /// - /// - internal static string ParseMain(params string[] replacements) - { - var count = 0; - - return Token.Replace(Resources.Main, match => - { - var replaced = replacements[count]; - - //we need to cater for the special syntax when we have js function() objects contained in the json - var jsFunctionParsed = JsFunctionParser.Replace(replaced, "$2"); - - count++; - - return jsFunctionParsed; - }); - } - - } -} +using System.IO; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Umbraco.Core.Manifest; + +namespace Umbraco.Web.UI.JavaScript +{ + /// + /// Reads from all defined manifests and ensures that any of their initialization is output with the + /// main Umbraco initialization output. + /// + internal class JsInitialization + { + private readonly ManifestParser _parser; + + public JsInitialization(ManifestParser parser) + { + _parser = parser; + } + + //used to strip comments + internal static readonly Regex Comments = new Regex("(/\\*.*\\*/)", RegexOptions.Compiled); + //used for dealing with js functions inside of json (which is not a supported json syntax) + private const string PrefixJavaScriptObject = "@@@@"; + private static readonly Regex JsFunctionParser = new Regex(string.Format("(\"{0}(.*?)\")+", PrefixJavaScriptObject), + RegexOptions.Multiline + | RegexOptions.CultureInvariant + | RegexOptions.Compiled); + //used to replace the tokens in the js main + private static readonly Regex Token = new Regex("(\"##\\w+?##\")", RegexOptions.Compiled); + + /// + /// Processes all found manifest files and outputs the main.js file containing all plugin manifests + /// + public string GetJavascriptInitialization(JArray umbracoInit) + { + foreach (var m in _parser.GetManifests()) + { + ManifestParser.MergeJArrays(umbracoInit, m.JavaScriptInitialize); + } + + return ParseMain(umbracoInit.ToString()); + } + + /// + /// Returns the default config as a JArray + /// + /// + internal static JArray GetDefaultInitialization() + { + var init = Resources.JsInitialize; + var jArr = JsonConvert.DeserializeObject(init); + return jArr; + } + + /// + /// Parses the JsResources.Main and replaces the replacement tokens accordingly. + /// + /// + /// + internal static string ParseMain(params string[] replacements) + { + var count = 0; + + return Token.Replace(Resources.Main, match => + { + var replaced = replacements[count]; + + //we need to cater for the special syntax when we have js function() objects contained in the json + var jsFunctionParsed = JsFunctionParser.Replace(replaced, "$2"); + + count++; + + return jsFunctionParsed; + }); + } + + } +} diff --git a/src/Umbraco.Web/UI/JavaScript/JsInitialize.js b/src/Umbraco.Web/UI/JavaScript/JsInitialize.js new file mode 100644 index 0000000000..4fe8a4fdd2 --- /dev/null +++ b/src/Umbraco.Web/UI/JavaScript/JsInitialize.js @@ -0,0 +1,18 @@ +[ + 'lib/jquery/jquery-1.8.2.min.js', + 'lib/jquery/jquery.cookie.js', + 'lib/angular/angular.min.js', + 'lib/bootstrap/js/bootstrap.js', + 'lib/underscore/underscore.js', + 'lib/umbraco/Extensions.js', + + 'js/app.js', + + 'js/umbraco.resources.js', + 'js/umbraco.directives.js', + 'js/umbraco.filters.js', + 'js/umbraco.services.js', + 'js/umbraco.security.js', + 'js/umbraco.controllers.js', + 'js/routes.js' +] \ No newline at end of file diff --git a/src/Umbraco.Web/UI/JavaScript/Main.js b/src/Umbraco.Web/UI/JavaScript/Main.js index d5340cd8d5..3dcd791733 100644 --- a/src/Umbraco.Web/UI/JavaScript/Main.js +++ b/src/Umbraco.Web/UI/JavaScript/Main.js @@ -1,13 +1,11 @@ -require.config("##RequireJsConfig##"); +yepnope({ -require("##RequireJsInitialize##", function (angular, app, jQuery) { + load: "##JsInitialize##", - //This function will be called when all the dependencies - //listed above are loaded. Note that this function could - //be called before the page is loaded. - //This callback is optional. + complete: function () { + jQuery(document).ready(function () { + angular.bootstrap(document, ['umbraco']); + }); - jQuery(document).ready(function () { - angular.bootstrap(document, ['umbraco']); - }); + } }); \ No newline at end of file diff --git a/src/Umbraco.Web/UI/JavaScript/RequireJsConfig.js b/src/Umbraco.Web/UI/JavaScript/RequireJsConfig.js deleted file mode 100644 index 81c2662fc6..0000000000 --- a/src/Umbraco.Web/UI/JavaScript/RequireJsConfig.js +++ /dev/null @@ -1,45 +0,0 @@ -{ - baseUrl: "js", - waitSeconds: 120, - paths: { - jquery: '../lib/jquery/jquery-1.8.2.min', - jqueryCookie: '../lib/jquery/jquery.cookie', - umbracoExtensions: '../lib/umbraco/extensions', - bootstrap: '../lib/bootstrap/js/bootstrap', - underscore: '../lib/underscore/underscore', - angular: '../lib/angular/angular.min', - angularResource: '../lib/angular/angular-resource', - - codemirror: '../lib/codemirror/js/lib/codemirror', - codemirrorJs: '../lib/codemirror/js/mode/javascript/javascript', - codemirrorCss: '../lib/codemirror/js/mode/css/css', - codemirrorXml: '../lib/codemirror/js/mode/xml/xml', - codemirrorHtml: '../lib/codemirror/js/mode/htmlmixed/htmlmixed', - - tinymce: '../lib/tinymce/tinymce.min', - text: '../lib/require/text', - async: '../lib/require/async', - css: '../lib/require/css', - namespaceMgr: '../lib/Umbraco/NamespaceManager', - }, - shim: { - 'umbracoExtensions' : {'exports' : 'umbracoExtensions'}, - 'angular' : {'exports' : 'angular'}, - 'angular-resource': { deps: ['angular'] }, - 'bootstrap': { deps: ['jquery'] }, - 'jqueryCookie': { deps: ['jquery'] }, - 'underscore': {exports: '_'}, - 'codemirror': {exports: 'CodeMirror'}, - 'codemirrorJs':{deps:['codemirror']}, - 'codemirrorCss':{deps:['codemirror']}, - 'codemirrorXml':{deps:['codemirror']}, - 'codemirrorHtml':{deps:['codemirrorXml','codemirrorCss','codemirrorJs'], exports: 'mixedMode'}, - /* THIS IS SPECIAL SYNTAX BECAUSE JS functions ARE NOT STANDARD JSON SO THEY CANNOT BE SERIALIZED */ - /* SO BEFORE WE RENDER WE'LL ENSURE THAT IT'S FORM */ - 'tinymce': "@@@@{exports: 'tinyMCE', init: function () { this.tinymce.DOM.events.domLoaded = true; return this.tinymce; } }" - }, - priority: [ - "angular" - ], - urlArgs: 'v=1.1' -} \ No newline at end of file diff --git a/src/Umbraco.Web/UI/JavaScript/RequireJsInitialize.js b/src/Umbraco.Web/UI/JavaScript/RequireJsInitialize.js deleted file mode 100644 index 9073e741b2..0000000000 --- a/src/Umbraco.Web/UI/JavaScript/RequireJsInitialize.js +++ /dev/null @@ -1,17 +0,0 @@ -[ - 'angular', - 'app', - 'jquery', - 'jqueryCookie', - 'umbracoExtensions', - 'bootstrap', - 'umbraco.resources', - 'umbraco.directives', - 'umbraco.filters', - 'umbraco.services', - 'umbraco.controllers', - 'sample.propertyeditor.controller', - 'sampletwo.propertyeditor.controller', - 'routes', - 'namespaceMgr' -] \ No newline at end of file diff --git a/src/Umbraco.Web/UI/JavaScript/Resources.Designer.cs b/src/Umbraco.Web/UI/JavaScript/Resources.Designer.cs index 19fef4ffa7..e10fc651a0 100644 --- a/src/Umbraco.Web/UI/JavaScript/Resources.Designer.cs +++ b/src/Umbraco.Web/UI/JavaScript/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18034 +// Runtime Version:4.0.30319.18046 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -61,18 +61,42 @@ namespace Umbraco.Web.UI.JavaScript { } /// - /// Looks up a localized string similar to require.config("##RequireJsConfig##"); + /// Looks up a localized string similar to [ + /// 'lib/jquery/jquery-1.8.2.min.js', + /// 'lib/jquery/jquery.cookie.js', + /// 'lib/angular/angular.min.js', + /// 'lib/bootstrap/js/bootstrap.js', + /// 'lib/underscore/underscore.js', + /// 'lib/umbraco/Extensions.js', /// - ///require("##RequireJsInitialize##", function (angular, myApp) { + /// 'js/app.js', /// - /// //This function will be called when all the dependencies - /// //listed above are loaded. Note that this function could - /// //be called before the page is loaded. - /// //This callback is optional. + /// 'js/umbraco.resources.js', + /// 'js/umbraco.directives.js', + /// 'js/umbraco.filters.js', + /// 'js/umbraco.services.js', + /// 'js/umbraco.security.js', + /// 'js/umbraco.controllers.js', + /// 'js/routes.js' + ///]. + /// + internal static string JsInitialize { + get { + return ResourceManager.GetString("JsInitialize", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to yepnope({ /// - /// jQuery(document).ready(function() { - /// angular.bootstrap(document, ['myApp']); - /// }); + /// load: "##JsInitialize##", + /// + /// complete: function () { + /// jQuery(document).ready(function () { + /// angular.bootstrap(document, ['umbraco']); + /// }); + /// + /// } ///});. /// internal static string Main { @@ -81,43 +105,6 @@ namespace Umbraco.Web.UI.JavaScript { } } - /// - /// Looks up a localized string similar to { - /// - /// /*NOTE: This is actually /Belle/js because we are loading in requireJs from /Belle already*/ - /// baseUrl: 'js', - /// - /// waitSeconds: 120, - /// paths: { - /// jquery: '../lib/jquery/jquery-1.8.2.min', - /// jqueryCookie: '../lib/jquery/jquery.cookie', - /// bootstrap: '../lib/bootstrap/js/bootstrap', - /// underscore: '../lib/underscore/underscore', - /// angular: '../lib/angular/angular', - /// angularResource: '../lib/angular/angular-resource', - /// statemanager: '../ [rest of string was truncated]";. - /// - internal static string RequireJsConfig { - get { - return ResourceManager.GetString("RequireJsConfig", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to [ - /// 'angular', - /// 'jquery', - /// 'underscore', - /// 'namespaceMgr', - /// 'myApp' - ///]. - /// - internal static string RequireJsInitialize { - get { - return ResourceManager.GetString("RequireJsInitialize", resourceCulture); - } - } - /// /// Looks up a localized string similar to //TODO: This would be nicer as an angular module so it can be injected into stuff... that'd be heaps nicer, but ///// how to do that when this is not a regular JS file, it is a server side JS file and RequireJS seems to only want diff --git a/src/Umbraco.Web/UI/JavaScript/Resources.resx b/src/Umbraco.Web/UI/JavaScript/Resources.resx index fd7f5c7c0f..a3e54b6805 100644 --- a/src/Umbraco.Web/UI/JavaScript/Resources.resx +++ b/src/Umbraco.Web/UI/JavaScript/Resources.resx @@ -118,15 +118,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + jsinitialize.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + Main.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - requirejsconfig.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - - - requirejsinitialize.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - servervariables.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 93c9649890..4d3e25bd03 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -328,12 +328,7 @@ - - - True - True - Resources.resx - + @@ -416,6 +411,11 @@ + + True + True + Resources.resx + @@ -1844,8 +1844,7 @@ Component - - +