<commit_before>moduleAid.VERSION = '1.1.1';
moduleAid.UTILS = true;

// messenger - 	Aid object to communicate with browser content scripts (e10s).
//		Important: this loads the defaults.js file into every browser window, so make sure that everything in it is wrapped in their own methods,
//		or that at least it won't fail when loaded like this.
// messageBrowser(aBrowser, aMessage, aData, aCPOW) - sends a message to content scripts of a browser
//	aBrowser - (xul element) the browser element to send the message to
//	aMessage - (string) message to send, will be sent as objName-aMessage
//	aData - (string) data to be passed along with the message; can be a JSON-serializable object
//	aCPOW - (object) an object, typically a xul element, that will be proxied to the content script
// messageWindow(aWindow, aMessage, aData, aCPOW) - sends a message to content scripts of all browsers in the provided window
//	aWindow - (obj) window of which all browsers should receive this message
//	see messageBrowser()
// messageAll(aMessage, aData, aCPOW) - sends a message to content scripts of all browsers in all windows
//	see messageBrowser()
// listenBrowser(aBrowser, aMessage, aListener) - registers a listener for messages sent from content scripts through this backbone's methods
//	aBrowser - (xul element) the browser element from which to listen to messages
//	aMessage - (string) message to listen for
//	aListener - (function) the listener that will respond to the message. Expects (message) as its only argument; see https://developer.mozilla.org/en-US/docs/The_message_manager
// unlistenBrowser(aBrowser, aMessage, aListener) - unregisters a listener for messages sent from content scripts
//	see listenBrowser()
// listenWindow(aWindow, aMessage, aListener) - registers a listener for messages sent from all browsers in the provided window
//	aWindow - (obj) window of which all browsers should be listened to
//	see listenBrowser()
// unlistenWindow(aWindow, aMessage, aListener) - unregisters a listener for messages sent from all browsers in the provided window
//	see listenWindow()
// listenAll(aMessage, aListener) - registers a listener for messages sent from all browsers open in all windows
//	see listenBrowser()
// unlistenAll(aMessage, aListener) - unregisters a listener for messages sent from all browsers open in all windows
//	see listenBrowser()
// loadInBrowser(aBrowser, aModule) - loads a module into the content script of the specified browser
//	aBrowser - (xul element) the browser element corresponding to the content script into which to load the module
//	aModule - (string) name of the module to load
// unloadFromBrowser(aBrowser, aModule) - unloads a module from a content script [undoes loadInBrowser()]
//	see loadInBrowser()
// loadInWindow(aWindow, aModule) - loads a module into all the content scripts of a specified window
//	aWindow - (xul element) navigator window of which all content scripts will have the module loaded into
//	see loadInBrowser()
// unloadFromWindow(aWindow, aModule) - unloads a module from all the content scripts of a window [undoes loadInWindow()]
//	see loadInWindow()
// loadInAll(aModule) - loads a module into all content scripts
//	see loadInBrowser()
// unloadFromAll(aModule) - unloads a module from all content scripts [undoes loadInAll()]
//	see loadInBrowser()
this.messenger = {
	loadedInAll: [],

	globalMM: Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager),

	messageBrowser: function(aBrowser, aMessage, aData, aCPOW) {
		if(!aBrowser || !aBrowser.messageManager) { return; }

		aBrowser.messageManager.sendAsyncMessage(objName+':'+aMessage, aData, aCPOW);
	},

	messageWindow: function(aWindow, aMessage, aData, aCPOW) {
		if(!aWindow || !aWindow.messageManager) { return; }

		aWindow.messageManager.broadcastAsyncMessage(objName+':'+aMessage, aData, aCPOW);
	},

	messageAll: function(aMessage, aData, aCPOW) {
		this.globalMM.broadcastAsyncMessage(objName+':'+aMessage, aData, aCPOW);
	},

	listenBrowser: function(aBrowser, aMessage, aListener) {
		if(!aBrowser || !aBrowser.messageManager) { return; }

		aBrowser.messageManager.addMessageListener(objName+':'+aMessage, aListener);
	},

	unlistenBrowser: function(aBrowser, aMessage, aListener) {
		if(!aBrowser || !aBrowser.messageManager) { return; }

		aBrowser.messageManager.removeMessageListener(objName+':'+aMessage, aListener);
	},

	listenWindow: function(aWindow, aMessage, aListener) {
		if(!aWindow || !aWindow.messageManager) { return; }

		aWindow.messageManager.addMessageListener(objName+':'+aMessage, aListener);
	},

	unlistenWindow: function(aWindow, aMessage, aListener) {
		if(!aWindow || !aWindow.messageManager) { return; }

		aWindow.messageManager.removeMessageListener(objName+':'+aMessage, aListener);
	},

	listenAll: function(aMessage, aListener) {
		this.globalMM.addMessageListener(objName+':'+aMessage, aListener);
	},

	unlistenAll: function(aMessage, aListener) {
		this.globalMM.removeMessageListener(objName+':'+aMessage, aListener);
	},

	loadInBrowser: function(aBrowser, aModule) {
		this.messageBrowser(aBrowser, 'load', aModule);
	},

	unloadFromBrowser: function(aBrowser, aModule) {
		this.messageBrowser(aBrowser, 'unload', aModule);
	},

	loadInWindow: function(aWindow, aModule) {
		if(aWindow.gBrowser && aWindow.gBrowser.tabContainer) {
			if(!aWindow.gBrowser.tabContainer[objName+'Content']) {
				aWindow.gBrowser.tabContainer[objName+'Content'] = {
					modules: [aModule],
					listener: function(e) {
						messenger.messageBrowser(e.target.linkedBrowser, 'reinit');
					}
				};
				aWindow.gBrowser.tabContainer.addEventListener('TabOpen', aWindow.gBrowser.tabContainer[objName+'Content'].listener, true);
			}
			else if(aWindow.gBrowser.tabContainer[objName+'Content'].modules.indexOf(aModule) == -1) {
				aWindow.gBrowser.tabContainer[objName+'Content'].modules.push(aModule);
			}
		}

		this.messageWindow(aWindow, 'load', aModule);
	},

	unloadFromWindow: function(aWindow, aModule) {
		if(aWindow.gBrowser && aWindow.gBrowser.tabContainer) {
			if(aWindow.gBrowser.tabContainer[objName+'Content'] && aWindow.gBrowser.tabContainer[objName+'Content'].modules.indexOf(aModule) != -1) {
				aWindow.gBrowser.tabContainer[objName+'Content'].modules.splice(aWindow.gBrowser.tabContainer[objName+'Content'].modules.indexOf(aModule), 1);
				if(aWindow.gBrowser.tabContainer[objName+'Content'].modules.length == 0) {
					aWindow.gBrowser.tabContainer.removeEventListener('TabOpen', aWindow.gBrowser.tabContainer[objName+'Content'].listener, true);
					delete aWindow.gBrowser.tabContainer[objName+'Content'];
				}
			}
		}

		this.messageWindow(aWindow, 'unload', aModule);
	},

	loadInAll: function(aModule) {
		if(this.loadedInAll.indexOf(aModule) != -1) { return; }
		this.loadedInAll.push(aModule);

		this.messageAll('load', aModule);
	},

	unloadFromAll: function(aModule) {
		if(this.loadedInAll.indexOf(aModule) == -1) { return; }
		this.loadedInAll.splice(this.loadedInAll.indexOf(aModule), 1);

		this.messageAll('unload', aModule);
	},

	initContent: function(m) {
		// if this is a preloaded browser, we don't need to load in it, the content script will still be loaded in the actual tab's browser
		if(m.target.parentNode.localName == 'window' && m.target.parentNode.id == 'win') { return; }

		messenger.messageBrowser(m.target, 'init');

		// carry the preferences current values into content
		var current = {};
		for(var pref in prefList) {
			if(pref.startsWith('NoSync_')) { continue; }
			current[pref] = prefAid[pref];
		}
		messenger.messageBrowser(m.target, 'pref', current);

		// load into this browser all the content modules that should be loaded in all content scripts
		for(var module of messenger.loadedInAll) {
			messenger.messageBrowser(m.target, 'load', module);
		}

		// load into this browser all the content modules that should be loaded into content scripts of this window
		if(m.target.ownerGlobal.gBrowser && m.target.ownerGlobal.gBrowser.tabContainer && m.target.ownerGlobal.gBrowser.tabContainer[objName+'Content']) {
			for(var module of m.target.ownerGlobal.gBrowser.tabContainer[objName+'Content'].modules) {
				messenger.messageBrowser(m.target, 'load', module);
			}
		}
	},

	carryPref: function(pref, val) {
		if(pref.startsWith('NoSync_')) { return; }

		var carry = {};
		carry[pref] = val;
		messenger.messageAll('pref', carry);
	},

	cleanWindow: function(aWindow) {
		if(aWindow.gBrowser && aWindow.gBrowser.tabContainer && aWindow.gBrowser.tabContainer[objName+'Content']) {
			aWindow.gBrowser.tabContainer.removeEventListener('TabOpen', aWindow.gBrowser.tabContainer[objName+'Content'].listener, true);
			delete aWindow.gBrowser.tabContainer[objName+'Content'];
		}
	}
};

moduleAid.LOADMODULE = function() {
	messenger.listenAll('init', messenger.initContent);
	messenger.globalMM.loadFrameScript('resource://'+objPathString+'/modules/utils/content.js?'+AddonData.initTime, true);

	for(var pref in prefList) {
		if(pref.startsWith('NoSync_')) { continue; }

		prefAid.listen(pref, messenger.carryPref);
	}
};

moduleAid.UNLOADMODULE = function() {
	messenger.unlistenAll('init', messenger.initContent);

	for(var pref in prefList) {
		if(pref.startsWith('NoSync_')) { continue; }

		prefAid.unlisten(pref, messenger.carryPref);
	}

	windowMediator.callOnAll(messenger.cleanWindow, 'navigator:browser');

	messenger.messageAll('shutdown');
};
<commit_msg>carry AddonData to content<commit_after>moduleAid.VERSION = '1.2.0';
moduleAid.UTILS = true;

