Skip to content

Instantly share code, notes, and snippets.

View anoopt's full-sized avatar

Anoop T anoopt

View GitHub Profile
var CascadingMMD = window.CascadingMMD || {};
CascadingMMD.termPathList = new Array(); //An array to store the paths of all terms in the termset (Continents, Countries and Regions)
CascadingMMD.CountryVals = new Array(); //An array to store only countries
CascadingMMD.RegionVals = new Array(); //An array to store only regions
CascadingMMD.CountryValsWithRegion = new Array(); //An array to store countries and regions
CascadingMMD.ddlCountry; //Country drop down
CascadingMMD.ddlRegion; // Region drop down
$(document).ready(function(){
//call the function to hide controls (see below in the blog)
CascadingMMD.Libs.hideControlsOnLoad();
//get the list stored in the cookie
var listFromCookie = CascadingMMD.Libs.getCookie("TermsPathList");
if(listFromCookie != null) {
//split the value in the cookie by ',' and store it in termPathList
CascadingMMD.termPathList = decodeURIComponent(listFromCookie).split(",");
var hideControlsOnLoad = function(){
CascadingMMD.ddlCountry = $('#ddlCountry');
CascadingMMD.ddlCountry.hide();
CascadingMMD.ddlRegion = $('#ddlRegion');
CascadingMMD.ddlRegion.hide();
};
"use strict";
var CascadingMMD = window.CascadingMMD || {};
CascadingMMD.termPathList = new Array(); //An array to store the paths of all terms in the termset (Continents, Countries and Regions)
CascadingMMD.CountryVals = new Array(); //An array to store only countries
CascadingMMD.RegionVals = new Array(); //An array to store only regions
CascadingMMD.CountryValsWithRegion = new Array(); //An array to store countries and regions
CascadingMMD.ddlCountry; //Country drop down
CascadingMMD.ddlRegion; // Region drop down
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="../Shared Documents/CascadingMMD.js"></script>
<link rel="stylesheet" href="https://appsforoffice.microsoft.com/fabric/2.2.0/fabric.min.css">
<link rel="stylesheet" href="https://appsforoffice.microsoft.com/fabric/2.2.0/fabric.components.min.css">
</head>
<body>
var getTermSetData = function(){
//Current Context
var context = SP.ClientContext.get_current();
//Current Taxonomy Session
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
//Term Stores
var termStores = taxSession.get_termStores();
//This function is similar to the previous one
var addCountryChangeHandler = function() {
$('#ddlCountry').change(function(){
var str = "";
$( "#ddlCountry option:selected" ).each(function() {
str += $( this ).text();
});
if(str == "All"){
CascadingMMD.ddlRegion.empty();
var addContinentChangeHandler = function(){
$("#ddlContinent").change(function() {
var str = "";
$( "#ddlContinent option:selected" ).each(function() {
str += $( this ).text();
});
//If selected text is first one "Select", then empty other drop downs and hide them
//Can use selected value instead of selected text
if(str == "Select"){
CascadingMMD.ddlCountry.empty();
var getDataContinent = function(){
var ddlContinent = $('#ddlContinent');
$.each( CascadingMMD.termPathList, function( index, value ){
if(value.indexOf(';') < 0){
ddlContinent.append(
$('<option></option>').html(value)
);
}