You are on page 1of 14

Drupal.theme.prototype.

popupButton = function(title, id) {


return '<span><input type="button" value="'+ title +'" id="'+ id +'" /></span>';
};

Drupal.theme.prototype.popupLoading = function() {
var loading = '<div id="popups-loading"><div>';
loading += Drupal.t('Loading...');
loading += '</div></div>';
return loading;
};

Drupal.theme.prototype.popupDialog = function(popupId, title, body, buttons) {


var template = Drupal.theme('popupTemplate', popupId);
if(buttons){
body = '<div class="popups-body-inner-has-buttons">' + body + '</div>';
}
var popups = template.replace('%title', title).replace('%body', body);

var themedButtons = '';


if (buttons) {
jQuery.each(buttons, function (id, button) {
themedButtons += Drupal.theme('popupButton', button.title, id);
});
themedButtons = '<div class="popups-buttons-inner">' + themedButtons +
'</div>';
}
popups = popups.replace('%buttons', themedButtons);
return popups;
};

/**
* Similar to drupal_attributes
*
* @param object attrs
*/
Drupal.attributes =
Drupal.theme.prototype.attributes = function(attrs){
var ret = '';
$.each(attrs, function(k, v){
ret += ' ' + k + '="' + Drupal.checkPlain(v) +'"';
});
return $.trim(ret);
};

/**
* Similar to Drupal's l()
*
* @param string text
* @param string path
* @param object opts
*/
Drupal.l =
Drupal.theme.prototype.l = function(text, path, opts){
if(typeof opts == 'undefined'){
var opts = {};
}
var defaults = {
attributes: {},
html: false
};
opts = $.extend(defaults, opts);

return '<a href="' + path + '"' + Drupal.attributes(opts.attributes) + '>' +


(opts.html ? text : Drupal.checkPlain(text)) + '</a>';
};

/**
* Return a jquery object with the tipsy plugin bound.
*
* @param string content the content to show in the tipsy
* @param object opts
* string text the text to go inside the element that triggers the tipsy
* string gravity
* object attributes standard Drupal.attributes
*/
Drupal.theme.infotip = function(content, opts){
if(typeof opts == 'undefined'){
var opts = {};
}
var defaults = {
text: '',
gravity: 's',
attributes: {
'class': ''
}
};
opts = $.extend(defaults, opts);

var el = '<span ' + Drupal.attributes(opts.attributes) + '>' + opts.text +


'</span>';
var infotipObj = $(el);
infotipObj.tipsy({
html: true,
gravity: opts.gravity,
title: function(){
return content;
}
});

return infotipObj;
};

/*
* Return Markup for action links
*/
Drupal.theme.sActionLinks = function(links, opts){
if(typeof opts == undefined){
var opts = {};
}

if(typeof links != 'object' && links.length == 0){


return '';
}

var defaults = {
wrapperId : '',
ulId : '',
btnId : '',
btnClass : '',
ulClass : '',
wrapperClass : '',
size : 'regular',
text : '',
isAngular : true
};
opts = $.extend(defaults, opts);
var output = '';
output += '<div class="' + (opts.isAngular ? 's-action-link' : '') + ' action-
links-wrapper action-links-wrapper-' + opts.size + ' ' + opts.wrapperClass + '">';
output += '<div tabindex="0" role="button" class="action-links-unfold" id="' +
opts.btnId + '">';
output += '<span class="action-links-unfold-text"><span class="visually-hidden">'
+ Drupal.t('Click to toggle options.') + '</span></span>';
output += '</div>';
output += '<ul class="action-links">';
$.each(links, function(k, v){
output += v;
});
output += '</ul>';
output += '</div>';
return output;
}

Drupal.theme.sCommonAngularDeletePopup = function(){
return {
title : Drupal.t('Delete'),
body : Drupal.t('Are you sure you want to delete this?'),
confirm : {
text : Drupal.t('Delete')
},
cancel : {
text : Drupal.t('Cancel')
}
};
}