// messenger - 	Aid object to communicate with browser content scripts (e10s).
//		Important: this loads the defaults.js file into every browser window, so make sure that everything in it is wrapped in their own methods,
//		or that at least it won't fail when loaded like this.
// messageBrowser(aBrowser, aMessage, aData, aCPOW) - sends a message to content scripts of a browser
//	aBrowser - (xul element) the browser element to send the message to
//	aMessage - (string) message to send, will be sent as objName-aMessage
//	aData - (string) data to be passed along with the message; can be a JSON-serializable object
//	aCPOW - (object) an object, typically a xul element, that will be proxied to the content script
// messageWindow(aWindow, aMessage, aData, aCPOW) - sends a message to content scripts of all browsers in the provided window
//	aWindow - (obj) window of which all browsers should receive this message
//	see messageBrowser()
// messageAll(aMessage, aData, aCPOW) - sends a message to content scripts of all browsers in all windows
//	see messageBrowser()
// listenBrowser(aBrowser, aMessage, aListener) - registers a listener for messages sent from content scripts through this backbone's methods
//	aBrowser - (xul element) the browser element from which to listen to messages
//	aMessage - (string) message to listen for
//	aListener - (function) the listener that will respond to the message. Expects (message) as its only argument; see https://developer.mozilla.org/en-US/docs/The_message_manager
// unlistenBrowser(aBrowser, aMessage, aListener) - unregisters a listener for messages sent from content scripts
//	see listenBrowser()
// listenWindow(aWindow, aMessage, aListener) - registers a listener for messages sent from all browsers in the provided window
//	aWindow - (obj) window of which all browsers should be listened to
//	see listenBrowser()
// unlistenWindow(aWindow, aMessage, aListener) - unregisters a listener for messages sent from all browsers in the provided window
//	see listenWindow()
// listenAll(aMessage, aListener) - registers a listener for messages sent from all browsers open in all windows
//	see listenBrowser()
// unlistenAll(aMessage, aListener) - unregisters a listener for messages sent from all browsers open in all windows
//	see listenBrowser()
// loadInBrowser(aBrowser, aModule) - loads a module into the content script of the specified browser
//	aBrowser - (xul element) the browser element corresponding to the content script into which to load the module
//	aModule - (string) name of the module to load
// unloadFromBrowser(aBrowser, aModule) - unloads a module from a content script [undoes loadInBrowser()]
//	see loadInBrowser()
// loadInWindow(aWindow, aModule) - loads a module into all the content scripts of a specified window
//	aWindow - (xul element) navigator window of which all content scripts will have the module loaded into
//	see loadInBrowser()
// unloadFromWindow(aWindow, aModule) - unloads a module from all the content scripts of a window [undoes loadInWindow()]
//	see loadInWindow()
// loadInAll(aModule) - loads a module into all content scripts
//	see loadInBrowser()
// unloadFromAll(aModule) - unloads a module from all content scripts [undoes loadInAll()]
//	see loadInBrowser()
this.messenger = {
	loadedInAll: [],

	globalMM: Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager),

	messageBrowser: function(aBrowser, aMessage, aData, aCPOW) {
		if(!aBrowser || !aBrowser.messageManager) { return; }

		aBrowser.messageManager.sendAsyncMessage(objName+':'+aMessage, aData, aCPOW);
	},

	messageWindow: function(aWindow, aMessage, aData, aCPOW) {
		if(!aWindow || !aWindow.messageManager) { return; }

		aWindow.messageManager.broadcastAsyncMessage(objName+':'+aMessage, aData, aCPOW);
	},

	messageAll: function(aMessage, aData, aCPOW) {
		this.globalMM.broadcastAsyncMessage(objName+':'+aMessage, aData, aCPOW);
	},

	listenBrowser: function(aBrowser, aMessage, aListener) {
		if(!aBrowser || !aBrowser.messageManager) { return; }

		aBrowser.messageManager.addMessageListener(objName+':'+aMessage, aListener);
	},

	unlistenBrowser: function(aBrowser, aMessage, aListener) {
		if(!aBrowser || !aBrowser.messageManager) { return; }

		aBrowser.messageManager.removeMessageListener(objName+':'+aMessage, aListener);
	},

	listenWindow: function(aWindow, aMessage, aListener) {
		if(!aWindow || !aWindow.messageManager) { return; }

		aWindow.messageManager.addMessageListener(objName+':'+aMessage, aListener);
	},

	unlistenWindow: function(aWindow, aMessage, aListener) {
		if(!aWindow || !aWindow.messageManager) { return; }

		aWindow.messageManager.removeMessageListener(objName+':'+aMessage, aListener);
	},

	listenAll: function(aMessage, aListener) {
		this.globalMM.addMessageListener(objName+':'+aMessage, aListener);
	},

	unlistenAll: function(aMessage, aListener) {
		this.globalMM.removeMessageListener(objName+':'+aMessage, aListener);
	},

	loadInBrowser: function(aBrowser, aModule) {
		this.messageBrowser(aBrowser, 'load', aModule);
	},

	unloadFromBrowser: function(aBrowser, aModule) {
		this.messageBrowser(aBrowser, 'unload', aModule);
	},

	loadInWindow: function(aWindow, aModule) {
		if(aWindow.gBrowser && aWindow.gBrowser.tabContainer) {
			if(!aWindow.gBrowser.tabContainer[objName+'Content']) {
				aWindow.gBrowser.tabContainer[objName+'Content'] = {
					modules: [aModule],
					listener: function(e) {
						messenger.messageBrowser(e.target.linkedBrowser, 'reinit');
					}
				};
				aWindow.gBrowser.tabContainer.addEventListener('TabOpen', aWindow.gBrowser.tabContainer[objName+'Content'].listener, true);
			}
			else if(aWindow.gBrowser.tabContainer[objName+'Content'].modules.indexOf(aModule) == -1) {
				aWindow.gBrowser.tabContainer[objName+'Content'].modules.push(aModule);
			}
		}

		this.messageWindow(aWindow, 'load', aModule);
	},

	unloadFromWindow: function(aWindow, aModule) {
		if(aWindow.gBrowser && aWindow.gBrowser.tabContainer) {
			if(aWindow.gBrowser.tabContainer[objName+'Content'] && aWindow.gBrowser.tabContainer[objName+'Content'].modules.indexOf(aModule) != -1) {
				aWindow.gBrowser.tabContainer[objName+'Content'].modules.splice(aWindow.gBrowser.tabContainer[objName+'Content'].modules.indexOf(aModule), 1);
				if(aWindow.gBrowser.tabContainer[objName+'Content'].modules.length == 0) {
					aWindow.gBrowser.tabContainer.removeEventListener('TabOpen', aWindow.gBrowser.tabContainer[objName+'Content'].listener, true);
					delete aWindow.gBrowser.tabContainer[objName+'Content'];
				}
			}
		}

		this.messageWindow(aWindow, 'unload', aModule);
	},

	loadInAll: function(aModule) {
		if(this.loadedInAll.indexOf(aModule) != -1) { return; }
		this.loadedInAll.push(aModule);

		this.messageAll('load', aModule);
	},

	unloadFromAll: function(aModule) {
		if(this.loadedInAll.indexOf(aModule) == -1) { return; }
		this.loadedInAll.splice(this.loadedInAll.indexOf(aModule), 1);

		this.messageAll('unload', aModule);
	},

	initContent: function(m) {
		// if this is a preloaded browser, we don't need to load in it, the content script will still be loaded in the actual tab's browser
		if(m.target.parentNode.localName == 'window' && m.target.parentNode.id == 'win') { return; }

		// can't stringify AddonData directly, because it contains an nsIFile instance (installPath) and an nsIURI instance (resourceURI)
		var carryData = {
			id: AddonData.id,
			initTime: AddonData.initTime,
			version: AddonData.version,
			oldVersion: AddonData.oldVersion,
			newVersion: AddonData.newVersion
		};
		messenger.messageBrowser(m.target, 'init', JSON.stringify(carryData));

		// carry the preferences current values into content
		var current = {};
		for(var pref in prefList) {
			if(pref.startsWith('NoSync_')) { continue; }
			current[pref] = prefAid[pref];
		}
		messenger.messageBrowser(m.target, 'pref', current);

		// load into this browser all the content modules that should be loaded in all content scripts
		for(var module of messenger.loadedInAll) {
			messenger.messageBrowser(m.target, 'load', module);
		}

		// load into this browser all the content modules that should be loaded into content scripts of this window
		if(m.target.ownerGlobal.gBrowser && m.target.ownerGlobal.gBrowser.tabContainer && m.target.ownerGlobal.gBrowser.tabContainer[objName+'Content']) {
			for(var module of m.target.ownerGlobal.gBrowser.tabContainer[objName+'Content'].modules) {
				messenger.messageBrowser(m.target, 'load', module);
			}
		}
	},

	carryPref: function(pref, val) {
		if(pref.startsWith('NoSync_')) { return; }

		var carry = {};
		carry[pref] = val;
		messenger.messageAll('pref', carry);
	},

	cleanWindow: function(aWindow) {
		if(aWindow.gBrowser && aWindow.gBrowser.tabContainer && aWindow.gBrowser.tabContainer[objName+'Content']) {
			aWindow.gBrowser.tabContainer.removeEventListener('TabOpen', aWindow.gBrowser.tabContainer[objName+'Content'].listener, true);
			delete aWindow.gBrowser.tabContainer[objName+'Content'];
		}
	}
};

moduleAid.LOADMODULE = function() {
	messenger.listenAll('init', messenger.initContent);
	messenger.globalMM.loadFrameScript('resource://'+objPathString+'/modules/utils/content.js?'+AddonData.initTime, true);

	for(var pref in prefList) {
		if(pref.startsWith('NoSync_')) { continue; }

		prefAid.listen(pref, messenger.carryPref);
	}
};

moduleAid.UNLOADMODULE = function() {
	messenger.unlistenAll('init', messenger.initContent);

	for(var pref in prefList) {
		if(pref.startsWith('NoSync_')) { continue; }

		prefAid.unlisten(pref, messenger.carryPref);
	}

	windowMediator.callOnAll(messenger.cleanWindow, 'navigator:browser');

	messenger.globalMM.removeDelayedFrameScript('resource://'+objPathString+'/modules/utils/content.js?'+AddonData.initTime);
	messenger.messageAll('shutdown');
};
<|endoftext|>


