Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edit mode on single post template #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 74 additions & 34 deletions assets/js/angular-app.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
wpAng = typeof wpAng === 'undefined' ? {} : wpAng;

wpAng.init = function(){

wpAng.app = angular.module('wpAngularTheme',['ui.router','ngResource','ui.tinymce'])

//FILTERS
.filter('to_trusted',['$sce',function($sce){
return function(text){
return $sce.trustAsHtml(text);
};
};
}])

//RUNFUNC
.run(function($rootScope){
.run(function($rootScope){
$rootScope.dir = ajaxInfo.template_directory;
$rootScope.tinymceOptions = {
skin:'lightgray',
height:300
};

$rootScope.is_admin = ajaxInfo.is_admin;
})

//ROUTES
.config(function($stateProvider,$urlRouterProvider){
$urlRouterProvider.otherwise('/');
Expand All @@ -37,7 +32,7 @@ wpAng.init = function(){
templateUrl:ajaxInfo.template_directory+'single.html'
})
})

//FACTORIES
.factory('Posts',function($resource){
return $resource(ajaxInfo.api_url+'posts/:ID',{
Expand Down Expand Up @@ -87,17 +82,19 @@ wpAng.init = function(){
id:'@id'
});
})

//CONTROLLERS
.controller('listView',['$scope','Posts',function($scope,Posts){

.controller('listView',['$scope','Posts', '$stateParams','PostsBySlug','Comments', function($scope,Posts,$stateParams,PostsBySlug,Comments){


$scope.refreshPosts = function(){
Posts.query(function(res){
$scope.posts = res;
});
};

$scope.refreshPosts();

//EDITPOST
$scope.openPost = {}
$scope.editPost = function(post){
Expand All @@ -108,7 +105,7 @@ wpAng.init = function(){
tinymce.activeEditor.setContent($scope.openPost.content.rendered);
},100);
};

//DELETEPOSTFUNCTION
$scope.deletePost = function(index,post){
if(post.id){
Expand All @@ -119,9 +116,10 @@ wpAng.init = function(){
}
}
};

//SAVEPOSTFUNCTION
$scope.savePost = function(){
$scope.savePost = function(){
console.log($scope.openPost);
if($scope.openPost.newPost){
$scope.openPost.title = $scope.openPost.title.rendered;
$scope.openPost.content = $scope.openPost.content.rendered;
Expand All @@ -140,45 +138,51 @@ wpAng.init = function(){
});
}
};

//ADDNEWPOST
$scope.addPost = function(){
$scope.openPost = {
newPost:true,
status:'publish'
}
}

//CLEARFORMFUNCTION
$scope.clear = function(){
$scope.$root.openPost = false;
jQuery('#save').modal('hide');
};
//SAVEMODALOPEN/COSE


//SAVEMODALOPEN/COSE
$scope.openSaveModal = function(){
jQuery('#save').modal('show');
}

$scope.closeSaveModal = function(){
jQuery('#save').modal('hide');
}

//DATEFUNCTION
$scope.datify = function(date){
$scope.date = newDate(date);
return $scope.date.getDate()+'/'+$scope.date.getMonth()+'/'+$scope.date.getYear();
};

}])

.controller('singleView',['$scope','$stateParams','PostsBySlug','Comments',function($scope,$stateParams,PostsBySlug,Comments){


.controller('singleView',['$scope','$stateParams','PostsBySlug','Comments','Posts',function($scope,$stateParams,PostsBySlug,Comments, Posts){

$scope.post = {};
$scope.virgin = {};

jQuery( "#title" ).prop( "disabled", true );

PostsBySlug.get($stateParams,function(res){
$scope.post = res.post;
angular.copy(res.post, $scope.virgin)
});

$scope.savecomment = function(){
$scope.openComment.post = $scope.post.ID;
Comments.save($scope.openComment,function(res){
Expand All @@ -191,9 +195,45 @@ wpAng.init = function(){
}
});
}


$scope.tinymceedit = function(){

//highlight fields
jQuery('.textblock').addClass('tinymceedit');
jQuery( "#title" ).prop( "disabled", false );

// initialise text editor
// work with post content only. title is input field
tinyMCE.init({
selector: 'div.tinymceedit',
theme: 'inlite',
plugins: 'image table link paste contextmenu textpattern autolink',
insert_toolbar: 'quickimage quicktable',
selection_toolbar: 'bold italic | quicklink h2 h3 blockquote',
inline: true,
paste_data_images: true,
// language:"ru"
});
};

$scope.tinymcesave = function(){

// remove text editor
tinymce.remove();
// kill highlighted blocks
jQuery('#title').prop( "disabled", true );
jQuery('.tinymceedit').removeClass('tinymceedit');

// form object to update on server
$scope.post.newPost = false;
$scope.post.title = $scope.post.post_title;
$scope.post.content = jQuery('#textblock').html();

// update :)
Posts.update({ID:$scope.post.ID}, $scope.post, function(res){
});
}
}])

};

wpAng.init();
wpAng.init();
48 changes: 36 additions & 12 deletions assets/scss/_more-style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ body{
}

a{

}
h1,h2,h3,h4,h5,h6{
margin:0;
Expand All @@ -45,7 +45,7 @@ h1,h2,h3,h4,h5,h6{
header{
padding:20px 0;
color:#FFF;

a{
color:#e7e7e7;
text-decoration: none;
Expand All @@ -62,7 +62,7 @@ header{
text-decoration: none;
}
}
}
}
span{
display:block;
font-size:14px;
Expand All @@ -74,7 +74,7 @@ nav{
margin:0;
padding:0;
list-style: none;

li{
display:inline-block;
a{
Expand Down Expand Up @@ -104,11 +104,34 @@ nav{
@include box-shadow(0,0,20px,rgba(0,0,0,0.4));
padding:20px 0;
background: #FFF;

/** single edit mode **/
.single{
.tinymceedit {
border: solid 2px #ddd;
}
.h1{
text-align: center;
}
.edit {
position: absolute;
left: 55%;
top: -20%;
}
#title {
width: 100%;

&:disabled {
background-color: transparent;
border-color: transparent;
}
}
}
}
/** PROJECTS ROW **/
article.projects{
padding:10px 0;

span.date{
display:block;
font-size:14px;
Expand All @@ -117,13 +140,13 @@ article.projects{
}
a{
line-height:20px;

&.title{
color:#05057c;
display:block;
font-size:20px;
}

}
p{
padding-right:20px;
Expand All @@ -137,7 +160,7 @@ article.projects{
/** SAVE MODAL **/
div#save{
padding:20px;

form{
width:100%;
input,textarea, button{
Expand All @@ -159,7 +182,7 @@ div#save{
display:block;
margin:0 auto;
position: relative;

table{
width:100%;
}
Expand All @@ -171,7 +194,7 @@ div.sidebar{
section{
margin-bottom:40px;
padding:10px 0;

&:first-child{
padding-top:0;
}
Expand Down Expand Up @@ -209,5 +232,6 @@ footer{
padding:20px 0;
color:#FFF;
@include gradient-bg();

}

}

5 changes: 3 additions & 2 deletions form.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<form ng-submit="savePost()" ng-show="openPost">
<input type="text" ng-model="openPost.title.rendered"/>
<br/>
<textarea ng-model="openPost.content.rendered" id="editor" class="editor" ui-tinymce="tinymceOptions"></textarea><Br/>
<div ng-model="openPost.content.rendered" id="editor" class="editor" ui-tinymce="tinymceOptions"></div>
<br/>
<input type="submit" value="SAVE" />
<button type="button" ng-click="clear()">CLEAR</button>
</form>
Expand All @@ -15,4 +16,4 @@
</div>
</div>
</div>
</div>
</div>
Loading