window.Meta=(function(){function getRunCommand(){if(!runCommandEnabled())return"";return $("#cmd-input").val()}
function runCommandEnabled(){return $("#cmd-checkbox").is(":checked")}
function getLanguageVersion(){return $("#lang-version").val()}
function isPublic(){return $("#public").val()==="true"};return{getRunCommand:getRunCommand,getLanguageVersion:getLanguageVersion,isPublic:isPublic}})();(function(){$(document).on("click","#cmd-checkbox",function(e){var checked=$(e.target).is(":checked");$("#cmd-input").prop('disabled',!checked)})})();window.Settings=(function(){var MIN_LINE_COUNT=10;function setTheme(theme){localStorage.theme=theme}
function getTheme(){if(localStorage.theme)return localStorage.theme;return"ace/theme/solarized_dark"}
function setKeybindings(keybindings){localStorage.keybindings=keybindings}
function getKeybindings(){if(localStorage.keybindings)return localStorage.keybindings;return""}
function setFullWidth(fullWidth){localStorage.fullWidth=(fullWidth?"true":"false")}
function getFullWidth(){if(localStorage.fullWidth)return localStorage.fullWidth==="true";return false}
function setLineCount(lineCount){localStorage.lineCount=Math.max(lineCount,MIN_LINE_COUNT);$(".line-count .count-value").text(localStorage.lineCount)}
function clearLineCount(lineCount){delete localStorage.lineCount;$(".line-count .count-value").text(lineCount)}
function getLineCount(){if(localStorage.lineCount)return Math.max(parseInt(localStorage.lineCount)||MIN_LINE_COUNT,MIN_LINE_COUNT);return undefined}
function calcLineCount(){var editorY=$(".editors").offset().top,browserHeight=Math.max(document.documentElement.clientHeight,window.innerHeight||0),lineHeight=18,bottomMargin=320,lineCount=Math.ceil((browserHeight-editorY-bottomMargin)/lineHeight);return Math.max(lineCount,MIN_LINE_COUNT)};return{setTheme:setTheme,getTheme:getTheme,setKeybindings:setKeybindings,getKeybindings:getKeybindings,setFullWidth:setFullWidth,getFullWidth:getFullWidth,getLineCount:getLineCount,setLineCount:setLineCount,clearLineCount:clearLineCount,calcLineCount:calcLineCount}})();(function(){function init(){selectOption(".themes",Settings.getTheme());selectOption(".keybindings",Settings.getKeybindings());selectOption(".full-width-dropdown",Settings.getFullWidth());var lineCount=Settings.getLineCount();if(!lineCount){Settings.clearLineCount(Settings.calcLineCount())}else Settings.setLineCount(lineCount)}
function selectOption(cls,value){$(cls+' [value="'+value+'"]').attr("selected","selected")};$(document).on("change",".themes",function(e){var theme=$(e.target).val();Settings.setTheme(theme);Editor.setTheme(theme)});$(document).on("change",".keybindings",function(e){var keybindings=$(e.target).val();Settings.setKeybindings(keybindings);Editor.setKeybindings(keybindings)});$(document).on("change",".full-width-dropdown",function(e){var fullWidth=$(e.target).val()==="true";Settings.setFullWidth(fullWidth);Editor.setFullWidth(fullWidth)});$(document).on("click",".line-count .increment",function(e){var lineCount=parseInt($(".line-count .count-value").text())+1;Settings.setLineCount(lineCount);Editor.setLineCount(lineCount)});$(document).on("click",".line-count .decrement",function(e){var lineCount=parseInt($(".line-count .count-value").text())-1;Settings.setLineCount(lineCount);Editor.setLineCount(lineCount)});$(document).on("click",".line-count .auto",function(e){var lineCount=Settings.calcLineCount();Settings.clearLineCount(lineCount);Editor.setLineCount(lineCount)});init()})();window.Editor=(function(){function initEditor(id){var theme=Settings.getTheme(),keybindings=Settings.getKeybindings(),lineCount=Settings.getLineCount()||Settings.calcLineCount(),editor=ace.edit(id);editor.setTheme(theme);editor.setKeyboardHandler(keybindings);editor.getSession().setMode("ace/mode/python");editor.setOptions({useSoftTabs:true,tabSize:4,minLines:lineCount,maxLines:lineCount});resizeEditor(editor)}
function resizeEditor(editor){setTimeout(function(){editor.resize()},1)}
function setTheme(theme){var editorIds=getEditorIds();editorIds.forEach(function(id){var editor=ace.edit(id);editor.setTheme(theme)})}
function setLineCount(lineCount){var editorIds=getEditorIds();editorIds.forEach(function(id){var editor=ace.edit(id);editor.setOptions({minLines:lineCount,maxLines:lineCount})})}
function clean(){var editorIds=getEditorIds();return editorIds.forEach(function(id){var editor=ace.edit(id);editor.session.getUndoManager().reset()})}
function isClean(){var editorIds=getEditorIds();return editorIds.every(function(id){var editor=ace.edit(id);return editor.session.getUndoManager().isClean()})}
function setKeybindings(keybindings){var editorIds=getEditorIds();editorIds.forEach(function(id){var editor=ace.edit(id);editor.setKeyboardHandler(keybindings)})}
function setFullWidth(fullWidth){if(fullWidth){$(".content-container").addClass("full-width")}else $(".content-container").removeClass("full-width")}
function resetEditor(id){var editor=ace.edit(id);editor.setValue("")}
function setFiles(files){files.forEach(function(file,i){var editorId="editor-"+(i+1);initEditor(editorId);setValue(editorId,file.content);setTabTitle(editorId,file.name);showTab(editorId)})}
function setValue(id,value){var editor=ace.edit(id);editor.setValue(value)}
function setActiveTab(elem){$(".editor-widget li.active").removeClass("active");elem.removeClass("hide");elem.addClass("active")}
function showTab(id){var selector=".nav-tabs [data-editor='"+id+"']";$(selector).removeClass("hide")}
function setTabTitle(id,title){var selector=".nav-tabs [data-editor='"+id+"'] .filename";$(selector).text(title)}
function closeTab(elem){if(elem.hasClass("active")){var prevTab=elem.prev(),prevEditorId=prevTab.data("editor");showEditor(prevEditorId);setActiveTab(elem.prev())};elem.addClass("hide")}
function showEditor(id){$(".editors .editor:not(.hide)").addClass("hide");$(".editor-footer").removeClass("hide");$("#"+id).removeClass("hide");$("#meta").addClass("hide");$("#settings").addClass("hide");var editor=getEditor(id);resizeEditor(editor)}
function showMeta(){$(".editors .editor:not(.hide)").addClass("hide");$(".editor-footer").addClass("hide");$("#meta").removeClass("hide");$("#settings").addClass("hide")}
function showSettings(){$(".editors .editor:not(.hide)").addClass("hide");$(".editor-footer").addClass("hide");$("#meta").addClass("hide");$("#settings").removeClass("hide")}
function getFiles(){var editorIds=getEditorIds(),files=editorIds.map(function(id){return{name:getFilename(id),content:getContent(id)}});return files.filter(function(file){return file.content.length>0})}
function getEditorIds(){return $(".editors .editor").map(function(){return $(this).attr('id')}).toArray()}
function getContent(editorId){var editor=getEditor(editorId);return editor.getValue()}
function getFilename(editorId){var selector='.nav-tabs [data-editor="'+editorId+'"] .filename';return $(selector).text()}
function getEditor(editorId){return ace.edit(editorId)}
function onRunCodeKeyComboPressed(callback){$(document).on('keydown',function(e){var isMac=navigator.platform.toUpperCase().indexOf('MAC')>=0,enterKeyPressed=e.which===13,metaKeyPressed=e.metaKey,ctrlKeyPressed=e.ctrlKey,shouldRunCode=enterKeyPressed&&((isMac&&metaKeyPressed)||(!isMac&&ctrlKeyPressed));if(shouldRunCode){e.preventDefault();callback()}})};return{initEditor:initEditor,resetEditor:resetEditor,setFiles:setFiles,setActiveTab:setActiveTab,closeTab:closeTab,showEditor:showEditor,showMeta:showMeta,showSettings:showSettings,setTheme:setTheme,setKeybindings:setKeybindings,setFullWidth:setFullWidth,setLineCount:setLineCount,getFiles:getFiles,clean:clean,isClean:isClean,onRunCodeKeyComboPressed:onRunCodeKeyComboPressed}})();window.Fork=(function(){function hasFiles(){if(localStorage.forkedFiles)return true;return false}
function setFiles(files){localStorage.forkedFiles=JSON.stringify(files)}
function getFiles(){if(!hasFiles())return null;var files=JSON.parse(localStorage.forkedFiles);delete localStorage.forkedFiles;return files};return{hasFiles:hasFiles,setFiles:setFiles,getFiles:getFiles}})();(function(){$(document).on("click",".nav-tabs [data-editor]",function(e){var tab=$(e.target).closest("li"),editorId=tab.data("editor");Editor.showEditor(editorId);Editor.setActiveTab(tab)});$(document).on("click",".nav-tabs .meta",function(e){var tab=$(e.target).closest("li");Editor.setActiveTab(tab);Editor.showMeta()});$(document).on("click",".nav-tabs .settings",function(e){var tab=$(e.target).closest("li");Editor.setActiveTab(tab);Editor.showSettings()});$(document).on("click",".new-file",function(e){e.preventDefault();var tab=$("[data-editor].hide").first();if(tab.length===0)return;var editorId=tab.data("editor");Editor.initEditor(editorId);Editor.showEditor(editorId);Editor.setActiveTab(tab)});$(document).on("click",".close-file",function(e){e.stopPropagation();if(!confirm("Are you sure you want to delete this file?"))return;var tab=$(e.target).parents("li[data-editor]"),editorId=tab.data("editor");Editor.resetEditor(editorId);Editor.closeTab(tab)});$(document).on("click",'.nav-tabs a[href="#"]',function(e){e.preventDefault()});$(document).on("click","li.active .filename",function(e){var elem=$(e.target),filename=prompt("Enter a new filename",elem.text());if(filename)elem.text(filename)});if(Fork.hasFiles()){var files=Fork.getFiles();Editor.setFiles(files)}else{var fileCount=1;for(var i=1;i<=fileCount;i++)Editor.initEditor("editor-"+i)};Editor.setFullWidth(Settings.getFullWidth())})();window.EditorFooter=(function(){function showInputTab(setActiveButton){$(".editor-footer .input").removeClass("hide");$(".editor-footer .output").addClass("hide");if(setActiveButton){$(".editor-footer .show-input-label").addClass("active");$(".editor-footer .show-output-label").removeClass("active")}}
function showOutputTab(setActiveButton){$(".editor-footer .output").removeClass("hide");$(".editor-footer .input").addClass("hide");if(setActiveButton){$(".editor-footer .show-output-label").addClass("active");$(".editor-footer .show-input-label").removeClass("active")}}
function show(result){for(var key in result){var value=result[key];if(value)showPanel(key,value)};checkExpandButton()}
function checkExpandButton(){var outputEl=$(".editor-footer .output"),showFullEl=$(".editor-footer .show-full-height");if(outputEl.length===0)return;if(outputEl[0].scrollHeight-outputEl.height()>200)showFullEl.removeClass("hide")}
function showInfo(){showPanel("info","Running...")}
function hideInfo(){hidePanel("info")}
function clear(){["info","stdout","stderr","error"].forEach(function(name){hidePanel(name)});showDefaultHeight();$(".editor-footer .show-full-height").addClass("hide")}
function showPanel(name,value){var selector=".editor-footer .output ."+name;$(selector).removeClass("hide");$(selector+" .body").text(value)}
function hidePanel(name){var selector=".editor-footer .output ."+name;$(selector).addClass("hide")}
function getStdin(){return $(".editor-footer .stdin").val()};$(document).on("change",".editor-footer .show-input",function(e){var radio=$(e.target);if(radio.prop("checked"))showInputTab(false)});$(document).on("change",".editor-footer .show-output",function(e){var radio=$(e.target);if(radio.prop("checked"))showOutputTab(false)});function showFullHeight(){$(".editor-footer .footer-left").addClass("full-height");$(".editor-footer .output").addClass("full-height")}
function showDefaultHeight(){$(".editor-footer .footer-left").removeClass("full-height");$(".editor-footer .output").removeClass("full-height")};$(document).on("click",".editor-footer .show-full-height",function(e){e.preventDefault();$(".editor-footer .show-full-height").addClass("hide");showFullHeight();$(".editor-footer .output").addClass("hide");setTimeout(function(){$(".editor-footer .output").removeClass("hide")},1)});$(document).ready(function(){checkExpandButton()});return{showInputTab:showInputTab,showOutputTab:showOutputTab,showInfo:showInfo,hideInfo:hideInfo,show:show,clear:clear,getStdin:getStdin}})();(function(){$(document).on("keydown","[contenteditable]",function(e){if(e.which==13){$(e.target).blur();window.getSelection().removeAllRanges()}});$(document).on("click",".run",function(e){run()});Editor.onRunCodeKeyComboPressed(function(){run()});$(document).on("click",".save",function(e){e.preventDefault();save()});$(document).on("click",".delete",function(e){e.preventDefault();if(confirm("Are you sure you want to delete this snippet?"))deleteSnippet()});$(document).on("click",".fork",function(e){var files=Editor.getFiles();Fork.setFiles(files);Editor.clean();Location.set("https://glot.io/new/python")});function run(){EditorFooter.showOutputTab(true);EditorFooter.clear();EditorFooter.showInfo("Running...");var version=Meta.getLanguageVersion(),url='https://glot.io/run/python?snippet=h196l8mjb3&'+$.param({version:version}),payload={files:Editor.getFiles(),stdin:EditorFooter.getStdin(),command:Meta.getRunCommand()};XHR.jsonPost(url,payload).then(function(data){EditorFooter.show(data)}).catch(function(msg){Alert.danger(msg)}).finally(function(){EditorFooter.hideInfo()})}
function save(){var payload={language:"python",title:getTitle(),public:Meta.isPublic(),files:Editor.getFiles()},version=Meta.getLanguageVersion(),url='https://glot.io/snippets/h196l8mjb3?'+$.param({version:version,command:Meta.getRunCommand(),stdin:EditorFooter.getStdin()});XHR.jsonPut(url,payload).then(function(data){Editor.clean();Location.reload()}).catch(function(msg){Alert.danger(msg)})}
function deleteSnippet(){XHR.delete("https://glot.io/snippets/h196l8mjb3").then(function(data){Editor.clean();Location.set("https://glot.io/snippets")}).catch(function(msg){Alert.danger(msg)})}
function getTitle(){return $("#snippet-title").text()};window.onbeforeunload=function(){if(!Editor.isClean())return"You have unsaved changes!"};$(document).popover({selector:".share",container:"body",content:$("#share-content").html(),html:true});$(document).on("click",".share",function(e){e.preventDefault();e.stopPropagation();function clickHandler(e){if(!$(e.target).parents(".popover").length)hidePopover()}
function escapeHandler(e){if(e.keyCode==27)hidePopover()}
function hidePopover(){$(".share").popover("hide");$(document).off("click",clickHandler);$(document).off("keyup",escapeHandler)};$(document).on("click",clickHandler);$(document).on("keyup",escapeHandler)})})();window.Alert=(function(){function fadeOut(selector,timeout){var el=$(selector);if(el.length===0)return;setTimeout(function(){el.addClass("fade-out")},timeout);setTimeout(function(){el.remove()},timeout+3000)}
function fadeOutAll(){fadeOut(".alert-success",5000);fadeOut(".alert-info",5000);fadeOut(".alert-warning",5000);fadeOut(".alert-danger",9000)}
function danger(msg){render("https://glot.io/alert/danger",msg)}
function render(url,msg){XHR.jsonPost(url,{message:msg}).then(function(res){show(res.message)})}
function show(html){$("body").append(html);fadeOutAll()};fadeOutAll();return{danger:danger}})();(function(){(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create',"UA-38975419-1",'auto');ga('send','pageview')})()