<commit_before>var regex = {
	AE:/\Wae\W|add|follow|manage|curat(e|or)|invite|f4f|^projects$|(big(gest)?|large(st)?|huge(st)?) (studio|gallery)|(as|how) (many|much)|feed (me|us)|(can (i|we)|help (me|us)) (get( to)?|reach|add)|(get( to)?|reach|add|need) (\d+|every|any|all)? ?(thing|body|one|projects)|(every|any)thing|\d+ project/gi,
	notAE:/only|quality|good|awesome|fantastic|great|amazing|test|science|math|programming|computer|tech|info|advice/gi,
	extras:null,
	set:function(r){this.extras=new RegExp(r,"gi");},
	test:function(str){if(this.notAE.test(str))return 0;if(this.AE.test(str))return 1;if(this.extras && regex.extras.test(str))return 2;return 0;}
};
<commit_msg>Greedy-be-gone<commit_after>var regex = {
	AE:/\Wae\W|add|follow|manage|curat(e|or)|invite|f4f|^projects$|(big(gest)?|large(st)?|huge(st)?) (studio|gallery)|(as|how) (many|much)|feed (me|us)|(can (i|we)|help (me|us)) (get( to)?|reach|add)|(get( to)?|reach|add|need) (\d+|every|any|all)? ?(thing|body|one|projects)|(every|any)thing|\d+ project/gi,
	notAE:/only|quality|simple|good|awesome|fantastic|great|amazing|test|science|math|programming|computer|tech|info|advice/gi,
	extras:null,
	set:function(r){if(r)this.extras=new RegExp(r,"gi");},
	test:function(str){if(this.notAE.test(str))return 0;if(this.AE.test(str))return 1;if(this.extras && regex.extras.test(str))return 2;return 0;}
};
<|endoftext|>


<commit_before>// This function makes it so that when a practice area is clicked, an active class is set.  After, the function removes the active class from all other practice areas.

