Skip to content

Commit

Permalink
content save service created
Browse files Browse the repository at this point in the history
  • Loading branch information
wishabhilash committed Jul 2, 2016
1 parent 578eca0 commit 21c9446
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require('angular');
require('angular-ui-router');
require('./controllers');
require('./directives');
require('./services');

require('angular-animate');
require('angular-aria');
Expand All @@ -16,7 +17,8 @@ var app = angular.module('poem', [
'poem.controller',
'ngMaterial',
'ngMessages',
'poem.directives'
'poem.directives',
'poem.services'
]).run(function() {
// CHECK TOKEN REFRESH AND SESSION EXPIRE
});
Expand Down
30 changes: 26 additions & 4 deletions src/js/directives/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,37 @@ let editorControl = function() {
// }

let editorContent = function() {
let controller = function($scope) {
let controller = function($scope, $timeout, contentService) {
"ngInject";
let editorContent = this;
editorContent.contentSaved = true;
editorContent.lastSavedContent = '';
editorContent.saveTimeoutPromise = null;

editorContent.saveContent = function(content) {
if (editorContent.lastSavedContent != content) {
editorContent.lastSavedContent = content;
editorContent.contentSaved = false;
}



if (!editorContent.contentSaved) {
$timeout.cancel(editorContent.saveTimeoutPromise);
editorContent.saveTimeoutPromise = $timeout(
contentService.save,
3000,
false,
content
);
editorContent.contentSaved = true;
}
}
}

let link = function(scope, element, attrs) {
element.on('keyup', function($event) {
scope.editorControl.toggleToolbarOnTextSelect();
let newContent = element.html();
scope.editorContent.saveContent(newContent);
});

element.on('paste', function($event) {
Expand All @@ -167,7 +187,9 @@ let editorContent = function() {

return {
restrict: 'A',
link: link
link: link,
controller: controller,
controllerAs: 'editorContent'
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/js/services/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";

module.exports = function() {
"ngInject";

this.save = function(content) {
console.log(content);
}

}
6 changes: 6 additions & 0 deletions src/js/services/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

var module = 'poem.services';

angular.module(module, [])
.service('contentService', require('./content'));

0 comments on commit 21c9446

Please sign in to comment.