o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1368642727.568609: @value"W€{I" class:EFI"ProcessedAsset;FI"logical_path;F"1ample_assets/classes/ample_assets_toolbar.jsI" pathname;F"{/Users/tcmacdonald/Sites/ample/ample_assets/app/assets/javascripts/ample_assets/classes/ample_assets_toolbar.js.coffeeI"content_type;FI"application/javascript;FI" mtime;FI"2013-05-15T14:31:51-04:00;FI" length;FiÄ|I" digest;F"%f9e41855497c25a19e5774b8df2e66fcI" source;FI"Ä|(function() { var __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; window.AmpleAssetsToolbar = (function(_super) { __extends(AmpleAssetsToolbar, _super); function AmpleAssetsToolbar() { return AmpleAssetsToolbar.__super__.constructor.apply(this, arguments); } AmpleAssetsToolbar.prototype.default_options = { debug: false, expanded: false, id: "ample-assets", handle_text: 'Assets', expanded_height: 180, collapsed_height: 0, base_url: '/ample_assets', search_url: '/files/search', thumb_url: '/files/thumbs', show_url: '/files/{{ id }}', touch_url: '/files/{{ id }}/touch', gravity_url: '/files/{{ id }}/gravity', onInit: function() {}, onExpand: function() {}, onCollapse: function() {}, panels_options: { debug: false, width: 950, height: 100, orientation: 'vertical', key_orientation: 'vertical', keyboard_nav: true, auto: false, parent: 'div', children: 'div.page' }, pages_options: { interval: 5000, width: 81, height: 81, enabled: true, distance: 10, auto: false, orientation: 'horizontal', key_orientation: 'horizontal', per_page: 10 }, pages: [ { id: 'recent-assets', title: 'Recently Viewed', url: '', panels: false } ] }; AmpleAssetsToolbar.prototype.init = function() { this.options.onInit(); AmpleAssetsToolbar.__super__.init.apply(this, arguments); this.setup(); return this.events(); }; AmpleAssetsToolbar.prototype.set_options = function(opts) { this.current = 0; this.keys_enabled = true; this.reloading = false; this.searching = false; this.loaded = false; return AmpleAssetsToolbar.__super__.set_options.apply(this, arguments); }; AmpleAssetsToolbar.prototype.setup = function() { var html, id, layout; id = this.options.id; layout = Mustache.to_html(this.tpl('layout'), { id: id, pages: this.get_pages(), tabs: this.get_pages('tab') }); this.handle = Mustache.to_html(this.tpl('handle'), { id: id, title: this.options.handle_text }); html = $(layout); $('body').append(html).append(this.handle); this.style(); this.drag_drop(); this.search(); if (this.options.expanded) { return this.goto(0); } }; AmpleAssetsToolbar.prototype.style = function() { var handle_opts; handle_opts = { position: 'absolute', bottom: 0, right: 0 }; $("#" + this.options.id + "-handle").css(handle_opts); this.loading = $("#" + this.options.id + "-tabs span.asset-loading"); $("#" + this.options.id + " .container").css('height', 200); if (this.options.expanded) { return $("#" + this.options.id).css({ height: this.options.expanded_height }); } }; AmpleAssetsToolbar.prototype.reload = function(i) { this.log("reload(" + i + ")"); this.reloading = true; if (i < this.options.pages.length - 1) { this.empty(i); this.options.pages[i]['loaded'] = false; this.options.pages[i]['pages_loaded'] = false; this.options.pages[i]['last_request_empty'] = false; $(this.options.pages[i]['panel_selector']).amplePanels('goto', 0); this.goto(i); return this.enable_panel(i); } }; AmpleAssetsToolbar.prototype.empty = function(i) { var selector; this.log("empty(" + i + ")"); selector = "#" + this.options.id + " .pages .page:nth-child(" + (i + 1) + ")"; if (this.options.pages[i]['panels']) { selector += " ul"; } return $(selector).empty(); }; AmpleAssetsToolbar.prototype.goto = function(i) { this.log("goto(" + i + ")"); this.show(i); this.disable_panels(); this.activate(i); if (!this.already_loaded(i)) { this.load(i); } if (this.already_loaded(i)) { return this.enable_panel(i); } }; AmpleAssetsToolbar.prototype.show = function(i) { $("#" + this.options.id + " .pages .page").hide(); return $("#" + this.options.id + " .pages .page:nth-child(" + (i + 1) + "), #" + this.options.id + " .pages .page:nth-child(" + (i + 1) + ") ul").show(); }; AmpleAssetsToolbar.prototype.drag_drop = function() { var base_url, ref, thumb_url; base_url = this.options.base_url; thumb_url = this.options.thumb_url; ref = this; $(".draggable").liveDraggable({ appendTo: "body", helper: "clone", start: function() { return $('div.ui-droppable, textarea.ui-droppable').addClass('asset-drop-target'); }, stop: function() { return $('div.ui-droppable, textarea.ui-droppable').removeClass('asset-drop-target'); } }); $("textarea").droppable({ activeClass: "asset-notice", hoverClass: "asset-success", accept: ".draggable", drop: function(event, ui) { if ($(ui.helper).data('role') !== 'gravity') { ref.target_textarea = this; return ref.resize_modal(ui.draggable); } } }); return $(".droppable").droppable({ activeClass: "asset-notice", hoverClass: "asset-success", accept: ".draggable", drop: function(event, ui) { var asset_id; if ($(ui.helper).data('role') !== 'gravity') { $(this).html(ui.draggable.clone()); asset_id = $(ui.draggable).attr("id").split("-")[1]; $(this).parent().children().first().val(asset_id); return $(this).parent().find('a.asset-remove').removeClass('hide').show(); } } }); }; AmpleAssetsToolbar.prototype.resize_modal = function(el) { var base_url, geometry, html, opts, orientation, size, thumb_url, uid; uid = $(el).attr("data-uid"); size = $(el).attr("data-size"); orientation = $(el).attr("data-orientation"); base_url = this.options.base_url; thumb_url = this.options.thumb_url; geometry = '100x>'; opts = { src: "" + base_url + thumb_url + "/" + geometry + "?uid=" + uid, orientation: orientation, dimensions: size, uid: uid }; html = Mustache.to_html(this.tpl('drop'), opts); return $.facebox("
" + html + "
"); }; AmpleAssetsToolbar.prototype.activate = function(i) { var tabs; this.log("activate(" + i + ")"); this.current = i; tabs = $("#" + this.options.id + " a.tab"); tabs.removeClass('on'); return tabs.eq(i).addClass('on'); }; AmpleAssetsToolbar.prototype.next = function() { if (this.current < this.options.pages.length - 1) { this.log("next()"); this.current += 1; return this.goto(this.current); } }; AmpleAssetsToolbar.prototype.previous = function() { if (this.current !== 0) { this.log("previous()"); this.current -= 1; return this.goto(this.current); } }; AmpleAssetsToolbar.prototype.get_pages = function(tpl) { var html, _this = this; if (tpl == null) { tpl = 'page'; } html = ''; $.each(this.options.pages, function(idx, el) { if (idx === 0) { el['classes'] = 'first-child'; } return html += Mustache.to_html(_this.tpl(tpl), el); }); return html; }; AmpleAssetsToolbar.prototype.toggle = function() { var el, _this = this; el = $("#" + this.options.id); if (this.options.expanded) { this.options.expanded = false; $('body').animate({ 'padding-bottom': 0 }, "fast"); return el.animate({ height: this.options.collapsed_height }, "fast", function() { _this.collapse(); _this.options.onCollapse(); return el.trigger('collapse'); }); } else { $("#" + this.options.id + "-handle").hide(); this.options.expanded = true; $('body').animate({ 'padding-bottom': this.options.expanded_height }, "fast"); return el.animate({ height: this.options.expanded_height }, "fast", function() { _this.expand(); _this.options.onExpand(); return el.trigger('expand'); }); } }; AmpleAssetsToolbar.prototype.load = function(i) { var data_type, load_next_page, ref, url; this.log("load(" + i + ")"); ref = this; load_next_page = true; if (this.options.pages[i]['last_request_empty']) { load_next_page = false; } if (this.reloading) { load_next_page = true; } if (this.options.pages[i]['url'] && load_next_page) { this.loading.show(); url = this.next_page_url(i); if (this.options.pages[i]['data_type']) { data_type = this.options.pages[i]['data_type']; } return $.get(url, function(response, xhr) { ref.loading.hide(); ref.options.pages[i]['loaded'] = true; if ($.trim(response) === '' || response.length === 0) { ref.options.pages[i]['last_request_empty'] = true; if (ref.reloading || !ref.options.pages[i]['panel_selector']) { return ref.load_empty(i); } } else { switch (data_type) { case "json": return ref.load_json(i, response); case "html": break; default: return ref.load_html(i, response); } } }, data_type); } else { if (!this.options.pages[i]['last_request_empty']) { return this.log("ERROR --> Couldn't load page because there was no url"); } } }; AmpleAssetsToolbar.prototype.load_empty = function(i) { var empty, _this = this; this.log("load_empty(" + i + ")"); empty = Mustache.to_html(this.tpl('empty')); this.load_html(i, empty); this.loading.hide(); $('li.empty').css('width', $('.ampn').first().width()); return $('li.empty a').click(function() { return _this.goto(_this.options.pages.length - 2); }); }; AmpleAssetsToolbar.prototype.load_html = function(i, response) { var selector; this.log("load(" + i + ") html"); selector = "#" + this.options.id + " .pages .page:nth-child(" + (i + 1) + ")"; if (this.options.pages[i]['panels'] || this.searching) { selector += " ul"; } $(selector).html(response).show(); return this.panels(i); }; AmpleAssetsToolbar.prototype.load_json = function(i, response) { var panels_loaded, ref, selector; this.log("load(" + i + ") json"); panels_loaded = this.options.pages[i]['panel_selector'] ? true : false; ref = this; selector = "#" + this.options.id + " .pages .page:nth-child(" + (i + 1) + ") ul"; $.each(response, function(j, el) { var li, link; link = ref.build(el); li = $('
  • ').append(link); if (panels_loaded) { $(selector).amplePanels('append', li); } else { $(selector).append(li); } return ref.load_img(li.find('a'), el.sizes.tn); }); $(selector).show(); if (!panels_loaded) { this.panels(i); } if (this.reloading) { this.reloading = false; return this.controls(); } }; AmpleAssetsToolbar.prototype.load_results = function(response) { var i, no_results, _this = this; this.log("load_results()"); i = this.options.pages.length - 1; if (response.length > 0) { $.each(response, function(j, el) { var li, link; link = _this.build(el); li = $('
  • ').append(link); $("#asset-results ul").amplePanels('append', li); return _this.load_img(link, el.sizes.tn); }); } else { no_results = Mustache.to_html(this.tpl('no_results')); this.load_html(i, no_results); this.loading.hide(); $('li.empty').css('width', $('.ampn').first().width()); } this.options.pages[i]['panel_selector'] = "#asset-results ul"; this.active_panel = $(this.options.pages[i]['panel_selector']); this.searching = false; this.loading.hide(); return this.controls(); }; AmpleAssetsToolbar.prototype.build = function(el) { var link, ref, show_url; ref = this; show_url = Mustache.to_html(this.options.show_url, { id: el.id }); link = $("").attr('id', "file-" + el.id).attr('data-uid', "" + el.uid).attr('data-filename', "" + el.filename).attr('data-gravity', el.gravity).addClass('draggable'); if (el.document === 'true') { link.addClass('document'); } else { link.attr('data-orientation', el.orientation); link.attr('data-size', el.size); } link.click(function() { ref.modal_open(el); return false; }); return link; }; AmpleAssetsToolbar.prototype.modal_open = function(data) { var delete_url, geometry, gravity, gravity_url, html, keywords, myPDF, url; this.modal_active = true; if (data.document === 'true') { delete_url = Mustache.to_html(this.options.show_url, { id: data.id }); html = Mustache.to_html(this.tpl('pdf'), { filename: data.uid, id: data.id, delete_url: "" + this.options.base_url + delete_url, mime_type: data.mime_type, url: data.url }); $.facebox("
    " + html + "
    "); myPDF = new PDFObject({ url: data.url, pdfOpenParams: { view: "Fit" } }).embed("pdf"); } else { geometry = data.orientation === 'portrait' ? 'x300>' : '480x>'; url = "" + this.options.base_url + this.options.thumb_url + "/" + geometry + "?uid=" + data.uid; delete_url = Mustache.to_html(this.options.show_url, { id: data.id }); gravity_url = Mustache.to_html(this.options.gravity_url, { id: data.id }); gravity = $("a[data-uid='" + data.uid + "']").first().attr('data-gravity'); keywords = ""; html = Mustache.to_html(this.tpl('show'), { filename: data.filename, size: data.size, mime_type: data.mime_type, keywords: keywords, src: url, orientation: data.orientation, id: data.id, uid: data.uid, gravity: gravity, delete_url: "" + this.options.base_url + delete_url, gravity_url: "" + this.options.base_url + gravity_url }); $.facebox("
    " + html + "
    "); } $('.clippy').clippy({ clippy_path: '/assets/ample_assets/clippy.swf' }); return this.touch(data); }; AmpleAssetsToolbar.prototype.load_img = function(el, src) { var img; img = new Image(); return $(img).load(function() { $(this).hide(); $(el).html(this); return $(this).fadeIn(); }).attr({ src: src }); }; AmpleAssetsToolbar.prototype.next_page_url = function(i) { if (!this.options.pages[i]['pages_loaded']) { this.options.pages[i]['pages_loaded'] = 0; } this.options.pages[i]['pages_loaded'] += 1; return "" + this.options.pages[i]['url'] + "?page=" + this.options.pages[i]['pages_loaded']; }; AmpleAssetsToolbar.prototype.touch = function(el) { var touch_url; this.log("touch()"); touch_url = Mustache.to_html(this.options.touch_url, { id: el.id }); return $.post("" + this.options.base_url + touch_url); }; AmpleAssetsToolbar.prototype.panels = function(i) { var el, ref; ref = this; if (this.options.pages[i]['panels']) { this.log("panels(" + i + ")"); el = "#" + this.options.id + " .pages .page:nth-child(" + (i + 1) + ") ul"; this.options.pages[i]['panel_selector'] = el; this.active_panel = el; this.options.pages[i][''] = $(el).attr('id', "" + this.options.pages[i]['id'] + "-panel"); $(el).parent().addClass('panels'); this.controls(); return $(el).amplePanels(this.options.pages_options).bind('slide_horizontal', function(e, d, dir) { if (dir === 'next') { return ref.load(i); } }); } }; AmpleAssetsToolbar.prototype.disable_panels = function() { var ref; this.log("disable_panels()"); ref = this; this.controls(false); return $.each(this.options.pages, function(i, el) { if (ref.options.pages[i]['panel_selector']) { return $(ref.options.pages[i]['panel_selector']).amplePanels('disable'); } }); }; AmpleAssetsToolbar.prototype.enable_panel = function(i) { this.log("enable_panel(" + i + ")"); if (this.options.pages[i]['panel_selector']) { this.active_panel = this.options.pages[i]['panel_selector']; $(this.options.pages[i]['panel_selector']).amplePanels('enable'); return this.controls(); } }; AmpleAssetsToolbar.prototype.controls = function(display) { if (display == null) { display = true; } this.log("controls(" + display + ")"); if ($(this.active_panel).find('li').length < this.options.pages_options.per_page) { display = false; } switch (display) { case true: return $('nav.controls').show(); case false: return $('nav.controls').hide(); } }; AmpleAssetsToolbar.prototype.already_loaded = function(i) { return typeof this.options.pages[i]['loaded'] === 'boolean' && this.options.pages[i]['loaded']; }; AmpleAssetsToolbar.prototype.remove = function(el) { var parent; parent = $(el).parent(); parent.find('.droppable').empty().html('Drag Asset Here'); parent.find('input').val(''); return $(el).hide(); }; AmpleAssetsToolbar.prototype["delete"] = function(id) { this.log("delete(" + id + ")"); $("a#file-" + id).parent().remove(); $(document).trigger('close.facebox'); this.reload(0); return false; }; AmpleAssetsToolbar.prototype.collapse = function() { $("#" + this.options.id + "-handle").css('bottom', -35).show().animate({ 'bottom': 0 }, 'fast'); return this.disable_panels(); }; AmpleAssetsToolbar.prototype.expand = function() { return this.goto(this.current); }; AmpleAssetsToolbar.prototype.events = function() { var ref, _this = this; this.modal_events(); this.global_events(); this.field_events(); this.drop_events(); this.drag_events(); this.reload_events(); this.resize_events(); this.key_events(); this.tab_events(); ref = this; $("#" + this.options.id + " a.collapse").live('click', function() { return _this.toggle(); }); $('body').bind('ample_uploadify.complete', function() { return _this.reload(0); }); $("a.asset-delete").live('ajax:success', function() { var id; id = parseInt($(this).attr('data-id')); return ref["delete"](id); }); $("a.asset-remove").live('click', function() { ref.remove(this); return false; }); return $("#" + this.options.id + "-handle").live('click', function() { _this.toggle(); return false; }); }; AmpleAssetsToolbar.prototype.global_events = function() { var _this = this; $('a.global.next').click(function() { return $(_this.active_panel).amplePanels('next'); }); return $('a.global.previous').click(function() { return $(_this.active_panel).amplePanels('previous'); }); }; AmpleAssetsToolbar.prototype.drag_events = function() { return this.log("drag_events()"); }; AmpleAssetsToolbar.prototype.drop_events = function() { var ref; ref = this; return $('.asset-drop .droppable a').live('click', function() { var id; id = $(this).attr("href"); $.get($(this).attr("href"), function(response) { return ref.modal_open(response); }, 'json'); return false; }); }; AmpleAssetsToolbar.prototype.field_events = function() { var _this = this; this.log("field_events()"); $('textarea, input').live('blur', function() { return _this.keys_enabled = true; }); return $('textarea, input').live('focus', function() { return _this.keys_enabled = false; }); }; AmpleAssetsToolbar.prototype.reload_events = function() { var reload, _this = this; this.log("reload_events()"); reload = $(''); return reload.appendTo('.asset-refresh').click(function(e) { return _this.reload(_this.current); }); }; AmpleAssetsToolbar.prototype.resize_events = function() { var _this = this; return $('.asset-resize').live('click', function() { var alt, constraints, geometry, height, html, textile, uid, url, width; constraints = $('#asset-constraints').val(); uid = $('#asset-uid').val(); width = $('#asset-width').val(); height = $('#asset-height').val(); alt = $('#asset-alt').val(); geometry = "" + width + "x" + height + constraints; if (constraints === '#' && (width === '' || height === '')) { return alert('Can\'t resize image using this geometry. Please select another option or supply a value for both width and height.'); } else { url = encodeURI("" + _this.options.base_url + _this.options.thumb_url + "/" + geometry + "?uid=" + uid); url = url.replace('#', '%23'); textile = "!" + url + "(" + alt + ")!"; html = "\"""; $(_this.target_textarea).insertAtCaret(($(_this.target_textarea).hasClass('textile') ? textile : html)); return $(document).trigger('close.facebox'); } }); }; AmpleAssetsToolbar.prototype.modal_events = function() { var _this = this; this.modal_active = false; $(document).bind('afterClose.facebox', function() { _this.keys_enabled = true; return _this.modal_active = false; }); return $(document).bind('loading.facebox', function() { _this.keys_enabled = false; return _this.modal_active = true; }); }; AmpleAssetsToolbar.prototype.search = function() { var i, ref, search_url; this.log('search()'); search_url = "" + this.options.base_url + this.options.search_url; i = $("#" + this.options.id + " .pages .page").length - 1; ref = this; $('#asset-results ul').attr('id', 'assets-result-list').amplePanels(this.options.pages_options); this.options.pages[i] = { loaded: true }; return $('#asset-search').bind('change', function() { $("#asset-results ul").amplePanels('empty'); ref.loading.show(); ref.controls(false); ref.show(i); ref.activate(i); ref.searching = true; $('.asset-results').show(); return $.post(search_url, $(this).serialize(), function(response) { return ref.load_results(response); }, 'json'); }); }; AmpleAssetsToolbar.prototype.tab_events = function() { var ref, tabs; tabs = $("#" + this.options.id + " a.tab"); ref = this; return $.each(tabs, function(idx, el) { if (idx === 0) { $(this).addClass('on'); } return $(el).click(function() { ref.goto(idx); return false; }); }); }; AmpleAssetsToolbar.prototype.key_events = function() { var down, escape, next, previous, ref, up, _this = this; ref = this; previous = 37; next = 39; up = 38; down = 40; escape = 27; $(document).keyup(function(e) { if (!_this.keys_enabled) { return; } switch (e.keyCode) { case escape: if (!_this.modal_active) { _this.toggle(); } } return e.stopPropagation(); }); return $(document).keydown(function(e) { if (!_this.keys_enabled) { return; } if (_this.active_panel) { switch (e.keyCode) { case previous: $(_this.active_panel).amplePanels('previous'); break; case next: $(_this.active_panel).amplePanels('next'); break; case up: _this.previous(); break; case down: _this.next(); } } return e.stopPropagation(); }); }; AmpleAssetsToolbar.prototype.tpl = function(view) { return this.tpls()[view]; }; AmpleAssetsToolbar.prototype.tpls = function() { return { layout: '\
    \ Close\
    \
    \
    \ \ {{{ tabs }}}\ Results\ \
    \
    \ {{{ pages }}}\
    \
      \
      \
      \ \
      \
      ', handle: '{{ title }}', tab: '{{ title }}', page: '\
      \ \
      ', show: '\
      \
      \ \
      \ \ \ \
      Asset updated successfully.
      \ Delete This Asset?\

      {{ filename }} {{ src }}


      \ \

      {{ keywords }}

      \
      ', pdf: '\
      \
      \ Delete This Asset?\

      {{ filename }} {{ url }}


      \ \

      {{ keywords }}

      \
      ', empty: '
    • Oops. There\'s nothing here. You should upload something.
    • ', no_results: '
    • Sorry. Your search returned zero results.
    • ', drop: '\
      \
      \ \
      \
      \

      ({{ dimensions }}, {{ orientation }})

      \

      \

      \ \ x \
      \ \

      \ \
      \
      \
      ' }; }; return AmpleAssetsToolbar; })(CoffeeCup); jQuery.fn.liveDraggable = function(opts) { return this.live("mouseover", function() { if (!$(this).data("init")) { return $(this).data("init", true).draggable(opts); } }); }; jQuery.fn.insertAtCaret = function(value) { return this.each(function(i) { var endPos, scrollTop, sel, startPos; if (document.selection) { this.focus(); sel = document.selection.createRange(); sel.text = value; return this.focus(); } else if (this.selectionStart || this.selectionStart === "0") { startPos = this.selectionStart; endPos = this.selectionEnd; scrollTop = this.scrollTop; this.value = this.value.substring(0, startPos) + value + this.value.substring(endPos, this.value.length); this.focus(); this.selectionStart = startPos + value.length; this.selectionEnd = startPos + value.length; return this.scrollTop = scrollTop; } else { this.value += value; return this.focus(); } }); }; }).call(this); ;TI"dependency_digest;F"%24c224d4b5884454c3534007193f7f13I"required_paths;F["{/Users/tcmacdonald/Sites/ample/ample_assets/app/assets/javascripts/ample_assets/classes/ample_assets_toolbar.js.coffeeI"dependency_paths;F[{I" path;F"{/Users/tcmacdonald/Sites/ample/ample_assets/app/assets/javascripts/ample_assets/classes/ample_assets_toolbar.js.coffeeI" mtime;FI"2013-05-15T14:31:51-04:00;FI" digest;F"%155b62de8da0bbf47913d3805aba7997I" _version;F"%979b712d447c42bc88f489bb52e370d7