/**
* Register an element for popups with the provided options.
*
* @param string/object el selector or jquery object
* @param object opts popups options
*/
Drupal.popup = function(el, opts){
var elObj = $(el)
elObj.not('.popups-processed').addClass('popups-processed').click(function(e){
e.preventDefault();
return Popups.clickPopupElement(this, opts);
});

return elObj;
};

Drupal.behaviors.schoologyTheme = function(context){
$('.popups-body textarea:not(.schoologyTheme-
processed)').addClass('schoologyTheme-processed').each(function(){
var ta = $(this);
ta.focus(function(){
ta.addClass('popups-textarea-focus');
popup = Popups.activePopup();
if(popup != null)
Popups.resizeAndCenter(popup);
});
});
};

Drupal.theme.sAjaxLoader = function(options){
var defaultOpts = {
asString : false,
imgId : false
};
var opts = $.extend( {}, $.fn.sActionLinks.defaults, options);
var ajaxLoader = $('<img
/>').attr('src','/sites/all/themes/schoology_theme/images/ajax-
loader.gif').addClass('ajax-loader');

if(opts.imgId){
ajaxLoader.attr('id', opts.imgId);
}

if(opts.asString){
return ajaxLoader[0].outerHTML;
}
return ajaxLoader;
}

Drupal.theme.sAjaxMessage = function(message, msgClass){


var msg = '<div class="messages ' + msgClass + '">\n\
<div class="messages-close-btn" style="">x</div>\n\
<div class="messages-container">\n\
<table role="presentation"><tbody><tr>\n\
<td><div class="messages-icon">&nbsp;</div></td>\n\
<td><div class="message-text">' + message + '</div></td>\n\
</tr></tbody></table>\n\
</div>\n\
</div>';

return msg;
}

Drupal.theme.s_course_no_members_overlay = function(course_nid, showNoMembers,


showNoTags){
var output = '';

// default show no tags to false


if(typeof showNoTags == 'undefined'){
showNoTags = false;
}

// Default show no members to true


if(typeof showNoMembers == 'undefined'){
showNoMembers = true;
}

output += '<div class="s-js-no-members-overlay no-members-overlay hidden">';


if(showNoMembers){
output += '<div class="no-members-message">';
output += '<span class="inline-icon medium students mono"></span>';
output += Drupal.t('Currently there are no <a href="!
members_link">members</a> in this course', {'!members_link': '/course/' +
course_nid + '/members'});
output += '</div>';
}
if(showNoTags && !showNoMembers){
output += '<div class="no-tags-message">';
output += '<span class="inline-icon medium tags mono"></span>';
output += Drupal.t('There are no learning objectives aligned in this
course');
output += '</div>';
}
output += '</div>';

return output;
};
;// JavaScript Document
var wait_image = '/sites/all/themes/schoology_theme/images/ajax-loader.gif';
var wait_image_width = 43;
var wait_image_height = 11;

Drupal.behaviors.sGradeItem = function(context){
sGradeItemEnableCommentJump();

// cluetip
if($('#save-for-later-help', context).length){
$('#save-for-later-help', context).cluetip({splitTitle: '|', dropShadow:
false, showTitle: false, positionBy: 'auto'});
}

$('.grade-item-action-links:not(.sGradeItem-processed)',
context).addClass('sGradeItem-processed').each(function () {
$(this).sActionLinks({hidden: false, wrapper: '.action-links-
wrapper'});
});

$('.info-container .view-info:not(.sGradeItem-processed)',
context).addClass('sGradeItem-processed').each(function () {
var linkBtn = $(this);
linkBtn.bind('click', function(){
var wrapper = $(this).parent();
$('.grading-info', wrapper).toggle();
linkBtn.toggleClass('active');
return false;
}).tipsy({
'gravity': 'se'
});
});
$('body').unbind('click.sGradeViewInfo').bind('click.sGradeViewInfo',
function(e){
var linkBtn = $('.info-container .view-info', context);
var target = $(e.target);
if(linkBtn.hasClass('active') && target.not('.grading-info') &&
target.parents('.grading-info').length == 0){
linkBtn.click();
}
});
$('.info-container .link-btn:not(.sGradeItem-processed)',
context).addClass('sGradeItem-processed').each(function () {
$(this).tipsy({
'gravity': 'se'
});
});

$('.comment:not(.sGradeItem-processed)', context).addClass('sGradeItem-
processed').each(function () {
var comment = $(this);
comment.bind('mouseenter', function(){
$(".entry-links-view", comment).show();
}).bind('mouseleave', function(){
$(".entry-links-view", comment).hide();
});
});

if(typeof tinyMCE != 'undefined'){


// the comment input usually initialize when the user focuses on the textarea
// since there are many of these on the homepage
// but the one on the assignment and assessment page can be initialized on page
load since there is only one of them
$('.s_grade_item_assignment #edit-comment.s-tinymce-load-
editor:not(.sGradeItem-processed), .s_grade_item_assessment #edit-comment.s-
tinymce-load-editor:not(.sGradeItem-processed)', context).addClass('sDiscussion-
sGradeItem').each(function(){
var textareaObj = $(this),
id = textareaObj.attr('id'),
editor = tinyMCE.get(id);
if(!editor){
sTinymceInit({
elements: id,
toolbar: 'basic_comment'
});
}
});
}

$('#s-grade-item-add-attachment-form:not(.sGradeItem-processed)',
context).addClass('sGradeItem-processed').each(function() {
setTimeout(function(){
$('#file-selector').click();
},150);
});

var commentVal = "";


$(".comment-area-toggle").on("click", function () {
commentVal = $("#edit-comment-wrapper .title-infield").val();
});

$(".grade-submit-buttons .cancel-btn").on("click", function (el) {


$("#edit-comment-wrapper .title-infield").val(commentVal);
$(el.currentTarget).closest("#s-grade-item-edit-enrollment-grade-
form").removeClass("active");
});

if ($('body').hasClass('s-enable-mathml')) {
s_renderMath();
}

$('body:not(.sGradeItem-processed)', context).addClass('sGradeItem-
processed').each(function() {
var viewInfoClickHandlers;
var viewStatsClickHandlers;

$(this).on('grade-item-disable-top-controls', function() {
$('.grade-item-action-links .action-links-unfold',
context).addClass('disabled');

var viewInfoLink = $('.link-btn.view-info', context);


if (viewInfoLink.length) {
if (viewInfoLink.data('events')) {
viewInfoClickHandlers = viewInfoLink.data('events').click;
viewInfoLink.data('events').click = null;
}
viewInfoLink.addClass('disabled');
viewInfoLink.tipsy('disable');
}

var viewStatsLink = $('.link-btn.view-stats', context);


if (viewStatsLink.length) {
if (viewStatsLink.data('events')) {
viewStatsClickHandlers = viewStatsLink.data('events').click;
viewStatsLink.data('events').click = null;
}

viewStatsLink.addClass('disabled');
viewStatsLink.tipsy('disable');
viewStatsLink.click(function(e) { e.preventDefault(); });
}

$('.assessment-status-wrapper', context).addClass('disabled');
});

$(this).on('grade-item-enable-top-controls', function() {
$('.grade-item-action-links .action-links-unfold',
context).removeClass('disabled');

var viewInfoLink = $('.link-btn.view-info', context);


if (viewInfoLink.length) {
viewInfoLink.removeClass('disabled').tipsy('enable');
if (viewInfoLink.data('events')) {
viewInfoLink.data('events').click = viewInfoClickHandlers;
}
}

var viewStatsLink = $('.link-btn.view-stats', context);


if (viewStatsLink.length) {
viewStatsLink.removeClass('disabled').tipsy('enable');
if (viewStatsLink.data('events')) {
viewStatsLink.data('events').click = viewStatsClickHandlers;
}
}

$('.assessment-status-wrapper', context).removeClass('disabled');
});
});
};

function sGradeItemEnableCommentJump(){

$(".go-to-reply").click(function() {
var el = $(this).parent().parent().parent().parent();
if (location.pathname.replace(/^\//,'') ==
this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
$(target).effect("highlight", {color: "#f9b974"}, 3000);
target = target.length && target || $('[name=' + this.hash.slice(1) +']');
if (target.length) {
var targetOffset = target.offset().top-20;
$('html,body').animate({scrollTop: targetOffset}, 500);
return false;
}
}
});
}

/**
* Ajax plugins callback
*
* @param {String} hook
* @param {Object} args
* @return {Bool}
*/

Drupal.Ajax.plugins.s_grade_item = function(hook, args) {


if(hook == 'message') { // response received, return false to hide messages
var submitter = args.local.submitter;
formObj = submitter.closest('.post-comment-form');

if(formObj.length){
if(typeof args.redirect == 'string' && args.redirect.length > 0){
window.location.href = args.redirect;
}
else{
var validateOutput = args.ajax_validate_output;
var submitOutput = args.ajax_submit_output;

var id = 'comment-container';
var content = '';
// Display the submit output if set, otherwise display validate output
if(submitOutput != undefined)
content = submitOutput;
else if(validateOutput != undefined)
content = validateOutput;

if($("."+id+" #s_comments").length > 0){ //append to existing comment


wrapper
$("."+id+" #s_comments").fadeIn(5000, function(){
var contentObj = $(content);
$("."+id+" #s_comments").append(contentObj);
Drupal.attachBehaviors(contentObj);
});
}
else{ //create own comment wrapper
var html = '<div id="s_comments">'+content+'</div>';
var contentObj = $(html);
$(".no-comments").replaceWith(contentObj);
Drupal.attachBehaviors(contentObj);
}
var editorObj = formObj.find('.s-tinymce-load-editor');
if(editorObj.length){
var ed = tinyMCE.get(editorObj.attr('id'));
if(ed){
ed.setContent('');
ed.save();
}
}
return false;
}
}
}
return false;
}
;
var wait_image = '/sites/all/themes/schoology_theme/images/ajax-loader.gif';
var wait_image_width = 43;
var wait_image_height = 11;

/**
* Ajax plugins callback
*
* @param {String} hook
* @param {Object} args
* @return {Bool}
*/
Drupal.Ajax.plugins.s_comment = function(hook, args) {

switch( hook ) {
case 'submit':
var submitter = args.submitter,
formObj = submitter.closest('form'),
editorObj = formObj.find('.s-tinymce-load-editor');
if(formObj.hasClass('post-comment-form')){
submitter.attr('disabled', 'disabled').parent().addClass('disabled');
}
if(editorObj.length){
var ed = tinyMCE.get(editorObj.attr('id'));
if(ed){
ed.save();
}
}
break;

case 'message':
var submitter = args.local.submitter;
var commentForm = submitter.parents('form');
if(!submitter.parents('form').hasClass('post-comment-form')){
return;
}

// reenable the submit button if the form's disable_submit flag is set to


FALSE
var submitEnabledForm = (submitter.parents('.submit-enabled').length > 0);
if(submitEnabledForm){
submitter.attr('disabled', false).parent().removeClass('disabled');
}

var validateOutput = args.ajax_validate_output;


var submitOutput;
var allComments;
if(typeof(args.ajax_submit_output) == 'object') {
submitOutput = args.ajax_submit_output.newComment;
allComments = args.ajax_submit_output.allComments;
}
else {
submitOutput = args.ajax_submit_output;
}
var footerComments = submitter.closest(":has(.feed-comments, .blog-
comments, .discussion-content, .album-comments, .update-comments)")
.find('.feed-comments, .blog-comments, .discussion-content, .album-
comments, .update-comments');
var feedContent = footerComments.parent();
var content = '';
var isDiscussion = $('body').hasClass('discussion-view');

// Display the submit output if set, otherwise display validate output


if(submitOutput != undefined)
content = submitOutput;
else if(validateOutput != undefined)
content = validateOutput;

// discussion comments, hide the 'no comments' message


$("p.no-discussion",$(".discussion-content")).hide()

//Post comment gets added to end of discussion thread in this block


if(footerComments.find("#s_comments").length > 0) {
footerComments.find("#s_comments").fadeIn(5000, function(){
var contentObj = $("<div class='discussion-card'></div>");
contentObj.append(content);

if(isDiscussion) {
$(this).prepend(contentObj);
} else {
$(this).append(contentObj);
}
Drupal.attachBehaviors(contentObj);
// submission failed (ie, discussion is locked)
var is_locked = false;
for (i = 0; i < args.messages_error.length; ++i) {
if(args.messages_error[i].value == 'This discussion is locked') {
is_locked = true;
}
}
if(is_locked) {
footerComments.find("textarea")
.attr('defaulttext', footerComments.find("textarea").val())
.addClass('is-locked');
}
sCommentScrollToNewComment(contentObj, 750, ":has(.s-comments-post-form-
new)");
if(isDiscussion){
var colorString = "rgba(213,227, 241, 0.6)";
contentObj.effect("highlight", {color: colorString}, 3000);
}
});
}
else {
var contentObj = $('<div id="s_comments"><div class="discussion-
card">'+content+'</div></div>');
if(isDiscussion){
var colorString = "rgba(213,227, 241, 0.6)";
footerComments.find(".s-comments-post-form").after(contentObj);
contentObj.effect("highlight", {color: colorString}, 3000);
} else {
footerComments.find(".s-comments-post-form").before(contentObj);
}
Drupal.attachBehaviors(contentObj);
}

// clear the user input


var inputObj = commentForm.find('textarea');
if(inputObj.length){
if(inputObj.hasClass('s-tinymce-load-editor')){
var ed = tinyMCE.get(inputObj.attr('id'));
if(ed){
ed.setContent('');
ed.save();
}
}
else{
inputObj.val('').trigger('blur');
}
}

// show all comments; remove disabled classes


// activate stats filter
if(allComments) {
for(var cid in allComments) {
var commentWrapper = footerComments.find("#comment-" + cid);
var commentBodyWrapper = $(".comment-body-wrapper", commentWrapper);
var commentTopWrapper = $(".comment-top", commentWrapper);
commentBodyWrapper.removeClass('disabled');

// The html is encoded because of check_plain, so we need to decode it.


// Textarea is used since no html elements are allowed in a textarea,
making it safer against XSS.
// If there happens to be html elements, it will be encoded by the
browser.
var commentBody = $('<textarea/>').html(allComments[cid].body).val();
commentBodyWrapper.html(commentBody);
$(allComments[cid].attachments).insertAfter(commentTopWrapper);
commentWrapper.removeClass('disabled');
$(".comment-reply", commentWrapper).removeClass('disabled').show();
}
Drupal.attachBehaviors(footerComments);
footerComments.prev('.discussion-require-post-notice').remove();
var courseInfo = footerComments.parents('.course-discussion');
$('#discussion-user-stats-wrapper', courseInfo).removeClass('disabled');
sAttachBehaviors(['s_discussion'], courseInfo);
}
// for update commment popup, resize and center
if( footerComments.hasClass('update-comments') ){
popup = Popups.activePopup();
if(popup) Popups.resizeAndCenter(popup);
}

var numCommentsLink = feedContent.find(".feed-footer").find("span.ajax-post-


comment");
var text = numCommentsLink.text();
var splice = text.split(" ");
var comments = splice[0];
var suffix = splice[1];

if(comments == 1)
suffix = splice[1]+"s";

++comments;
numCommentsLink.text(comments+ " "+suffix);
//resize textarea back to default size of 32 pixels
$('#edit-comment-wrapper #edit-comment', commentForm).css('height', '32px');

break;

case 'afterMessage':
// reset attachment form
if(!args.ajax_submit_output)
return;

if ($('#attachments').length > 0){


resetAttachmentForm();

//reset basic attachment form


sAttachmentResetBasicUploader();

//in certain areas (school updates, course/group discussions) need to


adjust DOM when using the basic uploader
unWantedForm = $('#edit-file-swf-wrapper .upload-form');
if (unWantedForm){
$('#edit-file-swf-wrapper').append(unWantedForm.children('input'));
unWantedForm.remove();
}
}

if ($('li#file-selector').hasClass('active')){
$('li#file-selector').removeClass('active');
}

break;
}
}

;// JavaScript Document

var wait_image = '/sites/all/themes/schoology_theme/images/ajax-loader.gif';


var wait_image_width = 43;
var wait_image_height = 11;

/**
* Ajax plugins callback
*
* @param {String} hook
* @param {Object} args
* @return {Bool}
*/
Drupal.Ajax.plugins.s_comment_reply = function(hook, args) {
switch(hook){
case 'submit': // submitting the form
// disable the submit button
var submitter = args.submitter;
submitter.attr('disabled', 'disabled').parent().addClass('disabled');
break;
case 'message': // response received, return false to hide messages
var submitter = args.local.submitter;
var form = submitter.parents('form');
if(form.attr('id') == 's-comment-reply-form'){
if(typeof args.redirect == 'string' && args.redirect.length > 0){
window.location.href = args.redirect;
}
else{
// reenable the submit button
submitter.attr('disabled', false).parent().removeClass('disabled');

var validateOutput = args.ajax_validate_output;


var submitOutput = args.ajax_submit_output;

var content = '';


// Display the submit output if set, otherwise display validate output
if(submitOutput != undefined){
// clear the rich text or input text area
var inputObj = form.find('textarea');
if(inputObj.length){
if(inputObj.hasClass('s-tinymce-load-editor')){
var ed = tinyMCE.get(inputObj.attr('id'));
if(ed){
ed.setContent('');
ed.save();
}
}
else{
inputObj.val('').trigger('blur');
}
}

content = submitOutput;

var parentComment = submitter.parents('.comment').eq(0);


var replyLevel = parentComment.next('.s_comments_level');
// if the next level of replies does not yet exist, create it
if(replyLevel.length == 0){
replyLevel = $('<div class="s_comments_level"></div>');

// Add nested class if needed


var parentCommentLevel = parentComment.parent('.s_comments_level');
if(parentCommentLevel && parentCommentLevel.hasClass('nested-
threshold-exceeded')) {
replyLevel.addClass('nested-threshold-exceeded');
}
parentComment.after(replyLevel);
}
var newComment = $(content);
replyLevel.append(newComment);
form.parent().hide();

// Discussion only behavior


var isDiscussion = $('body').hasClass('discussion-view');
var colorString = "#f9b974";
sCommentScrollToNewComment(newComment, 500);
if(isDiscussion){
colorString = "rgba(213,227, 241, 0.6)";
}
newComment.effect("highlight", {color: colorString}, 3000);

Drupal.attachBehaviors(replyLevel);
} else if(validateOutput != undefined) {
content = validateOutput;
}

//increment the thread counter and show the hide link if exists
var threadRoot = submitter.closest('.thread-root');
var expanderBar = threadRoot.prev();
//ensure its not a pending comment
var contentObj = $(content);
var isPending = $('.pending-comment', contentObj).length > 0;
if(expanderBar.hasClass('expander-bar') && !isPending){
var numRepliesWrapper = $('.num-replies', expanderBar);
var numReplies = numRepliesWrapper.text();
var expandText = $('.expander-text', expanderBar);
var hideText = $('.expander-hide-text', expanderBar);
numReplies = parseInt(numReplies);
numReplies++;
numRepliesWrapper.html(numReplies);
expandText.html(Drupal.formatPlural(numReplies, '1 Reply', '@count
Replies'));
hideText.html(Drupal.formatPlural(numReplies, 'Hide 1 reply', 'Hide All
@count Replies'));
if (numReplies == 1) {
$('.expander-link-expanded', expanderBar).removeClass('hidden');
}
}
}
}
break;
}
}
;

You might also like