Skip to content

Instantly share code, notes, and snippets.

@jeffikus
Forked from DanielSantoro/woo.js
Last active August 29, 2015 14:10
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 jeffikus/f06f6b48757a06471faf to your computer and use it in GitHub Desktop.
Save jeffikus/f06f6b48757a06471faf to your computer and use it in GitHub Desktop.
/*
* jQuery v1.9.1 included. Go allllll the way down
*/
$(document).ready(function() {
// Removes first 3 chars from Topics list - By Jeff Pearce
function setCharAt(str,index,chr) {
if(index > str.length-1) return str;
return str.substr(0,index) + chr + str.substr(index+1);
}
$('body ul.topic-list li.topic h3.topic-title a').each( function(){
str = $(this).text();
str = setCharAt(str,2,'');
str = setCharAt(str,1,'');
str = setCharAt(str,0,'');
$(this).text(str);
});
// fix sidebar button text on replies
$('.side-column').find('.request-details').next().text('Submit a new ticket');
// social share popups
$(".share a").click(function(e) {
e.preventDefault();
window.open(this.href, "", "height = 500, width = 500");
});
// toggle the share dropdown in communities
$(".share-label").on("click", function(e) {
e.stopPropagation();
var isSelected = this.getAttribute("aria-selected") == "true";
this.setAttribute("aria-selected", !isSelected);
$(".share-label").not(this).attr("aria-selected", "false");
});
$(document).on("click", function() {
$(".share-label").attr("aria-selected", "false");
});
// show form controls when the textarea receives focus
$(".answer-body textarea").one("focus", function() {
$(".answer-form-controls").show();
});
$(".comment-container textarea").one("focus", function() {
$(".comment-form-controls").show();
});
//alert($( ".answer-official-heading").html() );
}
// Fix New Topic Dropdown List - by Patrick Rauland
var topicOptions = $('#question_topic_id');
var listitems = topicOptions.children('option').get();
listitems.sort(function(a, b) {
return $(a).text().toUpperCase().localeCompare($(b).text().toUpperCase());
});
$.each(listitems, function(idx, itm) { topicOptions.append(itm); });
/**
* Handle ticket form field permissions based on customer data from WooThemes.com
* @author Gerhard Potgieter
*/
var current_url = $( location ).attr( 'href' );
var ticket_form_regex = /hc\/en-us\/requests\/new/;
if ( current_url.match( ticket_form_regex ) ) {
if ( ( typeof HelpCenter.user != 'undefined' ) && ( HelpCenter.user.email ) && ( HelpCenter.user.role != 'anonymous' ) ) {
$.get( 'https://www.woothemes.com/wc-api/customer-permissions?token=dexriV6DXbNK6e&email=' + HelpCenter.user.email, function( data ){
console.log( data );
});
}
}
/**
* End Ticket form permissions based on customer data from WooThemes.com
*/
});
// Add custom ID for single community question column - THIS ONE RIGHT HERE
// SEE! \/
(function($){
$(document).ready(function(){
var url = $( location ).attr( 'href' );
url = url.toLowerCase();
var patCommunity = /communities\/public\/questions/;
var patKB = /\/articles\//;
var DannysHelpPage = /hc\/en-us\/requests\//;
if( url.match( patCommunity ) || url.match( DannysHelpPage ) ){
$( '.main-column' ).attr( 'id','single-community-column' );
} else if( url.match( patKB ) ){
$( '.main-column' ).attr( 'id','single-article-column' );
}
});
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment