var up = new function () { this.root = '/js/up/'; this.csrf = new function () { this.get_meta_csrf = function () { return $('meta[name="csrf-token"]').attr('content'); } }; this.includer = new function () { this.included_files = []; /** * Асинхронный загрузчик файлов */ this.include = function (files) { var result = files.map(function (file) { if (this.included_files.indexOf(file) === -1) { this.included_files.push(file); return $.getScript(file).done(function () { return true; }); } }); return result; }; this.includeAsync = function (files) { var _arr = $.map(files, function (file) { if (this.included_files.indexOf(file) === -1) { this.included_files.push(file); switch (file.split(".").pop()) { case "css": $("", {rel: "stylesheet", type: "text/css", href: file}).appendTo("head"); return {readyState: 1}; break; case "js": return $.getScript(file); break; } } return true; }); _arr.push($.Deferred(function (deferred) { $(deferred.resolve); })); return $.when.apply($, _arr); }; }; }; /** * Загрузчик библиотеки "Union Projects" для динамических скриптов * Для работы необходимо: Jquery, LiveQuery * * Пример использования скрипта для перевода: class="up up-text-translate" * Файл скрипта должен находится в /up/text/translate.js * * @param up_root_path - Путь к root библиотеки */ $('.up').livequery(function () { var s = $(this).attr('class').match(/up-\w+-\w+/g); $.each(s, function (k, v) { var script_path = up.root + v.replace(/-/g, '/').replace('up', 'dynamic') + '.js'; up.includer.include([script_path]); }); });