Skip to content

Instantly share code, notes, and snippets.

@astehlik
Created March 24, 2016 10:30
Show Gist options
  • Save astehlik/515dedcb8eba1ed996e7 to your computer and use it in GitHub Desktop.
Save astehlik/515dedcb8eba1ed996e7 to your computer and use it in GitHub Desktop.
diff --git a/src/main/resources/META-INF/resources/jsp/application/app_form.jsp b/src/main/resources/META-INF/resources/jsp/application/app_form.jsp
index ba2fbff..d5730f7 100644
--- a/src/main/resources/META-INF/resources/jsp/application/app_form.jsp
+++ b/src/main/resources/META-INF/resources/jsp/application/app_form.jsp
@@ -14,6 +14,41 @@
<head>
<uv:head/>
+
+ <script type="text/javascript">
+ /**
+ * @param {string|{}} data
+ * @param {string} [data.src]
+ * @param {string} [data.fallback]
+ * @return {$.Deferred}
+ */
+ function addScript(data) {
+
+ var deferred = $.Deferred();
+ var isFallback = typeof data === 'string';
+
+ var script = document.createElement('script');
+ script.src = isFallback ? data : data.src;
+ script.type = 'text/javascript';
+
+ script.onload = function() {
+ deferred.resolve();
+ };
+
+ script.onerror = function() {
+ if (isFallback) {
+ deferred.reject();
+ } else {
+ addScript(data.fallback).then(deferred.resolve);
+ }
+ };
+
+ document.getElementsByTagName('head')[0].appendChild(script);
+
+ return deferred.promise();
+ }
+ </script>
+
<link rel="stylesheet" type="text/css" href="<spring:url value='/lib/jquery/css/ui-lightness/timepicker.css' />" />
<script src="<spring:url value='/lib/jquery/js/timepicker.js' />" type="text/javascript" ></script>
@@ -381,6 +416,31 @@
</div>
+<script>
+ $(function() {
+
+ var datepickerLocale = "${pageContext.response.locale.language}";
+
+ function addMomentScript() {
+ return addScript({
+ src: '//cdnjs.cloudflare.com/ajax/libs/moment.js/2.5.1/moment.min.js',
+ fallback: '<spring:url value='/lib/moment/moment.min.js' />'
+ });
+ }
+
+ // dependently of the locale a specific language file is fetched for momentjs
+ // fallback is a german language file
+ function addMomentLangScript() {
+ return addScript({
+ src: '//cdnjs.cloudflare.com/ajax/libs/moment.js/2.5.1/lang/' + datepickerLocale + '.js',
+ fallback: '<spring:url value='/lib/moment/moment.lang.de.js' />'
+ });
+ }
+
+ addMomentScript().then(addMomentLangScript);
+ });
+</script>
+
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment