Skip to content

Commit

Permalink
Flyttat JS/CSS
Browse files Browse the repository at this point in the history
Lagt till import av filer
Lagt till ajax anrop för att importera filer
Hämtning av post_id för redan importerade filer
  • Loading branch information
rickard2 committed Jun 5, 2012
1 parent 243bfe4 commit 3476250
Show file tree
Hide file tree
Showing 4 changed files with 856 additions and 12 deletions.
13 changes: 13 additions & 0 deletions pp-bilder/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pp-bilder-container {
display: none;
}

#pp-bilder {
padding: 20px;
}

#pp-bilder img {
border: solid 1px #ccc;
margin: 10px;
cursor: pointer;
}
52 changes: 52 additions & 0 deletions pp-bilder/js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
(function($){

var PPBilder = {

init: function() {
$(document).on('click', '#pp-bilder img', this.clickHandler);
},

clickHandler: function() {
var $this = $(this),
filename = $this.data('filename'),
post_id = $this.data('post-id');

if ( !post_id && !filename ) {
PPBilder.showError();
return;
}

if ( filename ) {
var jqxhr = PPBilder.importImage( filename );

jqxhr.done(function(data) {
/[0-9]+/.test(data) ?
PPBilder.selectImage(data) :
PPBilder.showError();
});
} else {
PPBilder.selectImage(post_id);
}
},

importImage: function(filename) {

//noinspection JSUnresolvedVariable
return $.post(ajaxurl, {
action:'pp_bilder_import_image',
filename:filename
});
},

selectImage: function(post_id) {
console.log('todo: implement selectImage');
},

showError: function() {
console.log('todo: implement showError');
}
};

PPBilder.init();

}(jQuery));
Loading

0 comments on commit 3476250

Please sign in to comment.