parent
50062d9d68
commit
698ec0e2c7
@ -1,99 +1,113 @@ |
|||||||
|
|
||||||
function createWord( word ) |
function createWord( word ) |
||||||
{ |
{ |
||||||
var s = ''; |
var s = ''; |
||||||
for( var i = 0; i < word.length; i++ ) |
for( var i = 0; i < word.length; i++ ) |
||||||
{ |
{ |
||||||
ch = word.charAt( i ); |
ch = word.charAt( i ); |
||||||
s +=
|
s +=
|
||||||
'<span class="upper">' + |
'<span class="upper">' + |
||||||
'<span>' + ch + '</span>' + |
'<span>' + ch + '</span>' + |
||||||
(( i < word.length - 1 ) ? |
(( i < word.length - 1 ) ? |
||||||
'<span class="dash">–</span>' : '' ) + |
'<span class="dash">–</span>' : '' ) + |
||||||
'</span>'; |
'</span>'; |
||||||
} |
} |
||||||
return s; |
return s; |
||||||
} |
} |
||||||
|
|
||||||
$(document).ready(function() |
$(document).ready(function() |
||||||
{ |
{ |
||||||
var w = new wcontainer( "#ub-widget" ); |
var w = new wcontainer( "#ub-widget" ); |
||||||
|
var words = ""; |
||||||
|
|
||||||
|
if(window.sankore) |
||||||
|
words = (sankore.preference("ordSplWords", ""))?sankore.preference("ordSplWords", ""):"so*phis*ti*ca*ted"; |
||||||
|
else |
||||||
|
words = "so*phis*ti*ca*ted"; |
||||||
|
w.setEditContent( '<div class="inputwrap"><input class="percent" value="' + words + '"></div>' ); |
||||||
|
w.setViewContent( '<span class="upper"><span class="dash fixed">—</span></span>' ); |
||||||
|
w.setData( "dashWidth", w.elements.container.find( "span.dash" ).outerWidth() ); |
||||||
|
w.setViewContent( "" ); |
||||||
|
|
||||||
w.setEditContent( '<div class="inputwrap"><input class="percent" value="so*phis*ti*ca*ted"></div>' ); |
// onViewMode
|
||||||
w.setViewContent( '<span class="upper"><span class="dash fixed">—</span></span>' ); |
w.onViewMode = function() |
||||||
w.setData( "dashWidth", w.elements.container.find( "span.dash" ).outerWidth() ); |
{ |
||||||
w.setViewContent( "" ); |
var word = w.elements.container.find( "input" ).val().trim( ['*'] ); |
||||||
|
|
||||||
// onViewMode
|
|
||||||
w.onViewMode = function() |
|
||||||
{ |
|
||||||
var word = w.elements.container.find( "input" ).val().trim( ['*'] ); |
|
||||||
|
|
||||||
w.setData( "word", word ); |
w.setData( "word", word ); |
||||||
word = word.replace( /\*/g, '' ); |
word = word.replace( /\*/g, '' ); |
||||||
w.setViewContent( createWord( word ) ); |
w.setViewContent( createWord( word ) ); |
||||||
w.elements.container.find( "span.upper" ).click( function(){ |
w.elements.container.find( "span.upper" ).click( function(){ |
||||||
$( this ).find( "span.dash" ).toggleClass( "fixed" ); |
$( this ).find( "span.dash" ).toggleClass( "fixed" ); |
||||||
w.adjustSize(); |
w.adjustSize(); |
||||||
w.checkAnswer(); |
w.checkAnswer(); |
||||||
}); |
}); |
||||||
w.checkAnswer(); |
w.checkAnswer(); |
||||||
}; |
}; |
||||||
|
|
||||||
// viewSize
|
// viewSize
|
||||||
w.viewSize = function() |
w.viewSize = function() |
||||||
{ |
{ |
||||||
var w = 0; |
var w = 0; |
||||||
var h = 0; |
var h = 0; |
||||||
|
|
||||||
winstance.elements.containerView.find( "span.upper span:visible" ).each( function() |
winstance.elements.containerView.find( "span.upper span:visible" ).each( function() |
||||||
{ |
{ |
||||||
w += $( this ).outerWidth(); |
w += $( this ).outerWidth(); |
||||||
h = Math.max( h, $( this ).outerHeight() ); |
h = Math.max( h, $( this ).outerHeight() ); |
||||||
}); |
}); |
||||||
var dw = winstance.getData( "dashWidth" ); |
var dw = winstance.getData( "dashWidth" ); |
||||||
|
|
||||||
return { w: w+dw, h: h }; |
return { |
||||||
}; |
w: w+dw,
|
||||||
|
h: h |
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
// editSize
|
// editSize
|
||||||
w.editSize = function() |
w.editSize = function() |
||||||
{ |
{ |
||||||
return { |
return { |
||||||
w: winstance.elements.containerEdit.find( "input" ).outerWidth( true ), |
w: winstance.elements.containerEdit.find( "input" ).outerWidth( true ), |
||||||
h: winstance.elements.containerEdit.find( "input" ).outerHeight( true ), |
h: winstance.elements.containerEdit.find( "input" ).outerHeight( true ), |
||||||
}; |
}; |
||||||
}; |
}; |
||||||
|
|
||||||
|
|
||||||
w.checkAnswer = function() |
w.checkAnswer = function() |
||||||
{ |
{ |
||||||
var word = ""; |
var word = ""; |
||||||
this.elements.container.find( "span.upper span:visible" ).each( function() |
this.elements.container.find( "span.upper span:visible" ).each( function() |
||||||
{ |
{ |
||||||
if( this.className.indexOf( "fixed" ) != -1 ){ |
if( this.className.indexOf( "fixed" ) != -1 ){ |
||||||
word += '*'; |
word += '*'; |
||||||
} |
} |
||||||
else if( this.className.indexOf( "dash" ) != -1 ){ |
else if( this.className.indexOf( "dash" ) != -1 ){ |
||||||
return; |
return; |
||||||
} |
} |
||||||
else{ |
else{ |
||||||
word += $( this ).text(); |
word += $( this ).text(); |
||||||
} |
} |
||||||
}); |
}); |
||||||
|
|
||||||
if( word == this.getData( "word" ) ){ |
if( word == this.getData( "word" ) ){ |
||||||
this.elements.container.addClass( "answerRight" ); |
this.elements.container.addClass( "answerRight" ); |
||||||
} |
} |
||||||
else{ |
else{ |
||||||
this.elements.container.removeClass( "answerRight" ); |
this.elements.container.removeClass( "answerRight" ); |
||||||
} |
} |
||||||
}; |
}; |
||||||
|
|
||||||
|
|
||||||
window.w = w; |
window.w = w; |
||||||
window.winstance = w; |
window.winstance = w; |
||||||
|
|
||||||
w.modeView(); |
w.modeView(); |
||||||
|
|
||||||
|
$(window).mouseout(function(){ |
||||||
|
if(window.sankore){ |
||||||
|
sankore.setPreference("ordSplWords", w.getData("word")); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
}); |
}); |
Loading…
Reference in new issue