{"size": 1696, "ext": "js", "max_stars_repo_path": "server-core/src/main/java/io/onedev/server/web/page/project/blob/render/edit/plain/plain-edit.js", "max_stars_repo_name": "mhoffrog/onedev", "max_stars_repo_stars_event_min_datetime": "2020-01-28T20:37:33.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-28T20:37:33.000Z", "max_issues_repo_path": "server-core/src/main/java/io/onedev/server/web/page/project/blob/render/edit/plain/plain-edit.js", "max_issues_repo_name": "mhoffrog/onedev", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server-core/src/main/java/io/onedev/server/web/page/project/blob/render/edit/plain/plain-edit.js", "max_forks_repo_name": "mhoffrog/onedev", "max_forks_repo_forks_event_min_datetime": "2022-03-15T19:33:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T19:33:12.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 31.4074074074, "max_line_length": 114, "alphanum_fraction": 0.6538915094}
onedev.server.plainEdit = {
	onDomReady: function(containerId, fileName) {
		var $container = $("#" + containerId);
		var $plainEdit = $container.children(".plain-edit");
		var $source = $plainEdit.children(".source");
		var cm = CodeMirror($source[0], {
			value: $plainEdit.children(".input").val(),
			theme: "eclipse",
			indentWithTabs: true,
			indentUnit: 4,
			lineNumbers: true,
			lineWrapping: true,
			tabSize: 4,
			styleActiveLine: true,
			styleSelectedText: true,
			foldGutter: true,
			matchBrackets: true,
			scrollbarStyle: "simple",
			gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
			highlightIdentifiers: {delay: 500}
		});
		
		onedev.server.codemirror.setModeByFileName(cm, fileName);
		
		/*
		 * AreYouSure can not track dirty correctly for CodeMirror generated
		 * textarea, and it will always mark the form as clean even if we 
		 * mark it as dirty explicitly. So we use no-dirtytrack class to 
		 * disable automatic dirty track
		 */
		$plainEdit.closest("form").find("textarea").addClass("no-dirtytrack").addClass("no-autosize");
		
		cm.on("change", function() {
			$plainEdit.closest("form").addClass("dirty");
        });
        
		onedev.server.codemirror.bindShortcuts(cm);
		
		$plainEdit.on("autofit", function(e, width, height) {
			if (cm.getOption("fullScreen"))
				return;
			
			$plainEdit.outerWidth(width);
			$plainEdit.outerHeight(height);
            cm.setSize($plainEdit.width(), $plainEdit.height());
            cm.refresh();
        });

        $plainEdit.on("beforeSubmit", function() {
            $plainEdit.children("textarea").val($plainEdit.find(">.source>.CodeMirror")[0].CodeMirror.getValue());
        });
	}
};
