Skip to content
Snippets Groups Projects
Commit 11afb4e9 authored by xamgore's avatar xamgore Committed by PavelBegunkov
Browse files

Refactor popup-windows code

parent d67e3baf
Branches
Tags
No related merge requests found
$(function() {
$('#openHelp').click(function()
{
$.get(URLdir + "window/help:student:index", function(data){
wnd.open(JSON.parse(data));
});
$(function () {
$('#openHelp').click(function () {
$.postJSON(URLdir + 'window/help:student:index')
.done(data => wnd.open(data))
});
});
\ No newline at end of file
var wnd = {}
wnd.$ = {}
var wnd = {};
wnd.$ = {};
wnd.isShow = false;
wnd.show = function () {
wnd.isShow = true;
wnd.scroll = $(window).scrollTop();
wnd.$.page.css("position", "fixed");
wnd.$.page.css("margin-top", -wnd.scroll);
wnd.$.window.fadeIn("fast");
}
wnd.isShow = true;
wnd.scroll = $(window).scrollTop();
wnd.$.page.css({ position: 'fixed', 'margin-top': -wnd.scroll });
wnd.$.window.fadeIn("fast");
};
wnd.hide = function () {
wnd.isShow = false;
wnd.$.page.css("position", "static");
wnd.$.page.css("margin-top", 0);
$(window).scrollTop(wnd.scroll);
wnd.$.window.fadeOut("fast");
}
wnd.open = function(data) {
wnd.$.title.html(data.title || '');
wnd.$.content.html(data.content || '');
wnd.$.block.width(data.width || 600);
wnd.$.block.css("top", data.top || '15%');
wnd.show();
wnd.$.window.css("min-width", wnd.$.block.width() + 40);
wnd.$.window.css("min-height", wnd.$.block.height() + 50);
}
wnd.isShow = false;
wnd.$.page.css({ position: 'static', 'margin-top', 0 });
$(window).scrollTop(wnd.scroll);
wnd.$.window.fadeOut("fast");
};
wnd.open = function ([title = '', width = 600, top = '15%', content = '']) {
wnd.$.title.html(title);
wnd.$.content.html(content);
wnd.$.block.width(width);
wnd.$.block.css("top", top);
wnd.show();
wnd.$.window.css({
'min-width': wnd.$.block.width() + 40,
'min-height': wnd.$.block.height() + 50
});
};
wnd.close = wnd.hide;
$(function() {
// Блок окна
$("body").append("<div class=\"window\"><div class=\"window-shadow\" onclick=\"wnd.close()\"></div><div class=\"window-block\"><div class=\"window-title\"></div><a href=\"javascript:wnd.close()\" class=\"window-close\"></a><div class=\"window-content\"></div></div></div>");
wnd.$.page = $(".page");
wnd.$.window = $(".window");
wnd.$.block = $(".window-block");
wnd.$.title = $(".window-title");
wnd.$.content = $(".window-content");
$(function () {
// Блок окна
$("body").append("<div class=\"window\"><div class=\"window-shadow\" onclick=\"wnd.close()\"></div><div class=\"window-block\"><div class=\"window-title\"></div><a href=\"javascript:wnd.close()\" class=\"window-close\"></a><div class=\"window-content\"></div></div></div>");
wnd.$.page = $(".page");
wnd.$.window = $(".window");
wnd.$.block = $(".window-block");
wnd.$.title = $(".window-title");
wnd.$.content = $(".window-content");
});
......@@ -13,18 +13,14 @@ class Controller_Window extends Controller
public function action_get() {
$path = UTF8::str_ireplace(':', '/', $this->request->param('id'));
if (Kohana::find_file('views/popup', $path, 'twig')) {
$twig = Twig::factory('popup/' . $path);
$twig->User = $this->user;
$arr = explode('||', $twig->render());
$json = json_encode(array(
'title' => $arr[0],
'width' => $arr[1],
'top' => $arr[2],
'content' => $arr[3]));
$this->response->body($json);
} else {
if (!Kohana::find_file('views/popup', $path, 'twig'))
throw HTTP_Exception::factory(404, "Искомый шаблон $path не найден");
}
$twig = Twig::factory('popup/' . $path)
->set('User', $this->user);
// title, width, top, content
$this->response->body(json_encode(explode('||', $twig->render())));
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment