Skip to content

Commit

Permalink
Dev: Fixes for frontend rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Nov 14, 2017
1 parent 34aa89b commit e4d4651
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 16 deletions.
1 change: 1 addition & 0 deletions application/config/packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
'question-numeric-slider'=>array(
'devBaseUrl' => 'assets/packages/questions/numeric-slider/',
'basePath' => 'core.questions.numeric-slider',
'position' => CClientScript::POS_BEGIN,
'css'=> array(
'numeric-slider.css',
),
Expand Down
1 change: 1 addition & 0 deletions application/config/third_party.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
'jqueryui' => array(
'devBaseUrl' => 'third_party/jquery-ui',
'basePath' => 'third_party.jquery-ui',
'position' => CClientScript::POS_BEGIN,
'js' => array(
'jquery-ui'.$minVersion.'.js',
),
Expand Down
10 changes: 5 additions & 5 deletions application/core/LSYii_ClientScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ public function renderBodyBegin(&$output)
*/
public function renderBodyEnd(&$output)
{
if(!isset($this->scriptFiles[self::POS_END]) && !isset($this->scripts[self::POS_END])
&& !isset($this->scripts[self::POS_READY]) && !isset($this->scripts[self::POS_LOAD]) && !isset($this->scripts[self::POS_POSTSCRIPT]))
if(!isset($this->scriptFiles[self::POS_END]) && !isset($this->scripts[self::POS_READY])
&& !isset($this->scripts[self::POS_LOAD]) && !isset($this->scripts[self::POS_POSTSCRIPT]))
{
str_replace('<###end###>','',$output);
return;
Expand Down Expand Up @@ -516,15 +516,15 @@ public function renderBodyEnd(&$output)
if(isset($this->scripts[self::POS_LOAD]))
{
if($fullPage) //This part is different to reflect the changes needed in the backend by the pjax loading of pages
$scripts[]="jQuery(document).on('load pjax:complete',function() {\n".implode("\n",$this->scripts[self::POS_LOAD])."\n});";
$scripts[]="jQuery(document).on('ready pjax:complete',function() {\n".implode("\n",$this->scripts[self::POS_LOAD])."\n});";
else
$scripts[]=implode("\n",$this->scripts[self::POS_LOAD]);
}

if(isset($this->scripts[self::POS_POSTSCRIPT]))
{
if($fullPage) //This part is different to reflect the changes needed in the backend by the pjax loading of pages
$scripts[]="jQuery(document).on('load pjax:scriptcomplete',function() {\nconsole.log('loading on scriptcomplete');\n".implode("\n",$this->scripts[self::POS_POSTSCRIPT])."\n});";
$scripts[]="jQuery(document).on('ready pjax:scriptcomplete', function() {\nconsole.log('loading on scriptcomplete');\n".implode("\n",$this->scripts[self::POS_POSTSCRIPT])."\n});";
else
$scripts[]=implode("\n",$this->scripts[self::POS_POSTSCRIPT]);
}
Expand All @@ -538,7 +538,7 @@ public function renderBodyEnd(&$output)

if($fullPage)
{
$output=str_replace('<###end###>',$html,$output);
$output=preg_replace('/<###end###>/',$html,$output,1);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/qanda_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2560,7 +2560,7 @@ function do_multiplechoice_withcomments($ia)
if($aQuestionAttributes['commented_checkbox']!="allways" && $aQuestionAttributes['commented_checkbox_auto'])
{
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."multiplechoice_withcomments.js", LSYii_ClientScript::POS_BEGIN);
Yii::app()->getClientScript()->registerScript("doMultipleChoiceWithComments{$ia[0]}","doMultipleChoiceWithComments({$ia[0]},'{$aQuestionAttributes["commented_checkbox"]}');",LSYii_ClientScript::POS_POSTSCRIPT);
Yii::app()->getClientScript()->registerScript("doMultipleChoiceWithComments{$ia[0]}","doMultipleChoiceWithComments({$ia[0]},'{$aQuestionAttributes["commented_checkbox"]}');",LSYii_ClientScript::POS_LOAD);
}

return array($answer, $inputnames);
Expand Down
2 changes: 1 addition & 1 deletion application/models/AdminTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function registerStylesAndScripts()
App()->getClientScript()->registerScript('coreuser', '
LS.globalUserId = "'.Yii::app()->user->id.'";', CClientScript::POS_HEAD);
App()->getClientScript()->registerPackage('jquery'); // jquery
App()->getClientScript()->registerPackage('jqueryui'); // jqueryui
// App()->getClientScript()->registerPackage('jqueryui'); // jqueryui
App()->getClientScript()->registerPackage('js-cookie'); // js-cookie
App()->getClientScript()->registerPackage('fontawesome'); // fontawesome
App()->getClientScript()->registerPackage('bootstrap-switch');
Expand Down
49 changes: 45 additions & 4 deletions assets/packages/pjax/pjax.js

Large diffs are not rendered by default.

47 changes: 44 additions & 3 deletions assets/packages/pjax/pjax.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Pjax.prototype = {

attachForm: require("./lib/proto/attach-form.js"),

updateStylesheets: require("./lib/update-stylesheets.js"),

forEachSelectors: function(cb, context, DOMcontext) {
return require("./lib/foreach-selectors.js").bind(this)(this.options.selectors, cb, context, DOMcontext)
},
Expand All @@ -65,6 +67,7 @@ Pjax.prototype = {
return require("./lib/switches-selectors.js").bind(this)(this.options.switches, this.options.switchesOptions, selectors, fromEl, toEl, options)
},


// too much problem with the code below
// + it’s too dangerous
// switchFallback: function(fromEl, toEl) {
Expand Down Expand Up @@ -120,6 +123,11 @@ Pjax.prototype = {
// try {
this.switchSelectors(this.options.selectors, tmpEl, document, options)

//reset stylesheets if activated
if(this.options.reRenderCSS === true){
this.updateStylesheets.call(this, tmpEl.querySelectorAll('link[rel=stylesheet]'), document.querySelectorAll('link[rel=stylesheet]'));
}

// FF bug: Won’t autofocus fields that are inserted via JS.
// This behavior is incorrect. So if theres no current focus, autofocus
// the last field.
Expand Down Expand Up @@ -250,7 +258,7 @@ else {
module.exports = stupidPjax
}

},{"./lib/clone.js":2,"./lib/events/on.js":4,"./lib/events/trigger.js":5,"./lib/execute-scripts.js":6,"./lib/foreach-els.js":7,"./lib/foreach-selectors.js":8,"./lib/is-supported.js":9,"./lib/proto/attach-form.js":11,"./lib/proto/attach-link.js":12,"./lib/proto/get-elements.js":13,"./lib/proto/log.js":14,"./lib/proto/parse-dom.js":15,"./lib/proto/parse-options.js":17,"./lib/proto/refresh.js":18,"./lib/reload.js":19,"./lib/request.js":20,"./lib/switches-selectors.js":21,"./lib/uniqueid.js":23}],2:[function(require,module,exports){
},{"./lib/clone.js":2,"./lib/events/on.js":4,"./lib/events/trigger.js":5,"./lib/execute-scripts.js":6,"./lib/foreach-els.js":7,"./lib/foreach-selectors.js":8,"./lib/is-supported.js":9,"./lib/proto/attach-form.js":11,"./lib/proto/attach-link.js":12,"./lib/proto/get-elements.js":13,"./lib/proto/log.js":14,"./lib/proto/parse-dom.js":15,"./lib/proto/parse-options.js":17,"./lib/proto/refresh.js":18,"./lib/reload.js":19,"./lib/request.js":20,"./lib/switches-selectors.js":21,"./lib/uniqueid.js":23,"./lib/update-stylesheets.js":24}],2:[function(require,module,exports){
module.exports = function(obj) {
if (null === obj || "object" != typeof obj) {
return obj
Expand Down Expand Up @@ -690,7 +698,8 @@ module.exports = function(el) {

module.exports = function(options){
this.options = options
this.options.elements = this.options.elements || "a[href], form[action]"
this.options.elements = this.options.elements || "a[href], form[action]",
this.options.reRenderCSS = this.options.reRenderCSS || false,
this.options.mainScriptElement = this.options.mainScriptElement || "head"
this.options.selectors = this.options.selectors || ["title", ".js-Pjax"]
this.options.switches = this.options.switches || {}
Expand Down Expand Up @@ -937,5 +946,37 @@ module.exports = (function() {
}
})()

},{}]},{},[1])(1)
},{}],24:[function(require,module,exports){
var forEachEls = require("./foreach-els")

module.exports = function(elements, oldElements) {
this.log("styleheets old elements", oldElements);
this.log("styleheets new elements", elements);
var toArray = function(enumerable){
var arr = [];
for(var i = enumerable.length; i--; arr.unshift(enumerable[i]));
return arr;
};
forEachEls(elements, function(newEl, i) {
var oldElementsArray = toArray(oldElements);
var resemblingOld = oldElements.reduce(function(acc, oldEl){ acc = (oldEl.attributes.href === newEl.attributes.href ? oldEl : acc); }, null);
if(resemblingOld !== null){
if (this.log) {
this.log("old stylesheet found not resetting");
}
} else {
if (this.log) {
this.log("new stylesheet => add to head");
}
var head = document.getElementsByTagName( 'head' )[0],
link = document.createElement( 'link' );
link.setAttribute( 'href', newEl.href );
link.setAttribute( 'rel', 'stylesheet' );
link.setAttribute( 'type', 'text/css' );
}
}, this);

}

},{"./foreach-els":7}]},{},[1])(1)
});
2 changes: 1 addition & 1 deletion assets/packages/questions/numeric-slider/numeric-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @param {number} qId The qid of the question where apply.
*/

function doNumericSlider(qID,options) {
var doNumericSlider = function(qID,options) {
$("#vmsg_"+qID+"_default").text(sliderTranslation.help);
$("#question"+qID+" .slider-container").each(function()
{
Expand Down
2 changes: 1 addition & 1 deletion assets/scripts/multiplechoice_withcomments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function doMultipleChoiceWithComments(qID,when)
var doMultipleChoiceWithComments = function(qID,when)
{
var question=$("#question"+qID+" .questions-list");
if (jQuery.inArray(when, ['checked','unchecked'])<0){when='checked'}
Expand Down

0 comments on commit e4d4651

Please sign in to comment.