Permalink
Browse files

move js to cs

  • Loading branch information...
1 parent d3d5bf2 commit e2101157d1a8de3efd6a9cfd9da5bcf51cd5a0b3 @benbalter committed Dec 29, 2012
Showing with 234 additions and 128 deletions.
  1. +104 −0 js/admin/wp_resume.dev.coffee
  2. +128 −122 js/admin/wp_resume.dev.js
  3. +2 −6 js/admin/wp_resume.js
@@ -0,0 +1,104 @@
+class WP_Resume
+
+ constructor: ->
+ switch pagenow
+
+ # Options Page
+ when "wp_resume_position_page_wp_resume_options"
+ jQuery("#wp_resume_help, #wp_resume_clearfix, #multiple, .underHood").hide()
+ jQuery("#wp_resume_help_toggle").click @toggleHelp
+ jQuery("#toggleMultiple").click @toggleMultiple
+ jQuery("#toggleHood").click @toggleHood
+ jQuery("#user").change jQuery(".button-primary").click
+ jQuery("#add_contact_field").click @addContactField
+ jQuery(".button-primary").click @submitOptions
+ @addContactField()
+ @makeSortable()
+
+ # Edit Position Page
+ when "wp_resume_position"
+ jQuery("#publish").click @validatePosition
+ @addTaxonomyBoxEvents taxonomy for taxonomy in ["wp_resume_section", "wp_resume_organization"]
+
+ # Edit Organization Page
+ when "edit-wp_resume_organization"
+ jQuery("#parent, #tag-slug").parent().hide()
+ jQuery("#tag-name").siblings("p").text wp_resume.orgName
+ jQuery("#tag-description").attr("rows", "1").siblings("label").text("Location").siblings("p").text wp_resume.orgLoc
+
+ # Edit Section Page
+ when "edit-wp_resume_section"
+ jQuery("#parent").parent().hide()
+ jQuery("#tag-description, #tag-slug").parent().hide()
+
+ toggleHelp: ->
+ jQuery("#wp_resume_help, #wp_resume_clearfix").toggle "fast"
+ if jQuery(this).text() is wp_resume.more
+ jQuery(this).text wp_resume.less
+ else
+ jQuery(this).text wp_resume.more
+ false
+
+ #verify that position has a section
+ validatePosition: (e) ->
+ return unless jQuery("input:radio[name=wp_resume_section]:checked").val() is ""
+ e.preventDefault()
+ e.stopPropagation()
+ alert wp_resume.missingTaxMsg
+ jQuery("#ajax-loading").hide()
+ setTimeout "jQuery('#publish').removeClass('button-primary-disabled')", 1
+ false
+
+ toggleMultiple: ->
+ jQuery("#multiple").toggle "fast"
+ if jQuery(this).text() is wp_resume.yes
+ jQuery(this).text wp_resume.no
+ else
+ jQuery(this).text wp_resume.yes
+ false
+
+ toggleHood: ->
+ jQuery('.underHood').toggle "fast"
+ if jQuery(this).text() is wp_resume.hideAdv
+ jQuery(this).text wp_resume.showAdv
+ else
+ jQuery(this).text wp_resume.hideAdv
+ false
+
+ addContactField: ->
+ jQuery("#contact_info").append jQuery(".contact_info_blank").html()
+ jQuery(".contact_info_row:last").fadeIn()
+ false
+
+ addTaxonomyBoxEvents: (taxonomy) ->
+ jQuery("#add_" + taxonomy + "_toggle").live "click", ->
+ type = jQuery(this).attr("id").replace("_toggle", "").replace("add_", "")
+ jQuery("#add_" + type + "_div").toggle()
+
+ jQuery("#add_" + taxonomy + "_button").live "click", (event) ->
+ type = jQuery(this).attr("id").replace("_button", "").replace("add_", "")
+ jQuery("#" + type + "-ajax-loading").show()
+ jQuery.post "admin-ajax.php?action=add_" + type, jQuery("#new_" + type + ", #new_" + type + "_location, #_ajax_nonce-add-" + type + ", #post_ID").serialize(), (data) ->
+ jQuery("#" + type + "div .inside").html data
+ event.preventDefault()
+
+ makeSortable: ->
+ jQuery("#sections, .positions, .organizations").sortable
+ axis: "y"
+ containment: "parent"
+ opacity: .5
+ update: ->
+ placeholder: "placeholder"
+ forcePlaceholderSize: "true"
+ jQuery("#sections").disableSelection()
+
+ submitOptions: ->
+ jQuery(".section").each (i, section) ->
+ jQuery("#wp_resume_form").append "<input type=\"hidden\" name=\"wp_resume_options[order][" + jQuery(this).attr("id") + "]\" value=\"" + i + "\">"
+
+ jQuery(".position").each (i, position) ->
+ jQuery("#wp_resume_form").append "<input type=\"hidden\" name=\"wp_resume_options[position_order][" + jQuery(this).attr("id") + "]\" value=\"" + i + "\">"
+
+jQuery(document).ready ->
+ window.resume = new WP_Resume()
+
@@ -1,128 +1,134 @@
-jQuery(document).ready(function($){
+// Generated by CoffeeScript 1.4.0
+(function() {
+ var WP_Resume;
- //order box
- $('#wp_resume_help, #wp_resume_clearfix').hide();
- $('#wp_resume_help_toggle').click(function(){
- $('#wp_resume_help, #wp_resume_clearfix').toggle('fast');
- if ($(this).text() == wp_resume.more )
- $(this).text( wp_resume.less );
- else
- $(this).text( wp_resume.more );
- return false;
- });
-
- //taxonomy box
- var types = ['wp_resume_section', 'wp_resume_organization'];
- for (var i in types) {
- $('#add_' + types[i] + '_toggle').live( 'click', function(){
- var type = $(this).attr('id').replace('_toggle', '').replace('add_', '');
- $('#add_' + type + '_div').toggle();
- });
- $('#add_' + types[i] + '_button').live( 'click', function() {
- var type = $(this).attr('id').replace('_button', '').replace('add_', '');
- $('#' + type + '-ajax-loading').show();
- $.post('admin-ajax.php?action=add_' + type, $('#new_' + type + ', #new_' + type + '_location, #_ajax_nonce-add-' + type + ', #post_ID').serialize(), function(data) {
- $('#' + type + 'div .inside').html(data);
- });
- event.preventDefault();
- });
- }
+ WP_Resume = (function() {
- $('#publish').click( function( e ) {
-
- //verify that position has a section
- if ( pagenow == 'wp_resume_position' &&
- $('input:radio[name=wp_resume_section]:checked').val() == '' ) {
-
- e.preventDefault();
- e.stopPropagation();
-
- alert( wp_resume.missingTaxMsg );
-
- $('#ajax-loading').hide();
- setTimeout( "jQuery('#publish').removeClass('button-primary-disabled')", 1);
+ function WP_Resume() {
+ var taxonomy, _i, _len, _ref;
+ switch (pagenow) {
+ case "wp_resume_position_page_wp_resume_options":
+ jQuery("#wp_resume_help, #wp_resume_clearfix, #multiple, .underHood").hide();
+ jQuery("#wp_resume_help_toggle").click(this.toggleHelp);
+ jQuery("#toggleMultiple").click(this.toggleMultiple);
+ jQuery("#toggleHood").click(this.toggleHood);
+ jQuery("#user").change(jQuery(".button-primary").click);
+ jQuery("#add_contact_field").click(this.addContactField);
+ jQuery(".button-primary").click(this.submitOptions);
+ this.addContactField();
+ this.makeSortable();
+ break;
+ case "wp_resume_position":
+ jQuery("#publish").click(this.validatePosition);
+ _ref = ["wp_resume_section", "wp_resume_organization"];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ taxonomy = _ref[_i];
+ this.addTaxonomyBoxEvents(taxonomy);
+ }
+ break;
+ case "edit-wp_resume_organization":
+ jQuery("#parent, #tag-slug").parent().hide();
+ jQuery("#tag-name").siblings("p").text(wp_resume.orgName);
+ jQuery("#tag-description").attr("rows", "1").siblings("label").text("Location").siblings("p").text(wp_resume.orgLoc);
+ break;
+ case "edit-wp_resume_section":
+ jQuery("#parent").parent().hide();
+ jQuery("#tag-description, #tag-slug").parent().hide();
+ }
+ }
- return false;
+ WP_Resume.prototype.toggleHelp = function() {
+ jQuery("#wp_resume_help, #wp_resume_clearfix").toggle("fast");
+ if (jQuery(this).text() === wp_resume.more) {
+ jQuery(this).text(wp_resume.less);
+ } else {
+ jQuery(this).text(wp_resume.more);
+ }
+ return false;
+ };
- }
-
-
- });
+ WP_Resume.prototype.validatePosition = function(e) {
+ if (jQuery("input:radio[name=wp_resume_section]:checked").val() !== "") {
+ return;
+ }
+ e.preventDefault();
+ e.stopPropagation();
+ alert(wp_resume.missingTaxMsg);
+ jQuery("#ajax-loading").hide();
+ setTimeout("jQuery('#publish').removeClass('button-primary-disabled')", 1);
+ return false;
+ };
- if ( pagenow == 'wp_resume_position_page_wp_resume_options' ) {
+ WP_Resume.prototype.toggleMultiple = function() {
+ jQuery("#multiple").toggle("fast");
+ if (jQuery(this).text() === wp_resume.yes) {
+ jQuery(this).text(wp_resume.no);
+ } else {
+ jQuery(this).text(wp_resume.yes);
+ }
+ return false;
+ };
- //options page -- contact info rows
- $('#contact_info').append( $('.contact_info_blank').html() );
- $('.contact_info_row:last').show();
- $('#add_contact_field').click(function(){
- $('#contact_info').append( $('.contact_info_blank').html() );
- $('.contact_info_row:last').fadeIn();
- return false;
- });
-
- //options page -- help toggles
- $('#multiple').hide();
- $('#toggleMultiple').click(function() {
- $('#multiple').toggle('fast');
- if ($(this).text() == wp_resume.yes )
- $(this).text( wp_resume.no );
- else
- $(this).text( wp_resume.yes );
- return false;
- });
- $('.underHood').hide();
- $('#toggleHood').click(function() {
- $('.underHood').toggle('fast');
- if ($(this).text() == wp_resume.hideAdv )
- $(this).text( wp_resume.showAdv );
- else
- $(this).text( wp_resume.hideAdv );
- return false;
- });
-
- //options page -- sorting
- $("#sections, .positions, .organizations").sortable({
- axis:'y',
- containment: 'parent',
- opacity: .5,
- update: function(){},
- placeholder: 'placeholder',
- forcePlaceholderSize: 'true'
- });
- $("#sections").disableSelection();
-
- //options page --submit button
- $('.button-primary').click(function(){
- var i = 0;
- $('.section').each(function(){
- $('#wp_resume_form').append('<input type="hidden" name="wp_resume_options[order]['+$(this).attr('id')+']" value="' + i + '">');
- i = i +1;
- });
- var i = 1;
- $('.position').each(function(){
- $('#wp_resume_form').append('<input type="hidden" name="wp_resume_options[position_order]['+$(this).attr('id')+']" value="' + i + '">');
- i = i +1;
- });
- });
-
- //options page -- user change
- $('#user').change(function(){
- $('.button-primary').click();
- });
-
- }
-
- //organizations page
- if ( pagenow == 'edit-wp_resume_organization') {
- $('#parent, #tag-slug').parent().hide();
- $('#tag-name').siblings('p').text( wp_resume.orgName );
- $('#tag-description').attr('rows','1').siblings('label').text('Location').siblings('p').text( wp_resume.orgLoc );
- }
-
- //sections page
- if ( pagenow == 'edit-wp_resume_section') {
- $('#parent').parent().hide();
- $('#tag-description, #tag-slug').parent().hide();
- }
-
-});
+ WP_Resume.prototype.toggleHood = function() {
+ jQuery('.underHood').toggle("fast");
+ if (jQuery(this).text() === wp_resume.hideAdv) {
+ jQuery(this).text(wp_resume.showAdv);
+ } else {
+ jQuery(this).text(wp_resume.hideAdv);
+ }
+ return false;
+ };
+
+ WP_Resume.prototype.addContactField = function() {
+ jQuery("#contact_info").append(jQuery(".contact_info_blank").html());
+ jQuery(".contact_info_row:last").fadeIn();
+ return false;
+ };
+
+ WP_Resume.prototype.addTaxonomyBoxEvents = function(taxonomy) {
+ jQuery("#add_" + taxonomy + "_toggle").live("click", function() {
+ var type;
+ type = jQuery(this).attr("id").replace("_toggle", "").replace("add_", "");
+ return jQuery("#add_" + type + "_div").toggle();
+ });
+ return jQuery("#add_" + taxonomy + "_button").live("click", function(event) {
+ var type;
+ type = jQuery(this).attr("id").replace("_button", "").replace("add_", "");
+ jQuery("#" + type + "-ajax-loading").show();
+ jQuery.post("admin-ajax.php?action=add_" + type, jQuery("#new_" + type + ", #new_" + type + "_location, #_ajax_nonce-add-" + type + ", #post_ID").serialize(), function(data) {
+ return jQuery("#" + type + "div .inside").html(data);
+ });
+ return event.preventDefault();
+ });
+ };
+
+ WP_Resume.prototype.makeSortable = function() {
+ jQuery("#sections, .positions, .organizations").sortable({
+ axis: "y",
+ containment: "parent",
+ opacity: .5,
+ update: function() {},
+ placeholder: "placeholder",
+ forcePlaceholderSize: "true"
+ });
+ return jQuery("#sections").disableSelection();
+ };
+
+ WP_Resume.prototype.submitOptions = function() {
+ jQuery(".section").each(function(i, section) {
+ return jQuery("#wp_resume_form").append("<input type=\"hidden\" name=\"wp_resume_options[order][" + jQuery(this).attr("id") + "]\" value=\"" + i + "\">");
+ });
+ return jQuery(".position").each(function(i, position) {
+ return jQuery("#wp_resume_form").append("<input type=\"hidden\" name=\"wp_resume_options[position_order][" + jQuery(this).attr("id") + "]\" value=\"" + i + "\">");
+ });
+ };
+
+ return WP_Resume;
+
+ })();
+
+ jQuery(document).ready(function() {
+ return window.resume = new WP_Resume();
+ });
+
+}).call(this);
@@ -1,6 +1,2 @@
-jQuery(document).ready(function(a){a("#wp_resume_help, #wp_resume_clearfix").hide();a("#wp_resume_help_toggle").click(function(){a("#wp_resume_help, #wp_resume_clearfix").toggle("fast");a(this).text()==wp_resume.more?a(this).text(wp_resume.less):a(this).text(wp_resume.more);return!1});var c=["wp_resume_section","wp_resume_organization"],d;for(d in c)a("#add_"+c[d]+"_toggle").live("click",function(){var b=a(this).attr("id").replace("_toggle","").replace("add_","");a("#add_"+b+"_div").toggle()}),a("#add_"+
-c[d]+"_button").live("click",function(){var b=a(this).attr("id").replace("_button","").replace("add_","");a("#"+b+"-ajax-loading").show();a.post("admin-ajax.php?action=add_"+b,a("#new_"+b+", #new_"+b+"_location, #_ajax_nonce-add-"+b+", #post_ID").serialize(),function(c){a("#"+b+"div .inside").html(c)});event.preventDefault()});a("#publish").click(function(b){if("wp_resume_position"==pagenow&&""==a("input:radio[name=wp_resume_section]:checked").val())return b.preventDefault(),b.stopPropagation(),alert(wp_resume.missingTaxMsg),
-a("#ajax-loading").hide(),setTimeout("jQuery('#publish').removeClass('button-primary-disabled')",1),!1});"wp_resume_position_page_wp_resume_options"==pagenow&&(a("#contact_info").append(a(".contact_info_blank").html()),a(".contact_info_row:last").show(),a("#add_contact_field").click(function(){a("#contact_info").append(a(".contact_info_blank").html());a(".contact_info_row:last").fadeIn();return!1}),a("#multiple").hide(),a("#toggleMultiple").click(function(){a("#multiple").toggle("fast");a(this).text()==
-wp_resume.yes?a(this).text(wp_resume.no):a(this).text(wp_resume.yes);return!1}),a(".underHood").hide(),a("#toggleHood").click(function(){a(".underHood").toggle("fast");a(this).text()==wp_resume.hideAdv?a(this).text(wp_resume.showAdv):a(this).text(wp_resume.hideAdv);return!1}),a("#sections, .positions, .organizations").sortable({axis:"y",containment:"parent",opacity:0.5,update:function(){},placeholder:"placeholder",forcePlaceholderSize:"true"}),a("#sections").disableSelection(),a(".button-primary").click(function(){var b=
-0;a(".section").each(function(){a("#wp_resume_form").append('<input type="hidden" name="wp_resume_options[order]['+a(this).attr("id")+']" value="'+b+'">');b+=1});b=1;a(".position").each(function(){a("#wp_resume_form").append('<input type="hidden" name="wp_resume_options[position_order]['+a(this).attr("id")+']" value="'+b+'">');b+=1})}),a("#user").change(function(){a(".button-primary").click()}));"edit-wp_resume_organization"==pagenow&&(a("#parent, #tag-slug").parent().hide(),a("#tag-name").siblings("p").text(wp_resume.orgName),
-a("#tag-description").attr("rows","1").siblings("label").text("Location").siblings("p").text(wp_resume.orgLoc));"edit-wp_resume_section"==pagenow&&(a("#parent").parent().hide(),a("#tag-description, #tag-slug").parent().hide())});
+// Generated by CoffeeScript 1.4.0
+(function(){var e;e=function(){function e(){var e,t,n,r;switch(pagenow){case"wp_resume_position_page_wp_resume_options":jQuery("#wp_resume_help, #wp_resume_clearfix, #multiple, .underHood").hide(),jQuery("#wp_resume_help_toggle").click(this.toggleHelp),jQuery("#toggleMultiple").click(this.toggleMultiple),jQuery("#toggleHood").click(this.toggleHood),jQuery("#user").change(jQuery(".button-primary").click),jQuery("#add_contact_field").click(this.addContactField),jQuery(".button-primary").click(this.submitOptions),this.addContactField(),this.makeSortable();break;case"wp_resume_position":jQuery("#publish").click(this.validatePosition),r=["wp_resume_section","wp_resume_organization"];for(t=0,n=r.length;t<n;t++)e=r[t],this.addTaxonomyBoxEvents(e);break;case"edit-wp_resume_organization":jQuery("#parent, #tag-slug").parent().hide(),jQuery("#tag-name").siblings("p").text(wp_resume.orgName),jQuery("#tag-description").attr("rows","1").siblings("label").text("Location").siblings("p").text(wp_resume.orgLoc);break;case"edit-wp_resume_section":jQuery("#parent").parent().hide(),jQuery("#tag-description, #tag-slug").parent().hide()}}return e.prototype.toggleHelp=function(){return jQuery("#wp_resume_help, #wp_resume_clearfix").toggle("fast"),jQuery(this).text()===wp_resume.more?jQuery(this).text(wp_resume.less):jQuery(this).text(wp_resume.more),!1},e.prototype.validatePosition=function(e){if(jQuery("input:radio[name=wp_resume_section]:checked").val()!=="")return;return e.preventDefault(),e.stopPropagation(),alert(wp_resume.missingTaxMsg),jQuery("#ajax-loading").hide(),setTimeout("jQuery('#publish').removeClass('button-primary-disabled')",1),!1},e.prototype.toggleMultiple=function(){return jQuery("#multiple").toggle("fast"),jQuery(this).text()===wp_resume.yes?jQuery(this).text(wp_resume.no):jQuery(this).text(wp_resume.yes),!1},e.prototype.toggleHood=function(){return jQuery(".underHood").toggle("fast"),jQuery(this).text()===wp_resume.hideAdv?jQuery(this).text(wp_resume.showAdv):jQuery(this).text(wp_resume.hideAdv),!1},e.prototype.addContactField=function(){return jQuery("#contact_info").append(jQuery(".contact_info_blank").html()),jQuery(".contact_info_row:last").fadeIn(),!1},e.prototype.addTaxonomyBoxEvents=function(e){return jQuery("#add_"+e+"_toggle").live("click",function(){var e;return e=jQuery(this).attr("id").replace("_toggle","").replace("add_",""),jQuery("#add_"+e+"_div").toggle()}),jQuery("#add_"+e+"_button").live("click",function(e){var t;return t=jQuery(this).attr("id").replace("_button","").replace("add_",""),jQuery("#"+t+"-ajax-loading").show(),jQuery.post("admin-ajax.php?action=add_"+t,jQuery("#new_"+t+", #new_"+t+"_location, #_ajax_nonce-add-"+t+", #post_ID").serialize(),function(e){return jQuery("#"+t+"div .inside").html(e)}),e.preventDefault()})},e.prototype.makeSortable=function(){return jQuery("#sections, .positions, .organizations").sortable({axis:"y",containment:"parent",opacity:.5,update:function(){},placeholder:"placeholder",forcePlaceholderSize:"true"}),jQuery("#sections").disableSelection()},e.prototype.submitOptions=function(){return jQuery(".section").each(function(e,t){return jQuery("#wp_resume_form").append('<input type="hidden" name="wp_resume_options[order]['+jQuery(this).attr("id")+']" value="'+e+'">')}),jQuery(".position").each(function(e,t){return jQuery("#wp_resume_form").append('<input type="hidden" name="wp_resume_options[position_order]['+jQuery(this).attr("id")+']" value="'+e+'">')})},e}(),jQuery(document).ready(function(){return window.resume=new e})}).call(this);

0 comments on commit e210115

Please sign in to comment.