/*-----------------------------TOP----------------------------------------*/ /*---------------------------ONPAGE Function - required by File Type Limit filter applied below------------------------------------------*/ onPage(/\/courses\/\d+\/settings/, function() { // do something }); hasAnyRole('admin', function(hasRole) { if (hasRole) { // do something } else { // do something else } }); isUser(1, function(isRyan) { if (isRyan) { // do something } else { // so something else } }); onElementRendered('a[href=#create_ticket]', function(el) { // do something with el (a jquery element collection) }); function onPage(regex, fn) { if (location.pathname.match(regex)) fn(); } function hasAnyRole(/*roles, cb*/) { var roles = [].slice.call(arguments, 0); var cb = roles.pop(); for (var i = 0; i < arguments.length; i++) { if (ENV.current_user_roles.indexOf(arguments[i]) !== -1) { return cb(true); } } return cb(false); } function isUser(id, cb) { cb(ENV.current_user_id == id); } function onElementRendered(selector, cb, _attempts) { var el = $(selector); _attempts = ++_attempts || 1; if (el.length) return cb(el); if (_attempts == 60) return; setTimeout(function() { onElementRendered(selector, cb, _attempts); }, 250); } /*---------------------------BOTTOM------------------------------------------*/ /*-----------------------------TOP----------------------------------------*/ /* Show list of file types for file limitation on assignment uploads. */ /* Note: uses onPage function by RPFlorence from https://gist.github.com/rpflorence/5817898 */ onPage(/\/courses\/\d+\/assignments\/(\d+\/edit|new)/, function() { onElementRendered('div#allowed_extensions_container', function(el) { //alert('On Page!'); if(!$('div#file_type_selection').length){ var ft = { "Word" : "doc,docx", "Excel" : "xls,xlsx", "PowerPoint" : "ppt,pptx", "PDF Files" : "pdf", "Text Files" : "txt", "Web Pages" : "html,htm", "Images" : "jpg,jpeg,gif,png,tiff,tif,bmp", "Zip Files" : "zip" }; $('div#allowed_extensions_container').append(function(){ curr = $('input#assignment_allowed_extensions').val(); var return_val = '
' + key + ' | '; if(c == 1){ return_val += "