Skip to content

Instantly share code, notes, and snippets.

View charitygrace's full-sized avatar

Charity charitygrace

View GitHub Profile
(?:^|\/|\\)(?:[a-zA-Z0-9\s\-\_])*\.[a-zA-Z]*$
This will check just the filename in a file upload and ignore the file path before the file name.
This will allow any filename with letters, numbers, dashes, underscores and spaces.
Use in jquery validator like this:
$.validator.addMethod("fileName", function(value, element) {
return this.optional(element) || /(?:^|\/|\\)(?:[a-zA-Z0-9\s\-\_])*\.[a-zA-Z]*$/.test(value);
}, "File names can only contain letters, numbers, dashes, and underscores (and spaces).");
@charitygrace
charitygrace / colorbox-resize.js
Created June 17, 2014 20:04
Colorbox global resize/responsive function
/* via https://github.com/jackmoore/colorbox/issues/158 */
/* Colorbox resize function */
var resizeTimer;
function resizeColorBox()
{
if (resizeTimer) clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
if (jQuery('#cboxOverlay').is(':visible')) {
jQuery.colorbox.resize({width:'80%', height:'80%', maxWidth:700, maxWidth:500});
@charitygrace
charitygrace / main-nav-CIT-loop
Created November 23, 2013 17:09
Loop through a custom item type using the built-in menu system in webvanta using the twitter bootstrap css/html. this code is particularly for when you create a custom top level menu entry where you can then target the custom url you give it. examples: wchc.wv.com, macbeath.wv.com #webvanta #webvantascript
<w:if_url matches="custom-menu-name"> <!--make "custom-menu-name" equal the "external menu link" url -->
<li class="dropdown <w:kb:item:each type='CIT-name' by='sequence asc'><w:var name='the_item_id'><w:id /></w:var><w:if condition='{{the_item_id}}={{this_item_id}}'>active </w:if></w:kb:item:each>">
<a href='#' data-toggle="dropdown" class="dropdown-toggle"><w:label /><b class="caret"></b></a>
<ul class="dropdown-menu">
<w:kb:item:each type="CIT-name" by="sequence asc">
<w:var name='the_item_id'><w:id /></w:var>
<li class="<w:if condition='{{the_item_id}}={{this_item_id}}'>active</w:if>">
<a href="/service/<w:perma_link_name />"><w:name /></a>
</li>
</w:kb:item:each>
@charitygrace
charitygrace / external-links.js
Created November 13, 2013 16:27
Generic code to open all external links in a new tab/window #webvanta
@charitygrace
charitygrace / member-controls.js
Last active December 28, 2015 05:39
Create a login/logout/edit profile link in Webvanta #webvanta #webvantascript
//The html would be:
//<div class="login">
// <span class="member_controls_login"><a href="/login">Member Login</a></span>
// <span class="member_controls" style="display:none;"><a href='/edit-profile'>Edit profile</a> | <a href='/logout'>Logout</a></span>
//</div>
//display member controls
if((WebvantaAdmin.getUIRValue("r")=="member")||(WebvantaAdmin.getUIRValue("r")=="admin")||(WebvantaAdmin.getUIRValue("r")=="content editor")) {
$(".member_name").text(WebvantaAdmin.getUIRValue("name"));