$(function() {
    $(".pa-1").click(function() {
       $(".pa-1").addClass('pa-button-active');
       si = 1;
       for (var i = 1; i < 19; i++) {
          if (i === 1) {
            $(".si-1").fadeIn(1500).text("what's good tho");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-2").click(function() {
       $(".pa-2").addClass('pa-button-active');
       si = 2;
       for (var i = 1; i < 19; i++) {
          if (i === 2) {
            $(".si-2").fadeIn(1500).text("not much tho");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-3").click(function() {
       $(".pa-3").addClass('pa-button-active');
       si = 3;
       for (var i = 1; i < 19; i++) {
          if (i === 3) {
            $(".si-3").fadeIn(1500).text("lmao ok");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-4").click(function() {
       $(".pa-4").addClass('pa-button-active');
       si = 4;
       for (var i = 1; i < 19; i++) {
          if (i === 4) {
             continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
       }
    });
 });

 $(function() {
    $(".pa-5").click(function() {
       $(".pa-5").addClass('pa-button-active');
       si = 5;
       for (var i = 1; i < 19; i++) {
          if (i === 5) {
             continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
       }
    });
 });

 $(function() {
    $(".pa-6").click(function() {
       $(".pa-6").addClass('pa-button-active');
       si = 6;
       for (var i = 1; i < 19; i++) {
          if (i === 6) {
             continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
       }
    });
 });

 $(function() {
    $(".pa-7").click(function() {
       $(".pa-7").addClass('pa-button-active');
       si = 7;
       for (var i = 1; i < 19; i++) {
          if (i === 7) {
             continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
       }
    });
 });

 $(function() {
    $(".pa-8").click(function() {
       $(".pa-8").addClass('pa-button-active');
       si = 8;
       for (var i = 1; i < 19; i++) {
          if (i === 8) {
             continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
       }
    });
 });

 $(function() {
    $(".pa-9").click(function() {
       $(".pa-9").addClass('pa-button-active');
       si = 9;
       for (var i = 1; i < 19; i++) {
          if (i === 9) {
             continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
       }
    });
 });

 $(function() {
    $(".pa-10").click(function() {
       $(".pa-10").addClass('pa-button-active');
       si = 10;
       for (var i = 1; i < 19; i++) {
          if (i === 10) {
             continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
       }
    });
 });

 $(function() {
    $(".pa-11").click(function() {
       $(".pa-11").addClass('pa-button-active');
       si = 11;
       for (var i = 1; i < 19; i++) {
          if (i === 11) {
             continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
       }
    });
 });

 $(function() {
    $(".pa-12").click(function() {
       $(".pa-12").addClass('pa-button-active');
       si = 12;
       for (var i = 1; i < 19; i++) {
          if (i === 12) {
             continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
       }
    });
 });

 $(function() {
    $(".pa-13").click(function() {
       $(".pa-13").addClass('pa-button-active');
       si = 13;
       for (var i = 1; i < 19; i++) {
          if (i === 13) {
             continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
       }
    });
 });

 $(function() {
    $(".pa-14").click(function() {
       $(".pa-14").addClass('pa-button-active');
       si = 14;
       for (var i = 1; i < 19; i++) {
          if (i === 14) {
             continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
       }
    });
 });

 $(function() {
    $(".pa-15").click(function() {
       $(".pa-15").addClass('pa-button-active');
       si = 15;
       for (var i = 1; i < 19; i++) {
          if (i === 15) {
             continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
       }
    });
 });

 $(function() {
    $(".pa-16").click(function() {
       $(".pa-16").addClass('pa-button-active');
       si = 16;
       for (var i = 1; i < 19; i++) {
          if (i === 16) {
             continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
       }
    });
 });

 $(function() {
    $(".pa-17").click(function() {
       $(".pa-17").addClass('pa-button-active');
       si = 17;
       for (var i = 1; i < 19; i++) {
          if (i === 17) {
             continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
       }
    });
 });

 $(function() {
    $(".pa-18").click(function() {
       $(".pa-18").addClass('pa-button-active');
       si = 18;
       for (var i = 1; i < 19; i++) {
          if (i === 18) {
             continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
       }
    });
 });
 <commit_msg>updating pa.js<commit_after>// This function makes it so that when a practice area is clicked, an active class is set.  After, the function removes the active class from all other practice areas.

$(function() {
    $(".pa-1").click(function() {
       $(".pa-1").addClass('pa-button-active');
       si = 1;
       for (var i = 1; i < 19; i++) {
          if (i === 1) {
            $(".si-1").fadeIn(1500).text("This is some filler information about sub-practice area 1.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-2").click(function() {
       $(".pa-2").addClass('pa-button-active');
       si = 2;
       for (var i = 1; i < 19; i++) {
          if (i === 2) {
            $(".si-2").fadeIn(1500).text("This is some filler information about sub-practice area 2.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-3").click(function() {
       $(".pa-3").addClass('pa-button-active');
       si = 3;
       for (var i = 1; i < 19; i++) {
          if (i === 3) {
            $(".si-3").fadeIn(1500).text("This is some filler information about sub-practice area 3.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-4").click(function() {
       $(".pa-4").addClass('pa-button-active');
       si = 4;
       for (var i = 1; i < 19; i++) {
          if (i === 4) {
            $(".si-4").fadeIn(1500).text("This is some filler information about sub-practice area 4.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-5").click(function() {
       $(".pa-5").addClass('pa-button-active');
       si = 5;
       for (var i = 1; i < 19; i++) {
          if (i === 5) {
            $(".si-5").fadeIn(1500).text("This is some filler information about sub-practice area 5.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-6").click(function() {
       $(".pa-6").addClass('pa-button-active');
       si = 6;
       for (var i = 1; i < 19; i++) {
          if (i === 6) {
            $(".si-6").fadeIn(1500).text("This is some filler information about sub-practice area 6.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-7").click(function() {
       $(".pa-7").addClass('pa-button-active');
       si = 7;
       for (var i = 1; i < 19; i++) {
          if (i === 7) {
            $(".si-7").fadeIn(1500).text("This is some filler information about sub-practice area 7.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-8").click(function() {
       $(".pa-8").addClass('pa-button-active');
       si = 8;
       for (var i = 1; i < 19; i++) {
          if (i === 8) {
            $(".si-8").fadeIn(1500).text("This is some filler information about sub-practice area 8.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-9").click(function() {
       $(".pa-9").addClass('pa-button-active');
       si = 9;
       for (var i = 1; i < 19; i++) {
          if (i === 9) {
            $(".si-9").fadeIn(1500).text("This is some filler information about sub-practice area 9.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-10").click(function() {
       $(".pa-10").addClass('pa-button-active');
       si = 10;
       for (var i = 1; i < 19; i++) {
          if (i === 10) {
            $(".si-10").fadeIn(1500).text("This is some filler information about sub-practice area 10.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-11").click(function() {
       $(".pa-11").addClass('pa-button-active');
       si = 11;
       for (var i = 1; i < 19; i++) {
          if (i === 11) {
            $(".si-11").fadeIn(1500).text("This is some filler information about sub-practice area 11.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-12").click(function() {
       $(".pa-12").addClass('pa-button-active');
       si = 12;
       for (var i = 1; i < 19; i++) {
          if (i === 12) {
            $(".si-12").fadeIn(1500).text("This is some filler information about sub-practice area 12.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-13").click(function() {
       $(".pa-13").addClass('pa-button-active');
       si = 13;
       for (var i = 1; i < 19; i++) {
          if (i === 13) {
            $(".si-13").fadeIn(1500).text("This is some filler information about sub-practice area 13.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-14").click(function() {
       $(".pa-14").addClass('pa-button-active');
       si = 14;
       for (var i = 1; i < 19; i++) {
          if (i === 14) {
            $(".si-14").fadeIn(1500).text("This is some filler information about sub-practice area 14.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-15").click(function() {
       $(".pa-15").addClass('pa-button-active');
       si = 15;
       for (var i = 1; i < 19; i++) {
          if (i === 15) {
            $(".si-15").fadeIn(1500).text("This is some filler information about sub-practice area 15.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-16").click(function() {
       $(".pa-16").addClass('pa-button-active');
       si = 16;
       for (var i = 1; i < 19; i++) {
          if (i === 16) {
            $(".si-16").fadeIn(1500).text("This is some filler information about sub-practice area 16.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-17").click(function() {
       $(".pa-17").addClass('pa-button-active');
       si = 17;
       for (var i = 1; i < 19; i++) {
          if (i === 17) {
            $(".si-17").fadeIn(1500).text("This is some filler information about sub-practice area 17.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });

 $(function() {
    $(".pa-18").click(function() {
       $(".pa-18").addClass('pa-button-active');
       si = 18;
       for (var i = 1; i < 19; i++) {
          if (i === 18) {
            $(".si-18").fadeIn(1500).text("This is some filler information about sub-practice area 18.  This will be filled with actual, relevant information in the future.  For now, however, all of the content contained within this row is simply irrelevant and serves no purpose other than to test out my code and how it will look.  This particular JavaScript file that I wrote is called pa.js.  The p stands for practice and the a stands for area.  For loops, as well as if statements are very useful.  This is enough text.");
            continue;
          }
          $(".pa-" + i).removeClass('pa-button-active');
          $(".si-" + i).hide();
       }
    });
 });
 <|endoftext|>


<commit_before>/**
 * ui.js base file.
 * @module ui.js
 */

 /**
 The class that holds the variables and functions created in the namespace of this file.
 The constrcutor of this object is only called once, because it is an anonymous function.

 Some of the functions defined in this class are later added to the MARKUS global object and can
 from that point on be called as `markus.ui.FUNCTION_NAME`

 @class ui.js_anonymous
 @constructor
 @param {Object}  _m a reference to the Markus Configuration Object is passed
 **/
( function(_m) {

/*
  require keypress.js
*/
/**
 * Create a new keyPress listener that listens to all keypresses in the whole window,
 * regardless of focus element. This object holds that listener
 *
 * @for UI
 * @property listener
 * @type {Listener}
 */
var listener = new window.keypress.Listener();

//Define the CTRL+S = save keyPresss
listener.simple_combo("meta s", function() {
    $("#save").trigger("click");
});
//Define the CTRL+' = edit document keyPress
listener.simple_combo("meta '", function() {
    $("#editDocBtn").trigger("click");
});
//Define the CTRL+J = show modal keypress
listener.simple_combo("meta j", function() {
    $("#showGotoModalBtn").trigger("click");
});
//Define the CTRL+D = Go through all the markups and remove them??
listener.simple_combo("meta d", function() {
    if ($('#popover').hasClass('in')){
        var countIndex = -1;
        var nextIndex = -1;
        var markups = $(".doc .markup");
        markups.each(function(){countIndex++; if ($(this).hasClass("selected")){nextIndex = countIndex +1}});
        $('#popover .glyphicon-trash').trigger("click");
        var obj = $(markups[nextIndex]);
        $(obj).trigger("click");
        if (!$(obj).isOnScreen()){
            $('html, body').animate({
                scrollTop: $(obj).offset().top - 100
            }, 200);
        }
    }
});

listener.simple_combo("meta =", function() {

    var fontSize = $(".doc pre").css('font-size');

    if (fontSize){
        fontSize = parseInt(fontSize + 10);

    } else {
        fontSize = "110";
    }
    $(".doc pre").css('font-size',fontSize+"%");
    return false;
});

listener.simple_combo("meta -", function() {
    var fontSize = $(".doc pre").css('font-size');
    if (fontSize){

        fontSize = Math.max(10,parseInt(fontSize + 10));

    } else {
        fontSize = "90";

    }
    $(".doc pre").css('font-size',fontSize+"%");
    return false;
});

/**
 * This method will transfer your focus from the currently selected markup instance
 * to the next one in the document with the same type.
 *
 * @for ui.js_anonymous
 * @method nextSameTypeMarkup
 */
function nextSameTypeMarkup(){
    //If there is an element selected we can find the next markup type
    if ($(".selected").length > 0){
      var countIndex = -1;
      var nextIndex = -1;

      //find the type of the markup we have selected right now
      var type = $(".doc .selected").attr("type");
      //get all the markups of that type
      var markups = $(".doc .markup."+type);

      //For each of the markups, find the one that is next to the selected one
      markups.each(function(){countIndex++; if ($(this).hasClass("selected")){nextIndex = countIndex +1}});

      //If the length is not longer than the array length
      if (markups.length > nextIndex) {
          //retrieve the markup that is the next one to the one we have currently selected
          var obj = $(markups[nextIndex]);
          //Trigger a click on it
          $(obj).trigger("click");
          //If it is not on screen yet, we animat to it
          if (!$(obj).isOnScreen()){
              $('html, body').animate({
                  scrollTop: $(obj).offset().top - 100
              }, 200);
          }
      }
    //If we have nothing selected, but we do have markup, we go to the first markup instance
    } else if ($(".doc .markup").length > 0){
      $($(".doc .markup")[0]).trigger("click");
    }
}

/**
 * Finds the next markup after the currently selected markup instance and will transfer
 * the focus by generating a click on the next element. This is markup_type agnostic.
 *
 * @for ui.js_anonymous
 * @method nextMarkup
 * @param  {Boolean} _sameType This Parameter is currently unused. TODO: Remove it, or fix it
 */
function nextMarkup(_sameType){
  //If we have an element selected, we start to look for the next element
  if ($(".selected").length > 0){
    var countIndex = -1;
    var nextIndex = -1;

    //Find all the generic markups
    var markups = $(".doc .markup");
    //Go through all of the markups and find the one that is selected, find the one after that
    markups.each(function(){countIndex++; if ($(this).hasClass("selected")){nextIndex = countIndex +1}});

    //Check if the nextIndex is actually a valid index in the array (index < array.length)
    if (markups.length > nextIndex) {
        //get the objet that must be the next markup
        var obj = $(markups[nextIndex]);
        //trigger a click on it
        $(obj).trigger("click");

        //and if it is not onscreen, smoothly scroll to it now
        if (!$(obj).isOnScreen()){
            $('html, body').animate({
                scrollTop: $(obj).offset().top - 100
            }, 200);
        }
    }
  //If we don't have any element selected, we just go to the first markup element and
  //trigger a click on it
  } else if ($(".doc .markup").length > 0){
    $($(".doc .markup")[0]).trigger("click");
  }
}

/**
 * Finds the previous markup before the currently selected markup instance and will transfer
 * the focus by generating a click on the previous element. This is markup_type agnostic.
 *
 * @for ui.js_anonymous
 * @method lastMarkup
 */
function lastMarkup(){
  //If we currently have something selected
  if ($(".selected").length > 0){
    var countIndex = -1;
    var nextIndex = -1;
    //Find all the markups in the document
    var markups = $(".doc .markup");

    //Go through all the markups and find the one that is the selected, go back one after that
    markups.each(function(){countIndex++; if ($(this).hasClass("selected")){nextIndex = countIndex -1}});
    //Check if that index is valid
    if (nextIndex > -1) {
        //Get the object at that index
        var obj = $(markups[nextIndex]);
        //Trigger a click on this markup
        $(obj).trigger("click");

        //If it is not currently onScreen, smoothly scroll to it
        if (!$(obj).isOnScreen()){
            $('html, body').animate({
                scrollTop: $(obj).offset().top - 100
            }, 200);
        }
    }
    //IF there is no current selection, we just focus on the first markup instance
  }else if ($(".doc .markup").length > 0){
    $($(".doc .markup")[0]).trigger("click");
  }
}

/**
 * Finds the previous markup before the currently selected markup instance and will transfer
 * the focus by generating a click on the previous element. This will only go through the instances
 * of the same markup_type.
 *
 * @for ui.js_anonymous
 * @method lastSameTypeMarkup
 */
function lastSameTypeMarkup(){
  //If we currently have an element selected
  if ($(".selected").length > 0){
    var countIndex = -1;
    var nextIndex = -1;
    //Find the type of the markup
    var type = $(".doc .selected").attr("type");
    //Find all the markups of that type
    var markups = $(".doc .markup."+type)

    //Go through all of them, find the selected one. go back one index to find the previous markup.
    markups.each(function(){countIndex++; if ($(this).hasClass("selected")){nextIndex = countIndex -1}});

    //If this is still a valid array index
    if (nextIndex > -1) {
        //Get the markup from the array
        var obj = $(markups[nextIndex]);
        //trigger a click on it
        $(obj).trigger("click");

        //If the markup is not on screen, smoothly scroll to it
        if (!$(obj).isOnScreen()){
            $('html, body').animate({
                scrollTop: $(obj).offset().top - 100
            }, 200);
        }
    }
    //If we didn't have anything selected right now
  }else if ($(".doc .markup").length > 0){
    //Just trigger a click on the first markup
    $($(".doc .markup")[0]).trigger("click");
  }
}

//Define that CTRL+RIGHT = goto next markup in the document
listener.register_combo({
    "keys"              : "meta right",
    "on_keyup"          : nextMarkup,
    "prevent_default"   : true,
    "is_exclusive"      : true
});

//Define that CTRL+SHIFT+RIGHT = goto next markup with same type in the document
listener.register_combo({
    "keys"              : "meta shift right",
    "on_keyup"          : nextSameTypeMarkup,
    "prevent_default"   : true,
    "is_exclusive"      : true
});
//Define that CTRL+LEFT = goto previous markup in the document
listener.register_combo({
    "keys"              : "meta left",
    "on_keyup"          : lastMarkup,
    "prevent_default"   : true,
    "is_exclusive"      : true
});
//Define that CTRL+SHIFT+LEFT = goto previous markup with same type in the document
listener.register_combo({
    "keys"              : "meta shift left",
    "on_keyup"          : lastSameTypeMarkup,
    "prevent_default"   : true,
    "is_exclusive"      : true
});

/**
 * Creates the markus.ui object and associates its member varaible listener with
 * the predefined listener variable from the ui.js_anonymous class. You can use this
 * class to gain access to the keyPress listener that was registered here.
 *
 * @class UI
 */
_m.ui = {
    listener: listener,
};

} )(markus);
<commit_msg>Bugs UI module overwrited<commit_after>/**
 * ui.js base file.
 * @module ui.js
 */

 /**
 The class that holds the variables and functions created in the namespace of this file.
 The constrcutor of this object is only called once, because it is an anonymous function.

 Some of the functions defined in this class are later added to the MARKUS global object and can
 from that point on be called as `markus.ui.FUNCTION_NAME`

 @class ui.js_anonymous
 @constructor
 @param {Object}  _m a reference to the Markus Configuration Object is passed
 **/
( function(_m) {

/*
  require keypress.js
*/
/**
 * Create a new keyPress listener that listens to all keypresses in the whole window,
 * regardless of focus element. This object holds that listener
 *
 * @for UI
 * @property listener
 * @type {Listener}
 */
var listener = new window.keypress.Listener();

//Define the CTRL+S = save keyPresss
listener.simple_combo("meta s", function() {
    $("#save").trigger("click");
});
//Define the CTRL+' = edit document keyPress
listener.simple_combo("meta '", function() {
    $("#editDocBtn").trigger("click");
});
//Define the CTRL+J = show modal keypress
listener.simple_combo("meta j", function() {
    $("#showGotoModalBtn").trigger("click");
});
//Define the CTRL+D = Go through all the markups and remove them??
listener.simple_combo("meta d", function() {
    if ($('#popover').hasClass('in')){
        var countIndex = -1;
        var nextIndex = -1;
        var markups = $(".doc .markup");
        markups.each(function(){countIndex++; if ($(this).hasClass("selected")){nextIndex = countIndex +1}});
        $('#popover .glyphicon-trash').trigger("click");
        var obj = $(markups[nextIndex]);
        $(obj).trigger("click");
        if (!$(obj).isOnScreen()){
            $('html, body').animate({
                scrollTop: $(obj).offset().top - 100
            }, 200);
        }
    }
});

listener.simple_combo("meta =", function() {

    var fontSize = $(".doc pre").css('font-size');

    if (fontSize){
        fontSize = parseInt(fontSize) + 1;

    } else {
        fontSize = "14";

    }
    $(".doc pre").css('font-size',fontSize+"px");
    return false;
});

listener.simple_combo("meta -", function() {

    var fontSize = $(".doc pre").css('font-size');
    if (fontSize){
        fontSize = Math.max(10,parseInt(fontSize) - 1);

    } else {
        fontSize = "12";

    }
    $(".doc pre").css('font-size',fontSize+"px");
    return false;
});

/**
 * This method will transfer your focus from the currently selected markup instance
 * to the next one in the document with the same type.
 *
 * @for ui.js_anonymous
 * @method nextSameTypeMarkup
 */
function nextSameTypeMarkup(){
    //If there is an element selected we can find the next markup type
    if ($(".selected").length > 0){
      var countIndex = -1;
      var nextIndex = -1;

      //find the type of the markup we have selected right now
      var type = $(".doc .selected").attr("type");
      //get all the markups of that type
      var markups = $(".doc .markup."+type);

      //For each of the markups, find the one that is next to the selected one
      markups.each(function(){countIndex++; if ($(this).hasClass("selected")){nextIndex = countIndex +1}});

      //If the length is not longer than the array length
      if (markups.length > nextIndex) {
          //retrieve the markup that is the next one to the one we have currently selected
          var obj = $(markups[nextIndex]);
          //Trigger a click on it
          $(obj).trigger("click");
          //If it is not on screen yet, we animat to it
          if (!$(obj).isOnScreen()){
              $('html, body').animate({
                  scrollTop: $(obj).offset().top - 100
              }, 200);
          }
      }
    //If we have nothing selected, but we do have markup, we go to the first markup instance
    } else if ($(".doc .markup").length > 0){
      $($(".doc .markup")[0]).trigger("click");
    }
}

/**
 * Finds the next markup after the currently selected markup instance and will transfer
 * the focus by generating a click on the next element. This is markup_type agnostic.
 *
 * @for ui.js_anonymous
 * @method nextMarkup
 * @param  {Boolean} _sameType This Parameter is currently unused. TODO: Remove it, or fix it
 */
function nextMarkup(_sameType){
  //If we have an element selected, we start to look for the next element
  if ($(".selected").length > 0){
    var countIndex = -1;
    var nextIndex = -1;

    //Find all the generic markups
    var markups = $(".doc .markup");
    //Go through all of the markups and find the one that is selected, find the one after that
    markups.each(function(){countIndex++; if ($(this).hasClass("selected")){nextIndex = countIndex +1}});

    //Check if the nextIndex is actually a valid index in the array (index < array.length)
    if (markups.length > nextIndex) {
        //get the objet that must be the next markup
        var obj = $(markups[nextIndex]);
        //trigger a click on it
        $(obj).trigger("click");

        //and if it is not onscreen, smoothly scroll to it now
        if (!$(obj).isOnScreen()){
            $('html, body').animate({
                scrollTop: $(obj).offset().top - 100
            }, 200);
        }
    }
  //If we don't have any element selected, we just go to the first markup element and
  //trigger a click on it
  } else if ($(".doc .markup").length > 0){
    $($(".doc .markup")[0]).trigger("click");
  }
}

/**
 * Finds the previous markup before the currently selected markup instance and will transfer
 * the focus by generating a click on the previous element. This is markup_type agnostic.
 *
 * @for ui.js_anonymous
 * @method lastMarkup
 */
function lastMarkup(){
  //If we currently have something selected
  if ($(".selected").length > 0){
    var countIndex = -1;
    var nextIndex = -1;
    //Find all the markups in the document
    var markups = $(".doc .markup");

    //Go through all the markups and find the one that is the selected, go back one after that
    markups.each(function(){countIndex++; if ($(this).hasClass("selected")){nextIndex = countIndex -1}});
    //Check if that index is valid
    if (nextIndex > -1) {
        //Get the object at that index
        var obj = $(markups[nextIndex]);
        //Trigger a click on this markup
        $(obj).trigger("click");

        //If it is not currently onScreen, smoothly scroll to it
        if (!$(obj).isOnScreen()){
            $('html, body').animate({
                scrollTop: $(obj).offset().top - 100
            }, 200);
        }
    }
    //IF there is no current selection, we just focus on the first markup instance
  }else if ($(".doc .markup").length > 0){
    $($(".doc .markup")[0]).trigger("click");
  }
}

/**
 * Finds the previous markup before the currently selected markup instance and will transfer
 * the focus by generating a click on the previous element. This will only go through the instances
 * of the same markup_type.
 *
 * @for ui.js_anonymous
 * @method lastSameTypeMarkup
 */
function lastSameTypeMarkup(){
  //If we currently have an element selected
  if ($(".selected").length > 0){
    var countIndex = -1;
    var nextIndex = -1;
    //Find the type of the markup
    var type = $(".doc .selected").attr("type");
    //Find all the markups of that type
    var markups = $(".doc .markup."+type)

    //Go through all of them, find the selected one. go back one index to find the previous markup.
    markups.each(function(){countIndex++; if ($(this).hasClass("selected")){nextIndex = countIndex -1}});

    //If this is still a valid array index
    if (nextIndex > -1) {
        //Get the markup from the array
        var obj = $(markups[nextIndex]);
        //trigger a click on it
        $(obj).trigger("click");

        //If the markup is not on screen, smoothly scroll to it
        if (!$(obj).isOnScreen()){
            $('html, body').animate({
                scrollTop: $(obj).offset().top - 100
            }, 200);
        }
    }
    //If we didn't have anything selected right now
  }else if ($(".doc .markup").length > 0){
    //Just trigger a click on the first markup
    $($(".doc .markup")[0]).trigger("click");
  }
}

//Define that CTRL+RIGHT = goto next markup in the document
listener.register_combo({
    "keys"              : "meta right",
    "on_keyup"          : nextMarkup,
    "prevent_default"   : true,
    "is_exclusive"      : true
});

//Define that CTRL+SHIFT+RIGHT = goto next markup with same type in the document
listener.register_combo({
    "keys"              : "meta shift right",
    "on_keyup"          : nextSameTypeMarkup,
    "prevent_default"   : true,
    "is_exclusive"      : true
});
//Define that CTRL+LEFT = goto previous markup in the document
listener.register_combo({
    "keys"              : "meta left",
    "on_keyup"          : lastMarkup,
    "prevent_default"   : true,
    "is_exclusive"      : true
});
//Define that CTRL+SHIFT+LEFT = goto previous markup with same type in the document
listener.register_combo({
    "keys"              : "meta shift left",
    "on_keyup"          : lastSameTypeMarkup,
    "prevent_default"   : true,
    "is_exclusive"      : true
});

/**
 * Creates the markus.ui object and associates its member varaible listener with
 * the predefined listener variable from the ui.js_anonymous class. You can use this
 * class to gain access to the keyPress listener that was registered here.
 *
 * @class UI
 */

 if (_m.ui == null) {
    _m.ui = {};
 }
_m.ui.listener = listener;

} )(markus);
<|endoftext|>


<commit_before>!function() {

	navigator.getMedia = navigator.getUserMedia ||
		navigator.webkitGetUserMedia ||
		navigator.mozGetUserMedia ||
		navigator.msGetUserMedia;

	var imgCanvas = document.createElement('canvas');
	var imgCtx = imgCanvas.getContext('2d');
	var videoCanvas = document.createElement('canvas');
	var videoCtx = videoCanvas.getContext('2d');

	var videoWidth, videoHeight, video, container, stream, videoTimer;

	/**
	 * value to character mapping from dark to light
	 * add more characters and they will be accounted for automatically
	 * note: the extra   is to account for the value range inclusive of 100%
	 */
	var chars = ['@','#','$','=','*','!',';',':','~','-',',','.',' ', ' '];
	var charLen = chars.length-1;
	function getChar(val) { return chars[parseInt(val*charLen, 10)]; }

	/**
	 * log when getUserMedia or when video metadata loading fail
	 */
	function logError(err) { if(console && console.log) console.log('Error!', err); return false; }

	/**
	 * Sets the video dimension (and subsequently ASCII string dimension)
	 */
	function setVideoDimension(width, height) {
		videoCanvas.width = videoWidth = width;
		videoCanvas.height = videoHeight = height;
	}

	/**
	 * given a video object and DOM element, render the ASCII string inside element
	 */
	function renderVideo(videoEl, containerEl) {
		if(typeof navigator.getMedia !== 'function') {
			var msg = 'Error: browser does not support getUserMedia';
			containerEl.innerHTML = msg;
			return logError(msg);
		}

		video = videoEl;
		container = containerEl;
		navigator.getMedia({video: true, audio: true}, function(localMediaStream){
			stream = localMediaStream;
			var url = window.URL || window.webkitURL;
			video.src = url.createObjectURL(localMediaStream);

			startRender(15);
			video.onloadedmetadata = logError;
		}, logError);
		return true;
	}

	/**
	 * gets video image data, perform ascii conversion, append string to container
	 */
	function startRender(interval) {
		if(typeof interval !== 'number') interval = 20;
		videoTimer = setInterval(function(){
			if(stream) {
				var w = videoWidth, h = videoHeight;
				videoCtx.drawImage(video, 0, 0, w, h);
				var data = videoCtx.getImageData(0, 0, w, h).data;
				container.innerHTML = getAsciiString(data, w, h);
			}
		}, interval);
	}

	/**
	 * Allow pause and play for ascii rendering
	 */
	function stopRender() { if(videoTimer) clearInterval(videoTimer); }

	/**
	 * given an image object and DOM element, render the ASCII string inside element
	 */
	function renderImage(image, container) {
		image.addEventListener('load', function(){
			var ratio = image.width/image.height;
			imgCanvas.width = w = 150;
			imgCanvas.height = h = w/ratio;
			imgCtx.drawImage(image, 0, 0, w, h);
			data = imgCtx.getImageData(0, 0, w, h).data;
			container.innerHTML = getAsciiString(data, w, h);
		});
	}

	/**
	 * helper function to retrieve rgb value from pixel data
	 * (pixel data is a 1-dimensional array of rgba sequence)
	 */
	function getRGB(d, i) { return [d[i=i*4], d[i+1], d[i+2]]; }

	/**
	 * given a picture/frame's pixel data and a defined width and height
	 * return the ASCII string representing the image
	 */
	function getAsciiString(d, width, height) {
		var len = width*height-1, str = '';
		for(var i=0; i<len; i++) {
			if(i%width === 0) str += '
';
			var rgb = getRGB(d, i);
			var val = Math.max(rgb[0], rgb[1], rgb[2])/255;
			//str += ''+getChar(val)+'';
			str += getChar(val);
		}
		return str;
	}

	/**
	 * default video dimension at 150 width and a 4:3 ratio
	 */
	setVideoDimension(150, parseInt(150*3/4, 10));

	window.Jscii = {
		setVideoDimension: setVideoDimension,
		renderVideo: renderVideo,
		startRender: startRender,
		stopRender: stopRender,
		renderImage: renderImage
	};

}();
<commit_msg>Fix stopRender function, added header<commit_after>/**
 * Jscii - Image to ASCII converter
 * http://enotionz.github.com/jscii/
 * Author: Dominick Pham (@enotionz | http://dph.am)
 */

!function() {

	navigator.getMedia = navigator.getUserMedia ||
		navigator.webkitGetUserMedia ||
		navigator.mozGetUserMedia ||
		navigator.msGetUserMedia;

	var imgCanvas = document.createElement('canvas');
	var imgCtx = imgCanvas.getContext('2d');
	var videoCanvas = document.createElement('canvas');
	var videoCtx = videoCanvas.getContext('2d');

	var videoWidth, videoHeight, video, container, stream, videoTimer;

	/**
	 * value to character mapping from dark to light
	 * add more characters and they will be accounted for automatically
	 * note: the extra   is to account for the value range inclusive of 100%
	 */
	var chars = ['@','#','$','=','*','!',';',':','~','-',',','.',' ', ' '];
	var charLen = chars.length-1;
	function getChar(val) { return chars[parseInt(val*charLen, 10)]; }

	/**
	 * log when getUserMedia or when video metadata loading fail
	 */
	function logError(err) { if(console && console.log) console.log('Error!', err); return false; }

	/**
	 * Sets the video dimension (and subsequently ASCII string dimension)
	 */
	function setVideoDimension(width, height) {
		videoCanvas.width = videoWidth = width;
		videoCanvas.height = videoHeight = height;
	}

	/**
	 * given a video object and DOM element, render the ASCII string inside element
	 */
	function renderVideo(videoEl, containerEl) {
		if(typeof navigator.getMedia !== 'function') {
			var msg = 'Error: browser does not support getUserMedia';
			containerEl.innerHTML = msg;
			return logError(msg);
		}

		video = videoEl;
		container = containerEl;
		navigator.getMedia({video: true, audio: true}, function(localMediaStream){
			stream = localMediaStream;
			var url = window.URL || window.webkitURL;
			video.src = url.createObjectURL(localMediaStream);

			startRender(15);
			video.onloadedmetadata = logError;
		}, logError);
		return true;
	}

	/**
	 * gets video image data, perform ascii conversion, append string to container
	 */
	function startRender(interval) {
		if(typeof interval !== 'number') interval = 20;
		stopRender();
		videoTimer = setInterval(function(){
			if(stream) {
				var w = videoWidth, h = videoHeight;
				videoCtx.drawImage(video, 0, 0, w, h);
				var data = videoCtx.getImageData(0, 0, w, h).data;
				container.innerHTML = getAsciiString(data, w, h);
			}
		}, interval);
	}

	/**
	 * Allow pause and play for ascii rendering
	 */
	function stopRender() { if(videoTimer) clearInterval(videoTimer); }

	/**
	 * given an image object and DOM element, render the ASCII string inside element
	 */
	function renderImage(image, container) {
		image.addEventListener('load', function(){
			var ratio = image.width/image.height;
			imgCanvas.width = w = 150;
			imgCanvas.height = h = w/ratio;
			imgCtx.drawImage(image, 0, 0, w, h);
			data = imgCtx.getImageData(0, 0, w, h).data;
			container.innerHTML = getAsciiString(data, w, h);
		});
	}

	/**
	 * helper function to retrieve rgb value from pixel data
	 * (pixel data is a 1-dimensional array of rgba sequence)
	 */
	function getRGB(d, i) { return [d[i=i*4], d[i+1], d[i+2]]; }

	/**
	 * given a picture/frame's pixel data and a defined width and height
	 * return the ASCII string representing the image
	 */
	function getAsciiString(d, width, height) {
		var len = width*height-1, str = '';
		for(var i=0; i<len; i++) {
			if(i%width === 0) str += '
';
			var rgb = getRGB(d, i);
			var val = Math.max(rgb[0], rgb[1], rgb[2])/255;
			//str += ''+getChar(val)+'';
			str += getChar(val);
		}
		return str;
	}

	/**
	 * default video dimension at 150 width and a 4:3 ratio
	 */
	setVideoDimension(150, parseInt(150*3/4, 10));

	window.Jscii = {
		setVideoDimension: setVideoDimension,
		renderVideo: renderVideo,
		startRender: startRender,
		stopRender: stopRender,
		renderImage: renderImage
	};

}();
<|endoftext|>


<commit_before>(function () {
    this.Kavie = function () {
        this.values = arguments[0];
        this.isActive = false;
    }

    Kavie.prototype.isValid = function () {
        var isValid = true;
        for (var i = 0; i < this.values.length; i++) {
            if (this.isKavieObservable(this.values[i])){
                this.values[i].startValidation();

                if (isValid) {
                    if (this.values[i].hasError()) {
                        isValid = false;
                    }
                }
            }
        }
        this.isActive = true;
        return isValid;
    }

    Kavie.prototype.isKavieObservable = function(observable){
      if (observable.hasError == null){
        return false;
      } else {
        return true;
      }
    }

    Kavie.prototype.deactivate = function () {
        for (var i = 0; i < this.values.length; i++) {
            this.values[i].stopValidation();
        }
        this.isActive = false;
    }

    Kavie.validatorFunctions = {
        required: function (propVal, eleVal) {
            if (propVal) {
                return (eleVal ? true : false);
            } else {
                return true;
            }
        },
        max: function (propVal, eleVal) {
          if (eleVal){
            return eleVal.length <= propVal;
          }
          return true; // if no value is found, it doesnt have a length. So thus it is less than the propVal
        },
        min: function (propVal, eleVal) {
          if (eleVal){
            return eleVal.length >= propVal;
          }
          return false; // opposite from above
        },
        date: function (propVal, eleVal) {
          if (eleVal){
            if (eleVal.length == 10) {
                if (new Date(eleVal) == "Invalid Date") {
                    return false;
                }
                return true;
            }
            return false;
          }
          return false; // noting is an invalid date
        },
        birthdate: function (propVal, eleVal) {
            // check to see if it is a valid date
            if (!Kavie.validatorFunctions.date(propVal, eleVal)) {
                return false;
            }

            var date = new Date(eleVal);

            // check to see if the date is in the future
            if (date > new Date()) {
                return false;
            }

            // check to see if date is a rational birthdate
            var minDateAllowed = new Date();
            minDateAllowed.setFullYear(minDateAllowed.getFullYear() - 120); // 120 is age of oldest person allodeewz5454ddeeha

            if (date < minDateAllowed) {
                return false;
            }

            return true;
        }
    }
    // functions to add:
    // numeric, regex pattern

}());

ko.extenders.kavie = function (target, rules) {
    target.hasError = ko.observable();

    target.rules = rules;

    function validate(newValue) {
        var rules = target.rules;

        for (key in rules) {
            for (funcKey in Kavie.validatorFunctions) {
                if (key == funcKey) {
                    var isValid = Kavie.validatorFunctions[funcKey](rules[key], newValue);
                    if (!isValid) {
                        target.hasError(true);
                        return;
                    }
                }
            }
        }

        target.hasError(false);
    }

    target.subscription;

    target.startValidation = function () {
        target.subscription = target.subscribe(validate);
        validate(target());
    }

    target.stopValidation = function () {
        target.subscription.dispose();
        target.hasError(false);
    }

    return target;
};
<commit_msg>Added addValue prototype method<commit_after>(function () {
    this.Kavie = function () {
        this.values = arguments[0];
        this.isActive = false;
    }

    Kavie.prototype.addValue = function(value){
      this.values.push(value);
    }

    Kavie.prototype.isValid = function () {
        var isValid = true;
        for (var i = 0; i < this.values.length; i++) {
            if (this.isKavieObservable(this.values[i])){
                this.values[i].startValidation();

                if (isValid) {
                    if (this.values[i].hasError()) {
                        isValid = false;
                    }
                }
            }
        }
        this.isActive = true;
        return isValid;
    }

    Kavie.prototype.isKavieObservable = function(observable){
      if (observable.hasError == null){
        return false;
      } else {
        return true;
      }
    }

    Kavie.prototype.deactivate = function () {
        for (var i = 0; i < this.values.length; i++) {
            this.values[i].stopValidation();
        }
        this.isActive = false;
    }

    Kavie.validatorFunctions = {
        required: function (propVal, eleVal) {
            if (propVal) {
                return (eleVal ? true : false);
            } else {
                return true;
            }
        },
        max: function (propVal, eleVal) {
          if (eleVal){
            return eleVal.length <= propVal;
          }
          return true; // if no value is found, it doesnt have a length. So thus it is less than the propVal
        },
        min: function (propVal, eleVal) {
          if (eleVal){
            return eleVal.length >= propVal;
          }
          return false; // opposite from above
        },
        date: function (propVal, eleVal) {
          if (eleVal){
            if (eleVal.length == 10) {
                if (new Date(eleVal) == "Invalid Date") {
                    return false;
                }
                return true;
            }
            return false;
          }
          return false; // noting is an invalid date
        },
        birthdate: function (propVal, eleVal) {
            // check to see if it is a valid date
            if (!Kavie.validatorFunctions.date(propVal, eleVal)) {
                return false;
            }

            var date = new Date(eleVal);

            // check to see if the date is in the future
            if (date > new Date()) {
                return false;
            }

            // check to see if date is a rational birthdate
            var minDateAllowed = new Date();
            minDateAllowed.setFullYear(minDateAllowed.getFullYear() - 120); // 120 is age of oldest person allodeewz5454ddeeha

            if (date < minDateAllowed) {
                return false;
            }

            return true;
        }
    }
    // functions to add:
    // numeric, regex pattern

}());

ko.extenders.kavie = function (target, rules) {
    target.hasError = ko.observable();

    target.rules = rules;

    function validate(newValue) {
        var rules = target.rules;

        for (key in rules) {
            for (funcKey in Kavie.validatorFunctions) {
                if (key == funcKey) {
                    var isValid = Kavie.validatorFunctions[funcKey](rules[key], newValue);
                    if (!isValid) {
                        target.hasError(true);
                        return;
                    }
                }
            }
        }

        target.hasError(false);
    }

    target.subscription;

    target.startValidation = function () {
        target.subscription = target.subscribe(validate);
        validate(target());
    }

    target.stopValidation = function () {
        target.subscription.dispose();
        target.hasError(false);
    }

    return target;
};
<|endoftext|>


<commit_before>/****** INIT CompConverter ******/
(function(){
    var isExportDirectoryCreated = false;
    var directoryCreationFailed = false;
    var compositionsList;
    var currentCompositionData;
    var filesDirectory;
    var mainProject = app.project;
    var scriptPath = ((File($.fileName)).path);
    var mainComp;
    var endCallback;

    var compositionData = {};

    function saveData(){
        if(!renderCancelled){
            var dataFile = new File(exportFolder.fullName+'/data.json');
            dataFile.open('w','TEXT','????');
            dataFile.write(JSON.stringify(compositionData)); //DO NOT ERASE, JSON UNFORMATTED
            //dataFile.write(JSON.stringify(compositionData, null, '  ')); //DO NOT ERASE, JSON FORMATTED
            dataFile.close();
        }
        currentCompositionData.rendered = true;
        searchNextComposition();
    }

    function layersConverted(duplicateMainComp){
        DOMAnimationManager.setCallback(saveData);
        //FOR DOM
        DOMAnimationManager.getCompositionAnimationData(duplicateMainComp,compositionData,filesDirectory);
    }

    function animationSaved(){
        saveData();
    }

    function directoryRemoved(){
        filesDirectory = new Folder(exportFolder.fullName+'/files');
        if(filesDirectory.create()){
            isExportDirectoryCreated = true;
        }
    }

    function createExportDirectory(){
        exportFolder = new Folder(currentCompositionData.destination+'/'+currentCompositionData.comp.name+'/');
        filesDirectory = new Folder(exportFolder.fullName+'/files');
        if(filesDirectory.exists){
            isExportDirectoryCreated = true;
        }else{
            if(filesDirectory.create()){
                isExportDirectoryCreated = true;
            }else{
                directoryCreationFailed = true;
            }
        }
    }

    function waitForDirectoryCreated(){
        if(isExportDirectoryCreated){
            start();
        }else if(directoryCreationFailed){
            alert(UITextsData.alertMessages.directoryCreationFailed);
        }else{
            $.sleep(100);
            waitForDirectoryCreated();
        }
    }

    function searchHelperRenderer(helperComp){
        var i=0,len = app.project.renderQueue.items.length;
        var item;
        while(i<len){
            item =  app.project.renderQueue.items[i+1];
            if(item.comp == helperComp){
                return item;
            }
            i++;
        }
    }

    function start(){
        UI.setExportText('Starting export');
        LayerConverter.convertComposition(mainComp);
    }

    function exportNextComposition(){
        isExportDirectoryCreated = false;
        directoryCreationFailed = false;
        mainComp = currentCompositionData.comp;
        createExportDirectory();
        waitForDirectoryCreated();
    }

    function searchNextComposition(){
        if(!renderCancelled){
            var len = compositionsList.length;
            var i = 0;
            while(i < len){
                if(compositionsList[i].queued === true && compositionsList[i].rendered == false){
                    currentCompositionData = compositionsList[i];
                    exportNextComposition();
                    return;
                }
                i+=1;
            }
        }
        //If it gets here there are no more compositions to render and callback is executed
        helperFootage.remove();
        endCallback.apply();
    }

    function renderCompositions(list){
        var helperFile = new File(scriptPath+'/helperProject.aep');
        var helperImportOptions = new ImportOptions();
        helperImportOptions.file = helperFile;
        helperFootage = mainProject.importFile(helperImportOptions);
        var helperFolder = helperFootage.item(2);
        var i = 0, len = helperFolder.items.length;
        while(i<len){
            if(helperFolder.item(i+1).name == 'helperSolidComp'){
                helperSolidComp = helperFolder.item(i+1);
            }
            i += 1;
        }
        helperSolid = helperSolidComp.layer(1);
        var helperPosition = helperSolid.transform["Anchor Point"];
        helperPosition.expression = "valueAtTime(time)";

        rqManager.setProject(app.project);
        LayerConverter.setCallback(layersConverted);
        compositionsList = list;
        len = compositionsList.length;
        for(i=0;i<len;i+=1){
            compositionsList[i].rendered = false;
        }
        searchNextComposition();
    }

    function setFinishCallback(cb){
        endCallback = cb;
    }

    var ob = {};
    ob.renderCompositions = renderCompositions;
    ob.setFinishCallback = setFinishCallback;

    CompConverter = ob;
}());
/****** END CompConverter ******/<commit_msg>exporting json single line<commit_after>/****** INIT CompConverter ******/
(function(){
    var isExportDirectoryCreated = false;
    var directoryCreationFailed = false;
    var compositionsList;
    var currentCompositionData;
    var filesDirectory;
    var mainProject = app.project;
    var scriptPath = ((File($.fileName)).path);
    var mainComp;
    var endCallback;

    var compositionData = {};

    function saveData(){
        if(!renderCancelled){
            var dataFile = new File(exportFolder.fullName+'/data.json');
            dataFile.open('w','TEXT','????');
            var string = JSON.stringify(compositionData);
            string = string.replace(/\n/g,'')  ;
            dataFile.write(string); //DO NOT ERASE, JSON UNFORMATTED
            //dataFile.write(JSON.stringify(compositionData, null, '  ')); //DO NOT ERASE, JSON FORMATTED
            dataFile.close();
        }
        currentCompositionData.rendered = true;
        searchNextComposition();
    }

    function layersConverted(duplicateMainComp){
        DOMAnimationManager.setCallback(saveData);
        //FOR DOM
        DOMAnimationManager.getCompositionAnimationData(duplicateMainComp,compositionData,filesDirectory);
    }

    function animationSaved(){
        saveData();
    }

    function directoryRemoved(){
        filesDirectory = new Folder(exportFolder.fullName+'/files');
        if(filesDirectory.create()){
            isExportDirectoryCreated = true;
        }
    }

    function createExportDirectory(){
        exportFolder = new Folder(currentCompositionData.destination+'/'+currentCompositionData.comp.name+'/');
        filesDirectory = new Folder(exportFolder.fullName+'/files');
        if(filesDirectory.exists){
            isExportDirectoryCreated = true;
        }else{
            if(filesDirectory.create()){
                isExportDirectoryCreated = true;
            }else{
                directoryCreationFailed = true;
            }
        }
    }

    function waitForDirectoryCreated(){
        if(isExportDirectoryCreated){
            start();
        }else if(directoryCreationFailed){
            alert(UITextsData.alertMessages.directoryCreationFailed);
        }else{
            $.sleep(100);
            waitForDirectoryCreated();
        }
    }

    function searchHelperRenderer(helperComp){
        var i=0,len = app.project.renderQueue.items.length;
        var item;
        while(i<len){
            item =  app.project.renderQueue.items[i+1];
            if(item.comp == helperComp){
                return item;
            }
            i++;
        }
    }

    function start(){
        UI.setExportText('Starting export');
        LayerConverter.convertComposition(mainComp);
    }

    function exportNextComposition(){
        isExportDirectoryCreated = false;
        directoryCreationFailed = false;
        mainComp = currentCompositionData.comp;
        createExportDirectory();
        waitForDirectoryCreated();
    }

    function searchNextComposition(){
        if(!renderCancelled){
            var len = compositionsList.length;
            var i = 0;
            while(i < len){
                if(compositionsList[i].queued === true && compositionsList[i].rendered == false){
                    currentCompositionData = compositionsList[i];
                    exportNextComposition();
                    return;
                }
                i+=1;
            }
        }
        //If it gets here there are no more compositions to render and callback is executed
        helperFootage.remove();
        endCallback.apply();
    }

    function renderCompositions(list){
        var helperFile = new File(scriptPath+'/helperProject.aep');
        var helperImportOptions = new ImportOptions();
        helperImportOptions.file = helperFile;
        helperFootage = mainProject.importFile(helperImportOptions);
        var helperFolder = helperFootage.item(2);
        var i = 0, len = helperFolder.items.length;
        while(i<len){
            if(helperFolder.item(i+1).name == 'helperSolidComp'){
                helperSolidComp = helperFolder.item(i+1);
            }
            i += 1;
        }
        helperSolid = helperSolidComp.layer(1);
        var helperPosition = helperSolid.transform["Anchor Point"];
        helperPosition.expression = "valueAtTime(time)";

        rqManager.setProject(app.project);
        LayerConverter.setCallback(layersConverted);
        compositionsList = list;
        len = compositionsList.length;
        for(i=0;i<len;i+=1){
            compositionsList[i].rendered = false;
        }
        searchNextComposition();
    }

    function setFinishCallback(cb){
        endCallback = cb;
    }

    var ob = {};
    ob.renderCompositions = renderCompositions;
    ob.setFinishCallback = setFinishCallback;

    CompConverter = ob;
}());
/****** END CompConverter ******/<|endoftext|>


<commit_before>/*
 * Kavie - knockout observable validator
 * Matthew Nitschke - http://pyrtio.com/
 * License: MIT (http://www.opensource.org/licenses/mit-license.php)
 */

ko.extenders.kavie = function (target, rules) {
    target.hasError = ko.observable();

    if (rules.addToArray){
      Kavie.add(target);
      delete rules.addToArray;
    }

    if (rules.section){
      if (!Kavie.sections[rules.section]){
        Kavie.sections[rules.section] = [];
      }

      Kavie.sections[rules.section].push(target);

      delete rules.section;
    }

    target.rules = rules;

    function validate(newValue) {
        var rules = target.rules;

        for (key in rules) {
            for (funcKey in Kavie.validatorFunctions) {
                if (key == funcKey) {
                    var isValid = Kavie.validatorFunctions[funcKey](rules[key], newValue);
                    if (!isValid) {
                        target.hasError(true);
                        return;
                    }
                }
            }
        }

        target.hasError(false);
    }

    target.subscription;

    target.startValidation = function () {
        target.subscription = target.subscribe(validate);
        validate(target());
    }

    target.stopValidation = function () {
        target.subscription.dispose();
        target.hasError(false);
    }

    return target;
};

var Kavie = function(){}
Kavie.observables = [];
Kavie.sections = [];

Kavie.isKavieObservable = function(observable){
  if (observable.hasOwnProperty("hasError")){ // when you extend an observable with kavie, it addes hasError.
    return true;
  } else {
    return false;
  }
}

Kavie.add = function(obs){
  if (this.isKavieObservable(obs)){
    this.observables = this.observables.concat(obs);
  }
}

Kavie.compileObservables = function(vm){
  var kavieObservables = [];

  if (this.observables.length > 0){
    kavieObservables = kavieObservables.concat(this.observables);
  }
  if (vm){
    var keys = Object.keys(vm);
    for(var i = 0; i < keys.length; i ++){
      if (this.isKavieObservable(vm[keys[i]])){
        kavieObservables.push(vm[keys[i]]);
      }
    }
  }
  return kavieObservables;
}

Kavie.isValid = function(vm){
  var isValid = true;

  var kavieObservables = Kavie.compileObservables(vm);

  for(var i = 0; i < kavieObservables.length; i ++){
    kavieObservables[i].startValidation();

    if (isValid) {
        if (kavieObservables[i].hasError()) {
            isValid = false;
        }
    }
  }
  return isValid;
}

Kavie.deactivate = function(vm){

  var kavieObservables = Kavie.compileObservables(vm);

  for(var i = 0; i < kavieObservables.length; i ++){
    kavieObservables[i].stopValidation();
  }
}

Kavie.validatorFunctions = {
    required: function (propVal, eleVal) {
        if (propVal) {
            return (eleVal ? true : false);
        } else {
            return true;
        }
    },
    numeric: function(propVal, eleVal){
      if (propVal){
         return !isNaN(parseFloat(eleVal)) && isFinite(eleVal);
      } else {
        return true;
      }

    },
    max: function (propVal, eleVal) {
      if (eleVal){
        return eleVal.length <= propVal;
      }
      return true; // if no value is found, it doesnt have a length. So thus it is less than the propVal
    },
    min: function (propVal, eleVal) {
      if (eleVal){
        return eleVal.length >= propVal;
      }
      return false; // opposite from above
    },
    date: function (propVal, eleVal) {
      if (eleVal){
        if (eleVal.length == 10) {
            if (new Date(eleVal) == "Invalid Date") {
                return false;
            }
            return true;
        }
        return false;
      }
      return false; // noting is an invalid date
    },
    birthdate: function (propVal, eleVal) {
        // check to see if it is a valid date
        if (!Kavie.validatorFunctions.date(propVal, eleVal)) {
            return false;
        }

        var date = new Date(eleVal);

        // check to see if the date is in the future
        if (date > new Date()) {
            return false;
        }

        // check to see if date is a rational birthdate
        var minDateAllowed = new Date();
        minDateAllowed.setFullYear(minDateAllowed.getFullYear() - 120); // 120 is age of oldest person allowd

        if (date < minDateAllowed) {
            return false;
        }

        return true;
    },
    regexPattern: function(propVal, eleVal){
      if (eleVal){
        return eleVal.toString().match(propVal) !== null;
      } else {
        return false;
      }
    }
}
<commit_msg>Updated comments on main script file<commit_after>/*
 * Kavie - knockout observable validator
 * Author: Matthew Nitschke
 * License: MIT (http://www.opensource.org/licenses/mit-license.php)
 */

ko.extenders.kavie = function (target, rules) {
    target.hasError = ko.observable();

    if (rules.addToArray){
      Kavie.add(target);
      delete rules.addToArray;
    }

    if (rules.section){
      if (!Kavie.sections[rules.section]){
        Kavie.sections[rules.section] = [];
      }

      Kavie.sections[rules.section].push(target);

      delete rules.section;
    }

    target.rules = rules;

    function validate(newValue) {
        var rules = target.rules;

        for (key in rules) {
            for (funcKey in Kavie.validatorFunctions) {
                if (key == funcKey) {
                    var isValid = Kavie.validatorFunctions[funcKey](rules[key], newValue);
                    if (!isValid) {
                        target.hasError(true);
                        return;
                    }
                }
            }
        }

        target.hasError(false);
    }

    target.subscription;

    target.startValidation = function () {
        target.subscription = target.subscribe(validate);
        validate(target());
    }

    target.stopValidation = function () {
        target.subscription.dispose();
        target.hasError(false);
    }

    return target;
};

var Kavie = function(){}
Kavie.observables = [];
Kavie.sections = [];

Kavie.isKavieObservable = function(observable){
  if (observable.hasOwnProperty("hasError")){ // when you extend an observable with kavie, it addes hasError.
    return true;
  } else {
    return false;
  }
}

Kavie.add = function(obs){
  if (this.isKavieObservable(obs)){
    this.observables = this.observables.concat(obs);
  }
}

Kavie.compileObservables = function(vm){
  var kavieObservables = [];

  if (this.observables.length > 0){
    kavieObservables = kavieObservables.concat(this.observables);
  }
  if (vm){
    var keys = Object.keys(vm);
    for(var i = 0; i < keys.length; i ++){
      if (this.isKavieObservable(vm[keys[i]])){
        kavieObservables.push(vm[keys[i]]);
      }
    }
  }
  return kavieObservables;
}

Kavie.isValid = function(vm){
  var isValid = true;

  var kavieObservables = Kavie.compileObservables(vm);

  for(var i = 0; i < kavieObservables.length; i ++){
    kavieObservables[i].startValidation();

    if (isValid) {
        if (kavieObservables[i].hasError()) {
            isValid = false;
        }
    }
  }
  return isValid;
}

Kavie.deactivate = function(vm){

  var kavieObservables = Kavie.compileObservables(vm);

  for(var i = 0; i < kavieObservables.length; i ++){
    kavieObservables[i].stopValidation();
  }
}

Kavie.validatorFunctions = {
    required: function (propVal, eleVal) {
        if (propVal) {
            return (eleVal ? true : false);
        } else {
            return true;
        }
    },
    numeric: function(propVal, eleVal){
      if (propVal){
         return !isNaN(parseFloat(eleVal)) && isFinite(eleVal);
      } else {
        return true;
      }

    },
    max: function (propVal, eleVal) {
      if (eleVal){
        return eleVal.length <= propVal;
      }
      return true; // if no value is found, it doesnt have a length. So thus it is less than the propVal
    },
    min: function (propVal, eleVal) {
      if (eleVal){
        return eleVal.length >= propVal;
      }
      return false; // opposite from above
    },
    date: function (propVal, eleVal) {
      if (eleVal){
        if (eleVal.length == 10) {
            if (new Date(eleVal) == "Invalid Date") {
                return false;
            }
            return true;
        }
        return false;
      }
      return false; // noting is an invalid date
    },
    birthdate: function (propVal, eleVal) {
        // check to see if it is a valid date
        if (!Kavie.validatorFunctions.date(propVal, eleVal)) {
            return false;
        }

        var date = new Date(eleVal);

        // check to see if the date is in the future
        if (date > new Date()) {
            return false;
        }

        // check to see if date is a rational birthdate
        var minDateAllowed = new Date();
        minDateAllowed.setFullYear(minDateAllowed.getFullYear() - 120); // 120 is age of oldest person allowd

        if (date < minDateAllowed) {
            return false;
        }

        return true;
    },
    regexPattern: function(propVal, eleVal){
      if (eleVal){
        return eleVal.toString().match(propVal) !== null;
      } else {
        return false;
      }
    }
}
<|endoftext|>


<commit_before>export function parse (source, name = '@') {
  if (!wasm)
    return init.then(() => parse(source));

  // need 2 bytes per code point plus analysis space so we double again
  const extraMem = (wasm.__heap_base.value || wasm.__heap_base) + source.length * 4 +  - wasm.memory.buffer.byteLength;
  if (extraMem > 0)
    wasm.memory.grow(Math.ceil(extraMem / 65536));

  copy(source, new Uint16Array(wasm.memory.buffer, wasm.sa(source.length), source.length + 1));

  if (!wasm.parse())
    throw Object.assign(new Error(`Parse error ${name}:${source.slice(0, wasm.e()).split('\n').length}:${wasm.e() - source.lastIndexOf('\n', wasm.e()) - 1}`), { idx: wasm.e() });

  const imports = [], exports = [];
  while (wasm.ri()) imports.push({ s: wasm.is(), e: wasm.ie(), d: wasm.id() });
  while (wasm.re()) exports.push(source.slice(wasm.es(), wasm.ee()));

  return [imports, exports];
}

function copy (src, outBuf16) {
  const len = src.length;
  let i = 0;
  while (i < len)
    outBuf16[i] = src.charCodeAt(i++);
}

let wasm;

export const init = WebAssembly.compile(
  (binary => typeof atob === 'function' ? Uint8Array.from(atob(binary), x => x.charCodeAt(0)) : Buffer.from(binary, 'base64'))
  ('WASM_BINARY')
)
.then(WebAssembly.instantiate)
.then(({ exports }) => { wasm = exports; });
<commit_msg>columns start at 1<commit_after>export function parse (source, name = '@') {
  if (!wasm)
    return init.then(() => parse(source));

  // need 2 bytes per code point plus analysis space so we double again
  const extraMem = (wasm.__heap_base.value || wasm.__heap_base) + source.length * 4 +  - wasm.memory.buffer.byteLength;
  if (extraMem > 0)
    wasm.memory.grow(Math.ceil(extraMem / 65536));

  copy(source, new Uint16Array(wasm.memory.buffer, wasm.sa(source.length), source.length + 1));

  if (!wasm.parse())
    throw Object.assign(new Error(`Parse error ${name}:${source.slice(0, wasm.e()).split('\n').length}:${wasm.e() - source.lastIndexOf('\n', wasm.e())}`), { idx: wasm.e() });

  const imports = [], exports = [];
  while (wasm.ri()) imports.push({ s: wasm.is(), e: wasm.ie(), d: wasm.id() });
  while (wasm.re()) exports.push(source.slice(wasm.es(), wasm.ee()));

  return [imports, exports];
}

function copy (src, outBuf16) {
  const len = src.length;
  let i = 0;
  while (i < len)
    outBuf16[i] = src.charCodeAt(i++);
}

let wasm;

export const init = WebAssembly.compile(
  (binary => typeof atob === 'function' ? Uint8Array.from(atob(binary), x => x.charCodeAt(0)) : Buffer.from(binary, 'base64'))
  ('WASM_BINARY')
)
.then(WebAssembly.instantiate)
.then(({ exports }) => { wasm = exports; });
<|endoftext|>