Skip to content

Instantly share code, notes, and snippets.

@myabc
Created February 6, 2015 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myabc/7506ad8b27eb35a6a019 to your computer and use it in GitHub Desktop.
Save myabc/7506ad8b27eb35a6a019 to your computer and use it in GitHub Desktop.
diff --git a/frontend/app/ui_components/has-preview-directive.js b/frontend/app/ui_components/has-preview-directive.js
index e6ac2ee..e304e62 100644
--- a/frontend/app/ui_components/has-preview-directive.js
+++ b/frontend/app/ui_components/has-preview-directive.js
@@ -26,7 +26,15 @@
// See doc/COPYRIGHT.rdoc for more details.
//++
-module.exports = function() {
+module.exports = function($http, $location, $anchorScroll) {
+
+ var previewOptions = {
+ headers: {
+ 'Accept': 'text/html',
+ 'Content-Type': 'application/x-www-form-urlencoded'
+ }
+ };
+
return {
restrict: 'A',
scope: {},
@@ -35,21 +43,14 @@ module.exports = function() {
var id = attrs.id;
var target = attrs.previewArea ||  '#preview';
+ var form = angular.element('#' + id.replace(/-preview/, ''));
+ var data = form.serialize().replace('_method=put&', '');
+
element.on('click', function() {
- jQuery.ajax({
- url: href,
- type: 'POST',
- data: angular.element('#' + id.replace(/-preview/, '')).serialize()
- .replace(
- '_method=put&', ''),
- success: function(data) {
- angular.element(target).html(data);
- angular.element('html, body').animate({
- scrollTop: angular.element('#preview').offset()
- .top
- },
- 'slow');
- }
+ $http.post(href, data, previewOptions).success(function(data) {
+ angular.element(target).html(data);
+ $location.hash(target.replace(/^\#/, ''));
+ $anchorScroll();
});
return false;
diff --git a/frontend/app/ui_components/index.js b/frontend/app/ui_components/index.js
index 5d72725..837843d 100644
--- a/frontend/app/ui_components/index.js
+++ b/frontend/app/ui_components/index.js
@@ -68,6 +68,9 @@ angular.module('openproject.uiComponents')
require('./has-dropdown-menu-directive')
])
.directive('hasPreview', [
+ '$http',
+ '$location',
+ '$anchorScroll',
require('./has-preview-directive')
])
.service('I18n', [require('./i18n')])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment