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 = ""; |
||||||
w.setEditContent( '<div class="inputwrap"><input class="percent" value="so*phis*ti*ca*ted"></div>' ); |
|
||||||
w.setViewContent( '<span class="upper"><span class="dash fixed">—</span></span>' ); |
if(window.sankore) |
||||||
w.setData( "dashWidth", w.elements.container.find( "span.dash" ).outerWidth() ); |
words = (sankore.preference("ordSplWords", ""))?sankore.preference("ordSplWords", ""):"so*phis*ti*ca*ted"; |
||||||
w.setViewContent( "" ); |
else |
||||||
|
words = "so*phis*ti*ca*ted"; |
||||||
// onViewMode
|
w.setEditContent( '<div class="inputwrap"><input class="percent" value="' + words + '"></div>' ); |
||||||
w.onViewMode = function() |
w.setViewContent( '<span class="upper"><span class="dash fixed">—</span></span>' ); |
||||||
{ |
w.setData( "dashWidth", w.elements.container.find( "span.dash" ).outerWidth() ); |
||||||
var word = w.elements.container.find( "input" ).val().trim( ['*'] ); |
w.setViewContent( "" ); |
||||||
|
|
||||||
w.setData( "word", word ); |
// onViewMode
|
||||||
word = word.replace( /\*/g, '' ); |
w.onViewMode = function() |
||||||
w.setViewContent( createWord( word ) ); |
{ |
||||||
w.elements.container.find( "span.upper" ).click( function(){ |
var word = w.elements.container.find( "input" ).val().trim( ['*'] ); |
||||||
$( this ).find( "span.dash" ).toggleClass( "fixed" ); |
|
||||||
w.adjustSize(); |
w.setData( "word", word ); |
||||||
w.checkAnswer(); |
word = word.replace( /\*/g, '' ); |
||||||
}); |
w.setViewContent( createWord( word ) ); |
||||||
w.checkAnswer(); |
w.elements.container.find( "span.upper" ).click( function(){ |
||||||
}; |
$( this ).find( "span.dash" ).toggleClass( "fixed" ); |
||||||
|
w.adjustSize(); |
||||||
// viewSize
|
w.checkAnswer(); |
||||||
w.viewSize = function() |
}); |
||||||
{ |
w.checkAnswer(); |
||||||
var w = 0; |
}; |
||||||
var h = 0; |
|
||||||
|
// viewSize
|
||||||
winstance.elements.containerView.find( "span.upper span:visible" ).each( function() |
w.viewSize = function() |
||||||
{ |
{ |
||||||
w += $( this ).outerWidth(); |
var w = 0; |
||||||
h = Math.max( h, $( this ).outerHeight() ); |
var h = 0; |
||||||
}); |
|
||||||
var dw = winstance.getData( "dashWidth" ); |
winstance.elements.containerView.find( "span.upper span:visible" ).each( function() |
||||||
|
{ |
||||||
return { w: w+dw, h: h }; |
w += $( this ).outerWidth(); |
||||||
}; |
h = Math.max( h, $( this ).outerHeight() ); |
||||||
|
}); |
||||||
// editSize
|
var dw = winstance.getData( "dashWidth" ); |
||||||
w.editSize = function() |
|
||||||
{ |
return { |
||||||
return { |
w: w+dw,
|
||||||
w: winstance.elements.containerEdit.find( "input" ).outerWidth( true ), |
h: h |
||||||
h: winstance.elements.containerEdit.find( "input" ).outerHeight( true ), |
}; |
||||||
}; |
}; |
||||||
}; |
|
||||||
|
// editSize
|
||||||
|
w.editSize = function() |
||||||
w.checkAnswer = function() |
{ |
||||||
{ |
return { |
||||||
var word = ""; |
w: winstance.elements.containerEdit.find( "input" ).outerWidth( true ), |
||||||
this.elements.container.find( "span.upper span:visible" ).each( function() |
h: winstance.elements.containerEdit.find( "input" ).outerHeight( true ), |
||||||
{ |
}; |
||||||
if( this.className.indexOf( "fixed" ) != -1 ){ |
}; |
||||||
word += '*'; |
|
||||||
} |
|
||||||
else if( this.className.indexOf( "dash" ) != -1 ){ |
w.checkAnswer = function() |
||||||
return; |
{ |
||||||
} |
var word = ""; |
||||||
else{ |
this.elements.container.find( "span.upper span:visible" ).each( function() |
||||||
word += $( this ).text(); |
{ |
||||||
} |
if( this.className.indexOf( "fixed" ) != -1 ){ |
||||||
}); |
word += '*'; |
||||||
|
} |
||||||
if( word == this.getData( "word" ) ){ |
else if( this.className.indexOf( "dash" ) != -1 ){ |
||||||
this.elements.container.addClass( "answerRight" ); |
return; |
||||||
} |
} |
||||||
else{ |
else{ |
||||||
this.elements.container.removeClass( "answerRight" ); |
word += $( this ).text(); |
||||||
} |
} |
||||||
}; |
}); |
||||||
|
|
||||||
|
if( word == this.getData( "word" ) ){ |
||||||
window.w = w; |
this.elements.container.addClass( "answerRight" ); |
||||||
window.winstance = w; |
} |
||||||
|
else{ |
||||||
w.modeView(); |
this.elements.container.removeClass( "answerRight" ); |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
window.w = w; |
||||||
|
window.winstance = w; |
||||||
|
|
||||||
|
w.modeView(); |
||||||
|
|
||||||
|
$(window).mouseout(function(){ |
||||||
|
if(window.sankore){ |
||||||
|
sankore.setPreference("ordSplWords", w.getData("word")); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
}); |
}); |
Loading…
Reference in new issue