Skip to content

Instantly share code, notes, and snippets.

@joshpangell
Last active October 2, 2015 09:38
Show Gist options
  • Save joshpangell/2220862 to your computer and use it in GitHub Desktop.
Save joshpangell/2220862 to your computer and use it in GitHub Desktop.
Cargo helper methods
/**
* Cargo's helper methods
*/
/*
* Config helpers
*/
// Returns the design
Cargo.Config.GetDesign();
// Returns the template
Cargo.Config.GetTemplate();
// Returns the page type of the open project (project / page)
Cargo.Config.GetCurrentPageType();
// Returns the current page in pagination (1, 2, 3, etc)
Cargo.Config.GetCurrentPage();
// Returns the total amount of pages (5)
Cargo.Config.GetTotalPages();
// Returns the amount of projects per page (15)
Cargo.Config.GetPageLimit();
// Returns true/false for IE
Cargo.Config.isIE();
// Returns true/false for IE8
Cargo.Config.isIE8();
// Returns true/false for mobile browser
Cargo.Config.isMobile();
/* Returns the page type
* Possible return values: "project" || "page" || "none"
* Must be fired after projectLoadComplete OR on document ready
* otherwise, it will return the previous project's type
*/
Cargo.Config.GetCurrentPageType();
/* Returns the width of the scroll bars
* Useful for determining if we are in Lion webkit or not
* Webkit will return 0
*/
Cargo.Config.GetScrollBarWidth();
/*
* Location helpers
*/
// Returns the Cargo/url, even on custom domain
// eg. "escher"
Cargo.Location.GetCargoUrl();
// Will return the domain, with or without the trailing slash
// (true) returns: "http://cargocollective.com"
// (false) returns: "http://butdoesitfloat.com/"
Cargo.Location.GetDomain( no_trailing_slash );
// Returns the ID of the network, even on custom domain
// eg. "5"
Cargo.Location.GetNetworkId();
// Returns the base URL if on Cargo domain, blank if custom domain
// eg: "/escher"
Cargo.Location.GetBaseUrl();
// Makes a direct link based on the purl value passed
// If no value is passed, it will return the value of the "homepage"
// Example: MakeDirectLink( "About" ) => "http://cargocollective.com/escher/About"
// Example: MakeDirectLink() => "http://butdoesitfloat" || "http://cargocollective.com/escher"
Cargo.Location.MakeDirectLink( purl );
// Returns the direct link to this project when passed a pid
Cargo.Location.GetDirectLink( pid );
// Returns a true/false value if you are on the following page or not
Cargo.Location.IsFollowing();
// Returns a true/false value if this is a custom domain or not
Cargo.Location.IsCustomDomain();
// Returns a true/false value if this page is a user filter
Cargo.Location.IsUserFilter();
// Returns the string of the filter, if there is one. If there is not, it will return false
Cargo.Location.GetUserFilter();
// Returns a true/false value if this page is a solo (perma) link
Cargo.Location.IsSoloLink();
// Returns a true/false value if this page is a direct link
Cargo.Location.IsDirectLink();
// Returns a true/false value if this is a startproject
Cargo.Location.IsStartProject();
// Returns a true/false value if this page is a project being edited
Cargo.Location.IsEditingProject();
// Returns a true/false value if this page is in the admin frame or not
Cargo.Location.IsInAdmin();
// Returns a true/false value if this page is a feed index
Cargo.Location.IsFeedIndex();
// Returns a true/false value if this page is the search results page
Cargo.Location.IsSearch();
// Returns a true/false value if this page is the tracemarks page
Cargo.Location.IsTraceMarks();
// Returns a true/false value if this page is a network
Cargo.Location.IsNetwork();
// Returns a true/false value if this page is the network members page
Cargo.Location.IsNetworkMemberList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment