новые иконки в OpenBoard
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OpenBoard/resources/library/interactivities/spl-text.wgt/scripts/wcontainer.js

260 lines
6.9 KiB

var sankoreLang = {
view: "View",
edit: "Edit",
example: "hello, this is the first sentence. hi, this is the second sentence. hello again, this is the third sentence. good morning, this is the fourth sentence. hi, sorry, i\'m late, i\'m the fifth sentence."
};
13 years ago
// if use the "view/edit" button or rely on the api instead
var isSankore = false;
// whether to do window.resize or not (window = widget area)
var isBrowser = ( typeof( widget ) == "undefined" );
function wcontainer( containerID )
{
// some protecred variables
var thisInstance = this;
this.editMode = false;
var data = {}; // see setData and getData
13 years ago
// widget size parameters
this.minHeight = 100;
this.minWidth = 400;
13 years ago
// set to 0 for no max width restriction
this.maxWidth = 0;
13 years ago
// links to the elements of the widget
this.elements = {};
13 years ago
/*
13 years ago
============
create
============
- creates html base, inits this.elements, assings events
*/
this.create = function( containerID )
{
var html =
'<div id="mp_setup">' +
'<div class="viewmode">' +
'<button>' + sankoreLang.edit + '</button>' +
'</div>' +
'<div class="editmode">' +
'<button>' + sankoreLang.view + '</button>' +
'</div>' +
'</div>' +
'<div id="mp_content">' +
'<div class="viewmode" id="mp_view">' +
'</div>' +
'<div class="editmode" id="mp_edit">' +
'</div>' +
'</div>';
13 years ago
var container = $( containerID );
13 years ago
container.append( html );
this.elements.edit = container.find( ".editmode" );
this.elements.view = container.find( ".viewmode" );
this.elements.container = container;
this.elements.subcontainer = container.find( "#mp_content" );
this.elements.containerView = this.elements.subcontainer.find( ".viewmode" );
this.elements.containerEdit = this.elements.subcontainer.find( ".editmode" );
13 years ago
container.find( ".viewmode button" ).click( function(){
thisInstance.modeEdit();
} );
13 years ago
container.find( ".editmode button" ).click( function(){
thisInstance.modeView();
} );
};
13 years ago
/*
13 years ago
===============
setViewContent
===============
- assigns custom html to the viewmode container
*/
this.setViewContent = function( html )
{
this.elements.container.find( "#mp_content .viewmode" ).html( html );
};
13 years ago
/*
13 years ago
===============
setEditContent
===============
- assigns custom html to the editmode container
*/
this.setEditContent = function( html )
{
this.elements.container.find( "#mp_content .editmode" ).html( html );
};
13 years ago
/*
13 years ago
=========================
modeEdit and modeView
=========================
- switch the widget betweed modes
* for customization extend onEditMode and onViewMode
*/
this.modeEdit = function()
{
this.onEditMode();
this.editMode = true;
this.elements.edit.removeClass( "hide" );
this.elements.view.addClass( "hide" );
13 years ago
this.adjustSize();
};
this.modeView = function()
{
this.onViewMode();
this.editMode = false;
this.elements.edit.addClass( "hide" );
this.elements.view.removeClass( "hide" );
13 years ago
this.adjustSize();
};
13 years ago
/*
13 years ago
================
adjustSize
================
- changes the widget size (window and container)
*/
this.adjustSize = function( width, height )
{
// retrieve the arguments
if( arguments.length < 2 )
{
var s = ( this.editMode )? this.editSize() : this.viewSize();
var width = s.w;
var height = s.h;
}
13 years ago
// check for validity
if( width + height == 0 )
return;
13 years ago
// add view/edit bar height
if( !isSankore ){
height += $( this.elements.container ).find( "#mp_setup" ).outerHeight();
}
13 years ago
// apply min and max restrictions
width = Math.max( this.minWidth, width );
height = Math.max( this.minHeight, height );
if( this.maxWidth ){
width = Math.min( width, this.maxWidth );
}
13 years ago
// if viewed as a widget, resize the window
if( !isBrowser )
{
var dw = this.getData( "dw" );
var dh = this.getData( "dh" );
13 years ago
if( width == 0 ){
width = widget.width;
}
if( height == 0 ){
height = widget.height;
}
window.resizeTo( width + dw, height + dh );
}
13 years ago
// resize the container
var params = {};
if( width != 0 ){
params.width = width;
}
if( height != 0 ){
params.height = height;
}
13 years ago
this.elements.container.animate( params );
13 years ago
};
13 years ago
/*
13 years ago
======================
setData and getData
======================
- store some data inside
*/
this.setData = function( name, value ){
data[name] = value;
};
this.getData = function( name ){
if( typeof( data[name] ) == "undefined" ){
return null;
} else return data[name];
};
13 years ago
// redefinable methods
13 years ago
/*
13 years ago
==========================
onEditMode and onViewMode
==========================
- these are called when the mode is being changed
*/
this.onEditMode = function(){
//
};
this.onViewMode = function(){
//
};
/*
13 years ago
======================
viewSize and editSize
======================
- calculate container size for the adjustSize method
* they are likely to be redefined for each particular widget
*/
this.viewSize = function(){
return {
w: this.elements.containerView.outerWidth(),
h: this.elements.containerView.outerHeight()
};
};
this.editSize = function(){
return {
w: this.elements.containerEdit.outerWidth(),
h: this.elements.containerEdit.outerHeight()
};
};
/*
13 years ago
=====================
checkAnswer
=====================
- check if the exercise in the view mode was done right
* redefine it for each particular widget
*/
this.checkAnswer = function()
{
//
};
// constructor end
// if the constructor was called with a parameter,
// call create() automatically
if( arguments.length > 0 ){
this.create( containerID );
}
this.setData( "dw", this.elements.container.outerWidth( true ) - this.elements.container.width() );
this.setData( "dh", this.elements.container.outerHeight( true ) - this.elements.container.height() );
window.winstance = thisInstance;
13 years ago
}